From 4d3a1eed67b65166165dd116690489e65c7f6d62 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Thu, 8 Feb 2018 17:34:41 +0100 Subject: [PATCH] move TerminalMenus.jl into a submodule in stdlib/REPL --- stdlib/REPL/docs/src/index.md | 149 ++++++++++++++- stdlib/REPL/src/REPL.jl | 1 + stdlib/REPL/src/TerminalMenus/.gitignore | 5 - stdlib/REPL/src/TerminalMenus/.travis.yml | 35 ---- .../TerminalMenus/{src => }/AbstractMenu.jl | 4 +- stdlib/REPL/src/TerminalMenus/LICENSE.md | 22 --- .../{src => }/MultiSelectMenu.jl | 2 +- stdlib/REPL/src/TerminalMenus/README.md | 170 ------------------ stdlib/REPL/src/TerminalMenus/REQUIRE | 1 - .../src/TerminalMenus/{src => }/RadioMenu.jl | 2 +- .../TerminalMenus/{src => }/TerminalMenus.jl | 5 +- stdlib/REPL/src/TerminalMenus/appveyor.yml | 47 ----- stdlib/REPL/src/TerminalMenus/changelog.md | 10 -- .../src/TerminalMenus/{src => }/config.jl | 4 +- .../REPL/src/TerminalMenus/{src => }/util.jl | 9 +- .../TerminalMenus}/multiselect_menu.jl | 0 .../test => test/TerminalMenus}/radio_menu.jl | 0 .../test => test/TerminalMenus}/runtests.jl | 7 +- stdlib/REPL/test/runtests.jl | 3 + 19 files changed, 170 insertions(+), 306 deletions(-) delete mode 100644 stdlib/REPL/src/TerminalMenus/.gitignore delete mode 100644 stdlib/REPL/src/TerminalMenus/.travis.yml rename stdlib/REPL/src/TerminalMenus/{src => }/AbstractMenu.jl (98%) delete mode 100644 stdlib/REPL/src/TerminalMenus/LICENSE.md rename stdlib/REPL/src/TerminalMenus/{src => }/MultiSelectMenu.jl (98%) delete mode 100644 stdlib/REPL/src/TerminalMenus/README.md delete mode 100644 stdlib/REPL/src/TerminalMenus/REQUIRE rename stdlib/REPL/src/TerminalMenus/{src => }/RadioMenu.jl (96%) rename stdlib/REPL/src/TerminalMenus/{src => }/TerminalMenus.jl (70%) delete mode 100644 stdlib/REPL/src/TerminalMenus/appveyor.yml delete mode 100644 stdlib/REPL/src/TerminalMenus/changelog.md rename stdlib/REPL/src/TerminalMenus/{src => }/config.jl (95%) rename stdlib/REPL/src/TerminalMenus/{src => }/util.jl (93%) rename stdlib/REPL/{src/TerminalMenus/test => test/TerminalMenus}/multiselect_menu.jl (100%) rename stdlib/REPL/{src/TerminalMenus/test => test/TerminalMenus}/radio_menu.jl (100%) rename stdlib/REPL/{src/TerminalMenus/test => test/TerminalMenus}/runtests.jl (91%) diff --git a/stdlib/REPL/docs/src/index.md b/stdlib/REPL/docs/src/index.md index 158b077b16060..ff828c35aa409 100644 --- a/stdlib/REPL/docs/src/index.md +++ b/stdlib/REPL/docs/src/index.md @@ -366,7 +366,154 @@ ENV["JULIA_WARN_COLOR"] = :yellow ENV["JULIA_INFO_COLOR"] = :cyan ``` -## References +# TerminalMenus + +TerminalMenus is a submodule of the Julia REPL and enables small, low-profile interactive menus in the terminal. + +## Examples + +```julia +import REPL +using REPL.TerminalMenus + +options = ["apple", "orange", "grape", "strawberry", + "blueberry", "peach", "lemon", "lime"] + +``` + +### RadioMenu + +The RadioMenu allows the user to select one option from the list. The `request` +function displays the interactive menu and returns the index of the selected +choice. If a user presses 'q' or `ctrl-c`, `request` will return a `-1`. + + +```julia +# `pagesize` is the number of items to be displayed at a time. +# The UI will scroll if the number of options is greater +# than the `pagesize` +menu = RadioMenu(options, pagesize=4) + +# `request` displays the menu and returns the index after the +# user has selected a choice +choice = request("Choose your favorite fruit:", menu) + +if choice != -1 + println("Your favorite fruit is ", options[choice], "!") +else + println("Menu canceled.") +end + +``` + +Output: + +``` +Choose your favorite fruit: +^ grape + strawberry + > blueberry +v peach +Your favorite fruit is blueberry! +``` + +### MultiSelectMenu + +The MultiSelectMenu allows users to select many choices from a list. + +```julia +# here we use the default `pagesize` 10 +menu = MultiSelectMenu(options) + +# `request` returns a `Set` of selected indices +# if the menu us canceled (ctrl-c or q), return an empty set +choices = request("Select the fruits you like:", menu) + +if length(choices) > 0 + println("You like the following fruits:") + for i in choices + println(" - ", options[i]) + end +else + println("Menu canceled.") +end +``` + +Output: + +``` +Select the fruits you like: +[press: d=done, a=all, n=none] + [ ] apple + > [X] orange + [X] grape + [ ] strawberry + [ ] blueberry + [X] peach + [ ] lemon + [ ] lime +You like the following fruits: + - orange + - grape + - peach +``` + +## Customization / Configuation + +All interface customization is done through the keyword only +`TerminalMenus.config()` function. + +### Arguments + + - `charset::Symbol=:na`: ui characters to use (`:ascii` or `:unicode`); overridden by other arguments + - `cursor::Char='>'|'→'`: character to use for cursor + - `up_arrow::Char='^'|'↑'`: character to use for up arrow + - `down_arrow::Char='v'|'↓'`: character to use for down arrow + - `checked::String="[X]"|"✓"`: string to use for checked + - `unchecked::String="[ ]"|"⬚")`: string to use for unchecked + - `scroll::Symbol=:na`: If `:wrap` then wrap the cursor around top and bottom, if :`nowrap` do not wrap cursor + - `supress_output::Bool=false`: For testing. If true, menu will not be printed to console. + - `ctrl_c_interrupt::Bool=true`: If `false`, return empty on ^C, if `true` throw InterruptException() on ^C + +### Examples + +```julia +julia> menu = MultiSelectMenu(options, pagesize=5); + +julia> request(menu) # ASCII is used by default +[press: d=done, a=all, n=none] + [ ] apple + [X] orange + [ ] grape + > [X] strawberry +v [ ] blueberry +Set([4, 2]) + +julia> TerminalMenus.config(charset=:unicode) + +julia> request(menu) +[press: d=done, a=all, n=none] + ⬚ apple + ✓ orange + ⬚ grape + → ✓ strawberry +↓ ⬚ blueberry +Set([4, 2]) + +julia> TerminalMenus.config(checked="YEP!", unchecked="NOPE", cursor='⧐') + +julia> request(menu) +[press: d=done, a=all, n=none] + NOPE apple + YEP! orange + NOPE grape + ⧐ YEP! strawberry +↓ NOPE blueberry +Set([4, 2]) + +``` + +# References ```@docs Base.atreplinit diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl index b35f030672eaa..ce34e7882acf1 100644 --- a/stdlib/REPL/src/REPL.jl +++ b/stdlib/REPL/src/REPL.jl @@ -42,6 +42,7 @@ import ..LineEdit: include("REPLCompletions.jl") using .REPLCompletions +include("TerminalMenus/TerminalMenus.jl") include("docview.jl") function __init__() diff --git a/stdlib/REPL/src/TerminalMenus/.gitignore b/stdlib/REPL/src/TerminalMenus/.gitignore deleted file mode 100644 index cba1e08692383..0000000000000 --- a/stdlib/REPL/src/TerminalMenus/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -*.jl.cov -*.jl.*.cov -*.jl.mem -*.o -*.d diff --git a/stdlib/REPL/src/TerminalMenus/.travis.yml b/stdlib/REPL/src/TerminalMenus/.travis.yml deleted file mode 100644 index 6d6b8101aa76a..0000000000000 --- a/stdlib/REPL/src/TerminalMenus/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -## Documentation: http://docs.travis-ci.com/user/languages/julia/ -language: julia -os: - - linux - - osx -julia: - - 0.6 - - nightly -notifications: - email: false -git: - depth: 99999999 - -## uncomment the following lines to allow failures on nightly julia -## (tests will run but not make your overall status red) -#matrix: -# allow_failures: -# - julia: nightly - -## uncomment and modify the following lines to manually install system packages -#addons: -# apt: # apt-get for linux -# packages: -# - gfortran -#before_script: # homebrew for mac -# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi - -## uncomment the following lines to override the default test script -#script: -# - julia -e 'Pkg.clone(pwd()); Pkg.build("TerminalMenus"); Pkg.test("TerminalMenus"; coverage=true)' -after_success: - # push coverage results to Coveralls - - julia -e 'cd(Pkg.dir("TerminalMenus")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())' - # push coverage results to Codecov - - julia -e 'cd(Pkg.dir("TerminalMenus")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' diff --git a/stdlib/REPL/src/TerminalMenus/src/AbstractMenu.jl b/stdlib/REPL/src/TerminalMenus/AbstractMenu.jl similarity index 98% rename from stdlib/REPL/src/TerminalMenus/src/AbstractMenu.jl rename to stdlib/REPL/src/TerminalMenus/AbstractMenu.jl index 508178f50f8a6..20cc52659d219 100644 --- a/stdlib/REPL/src/TerminalMenus/src/AbstractMenu.jl +++ b/stdlib/REPL/src/TerminalMenus/AbstractMenu.jl @@ -101,7 +101,7 @@ varies based on menu type. """ request(m::AbstractMenu) = request(terminal, m) -function request(term::Base.Terminals.TTYTerminal, m::AbstractMenu) +function request(term::REPL.Terminals.TTYTerminal, m::AbstractMenu) cursor = 1 menu_header = header(m) @@ -212,7 +212,7 @@ Shorthand for `println(msg); request(m)`. request(msg::AbstractString, m::AbstractMenu) = request(terminal, msg, m) -function request(term::Base.Terminals.TTYTerminal, +function request(term::REPL.Terminals.TTYTerminal, msg::AbstractString, m::AbstractMenu) println(term.out_stream, msg) request(term, m) diff --git a/stdlib/REPL/src/TerminalMenus/LICENSE.md b/stdlib/REPL/src/TerminalMenus/LICENSE.md deleted file mode 100644 index a5614bca6fbfb..0000000000000 --- a/stdlib/REPL/src/TerminalMenus/LICENSE.md +++ /dev/null @@ -1,22 +0,0 @@ -The TerminalMenus.jl package is licensed under the MIT "Expat" License: - -> Copyright (c) 2017: Nick Paul. -> -> Permission is hereby granted, free of charge, to any person obtaining a copy -> of this software and associated documentation files (the "Software"), to deal -> in the Software without restriction, including without limitation the rights -> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -> copies of the Software, and to permit persons to whom the Software is -> furnished to do so, subject to the following conditions: -> -> The above copyright notice and this permission notice shall be included in all -> copies or substantial portions of the Software. -> -> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -> SOFTWARE. -> diff --git a/stdlib/REPL/src/TerminalMenus/src/MultiSelectMenu.jl b/stdlib/REPL/src/TerminalMenus/MultiSelectMenu.jl similarity index 98% rename from stdlib/REPL/src/TerminalMenus/src/MultiSelectMenu.jl rename to stdlib/REPL/src/TerminalMenus/MultiSelectMenu.jl index e3ae58213fb46..686749f5455ff 100644 --- a/stdlib/REPL/src/TerminalMenus/src/MultiSelectMenu.jl +++ b/stdlib/REPL/src/TerminalMenus/MultiSelectMenu.jl @@ -94,7 +94,7 @@ function writeLine(buf::IOBuffer, menu::MultiSelectMenu, idx::Int, cursor::Bool) print(buf, CONFIG[:unchecked], " ") end - print(buf, replace(menu.options[idx], "\n", "\\n")) + print(buf, replace(menu.options[idx], "\n" => "\\n")) end # d: Done, return from request diff --git a/stdlib/REPL/src/TerminalMenus/README.md b/stdlib/REPL/src/TerminalMenus/README.md deleted file mode 100644 index ba670102ec2fb..0000000000000 --- a/stdlib/REPL/src/TerminalMenus/README.md +++ /dev/null @@ -1,170 +0,0 @@ -# TerminalMenus - -[![Build Status](https://travis-ci.org/nick-paul/TerminalMenus.jl.svg?branch=master)](https://travis-ci.org/nick-paul/TerminalMenus.jl) [![Build status](https://ci.appveyor.com/api/projects/status/weaqa64co5boj87g?svg=true)](https://ci.appveyor.com/project/nick-paul/terminalmenus-jl) - -![Demo](http://npaul.co/files/TerminalMenus-demo.gif) - -TerminalMenus.jl enables small, low-profile interactive menus in the terminal. - - -# Installation - -TerminalMenus requires Julia 0.6. Use `Pkg` to install: - -``` -Pkg.add("TerminalMenus") -``` - - -# Examples - -```julia -using TerminalMenus - -options = ["apple", "orange", "grape", "strawberry", - "blueberry", "peach", "lemon", "lime"] - -``` - -## RadioMenu - -The RadioMenu allows the user to select one option from the list. The `request` -function displays the interactive menu and returns the index of the selected -choice. If a user presses 'q' or `ctrl-c`, `request` will return a `-1`. - - -```julia -# `pagesize` is the number of items to be displayed at a time. -# The UI will scroll if the number of options is greater -# than the `pagesize` -menu = RadioMenu(options, pagesize=4) - -# `request` displays the menu and returns the index after the -# user has selected a choice -choice = request("Choose your favorite fruit:", menu) - -if choice != -1 - println("Your favorite fruit is ", options[choice], "!") -else - println("Menu canceled.") -end - -``` - -Output: - -``` -Choose your favorite fruit: -^ grape - strawberry - > blueberry -v peach -Your favorite fruit is blueberry! -``` - -## MultiSelectMenu - -The MultiSelectMenu allows users to select many choices from a list. - -```julia -# here we use the default `pagesize` 10 -menu = MultiSelectMenu(options) - -# `request` returns a `Set` of selected indices -# if the menu us canceled (ctrl-c or q), return an empty set -choices = request("Select the fruits you like:", menu) - -if length(choices) > 0 - println("You like the following fruits:") - for i in choices - println(" - ", options[i]) - end -else - println("Menu canceled.") -end -``` - -Output: - -``` -Select the fruits you like: -[press: d=done, a=all, n=none] - [ ] apple - > [X] orange - [X] grape - [ ] strawberry - [ ] blueberry - [X] peach - [ ] lemon - [ ] lime -You like the following fruits: - - orange - - grape - - peach -``` - -# Customization / Configuation - -All interface customization is done through the keyword only -`TerminalMenus.config()` function. - -## Arguments - - - `charset::Symbol=:na`: ui characters to use (`:ascii` or `:unicode`); overridden by other arguments - - `cursor::Char='>'|'→'`: character to use for cursor - - `up_arrow::Char='^'|'↑'`: character to use for up arrow - - `down_arrow::Char='v'|'↓'`: character to use for down arrow - - `checked::String="[X]"|"✓"`: string to use for checked - - `unchecked::String="[ ]"|"⬚")`: string to use for unchecked - - `scroll::Symbol=:na`: If `:wrap` then wrap the cursor around top and bottom, if :`nowrap` do not wrap cursor - - `supress_output::Bool=false`: For testing. If true, menu will not be printed to console. - - `ctrl_c_interrupt::Bool=true`: If `false`, return empty on ^C, if `true` throw InterruptException() on ^C - -## Examples - -```julia -julia> menu = MultiSelectMenu(options, pagesize=5); - -julia> request(menu) # ASCII is used by default -[press: d=done, a=all, n=none] - [ ] apple - [X] orange - [ ] grape - > [X] strawberry -v [ ] blueberry -Set([4, 2]) - -julia> TerminalMenus.config(charset=:unicode) - -julia> request(menu) -[press: d=done, a=all, n=none] - ⬚ apple - ✓ orange - ⬚ grape - → ✓ strawberry -↓ ⬚ blueberry -Set([4, 2]) - -julia> TerminalMenus.config(checked="YEP!", unchecked="NOPE", cursor='⧐') - -julia> request(menu) -[press: d=done, a=all, n=none] - NOPE apple - YEP! orange - NOPE grape - ⧐ YEP! strawberry -↓ NOPE blueberry -Set([4, 2]) - -``` - -# TODO - - - Nested menus - - More customization? - ---- - -*The interactive menu has been tested on Ubuntu 16.04 and windows 7, 8, & 10. -If there are any issues on your platform, please submit an issue or a pull -request.* diff --git a/stdlib/REPL/src/TerminalMenus/REQUIRE b/stdlib/REPL/src/TerminalMenus/REQUIRE deleted file mode 100644 index 137767a42af4a..0000000000000 --- a/stdlib/REPL/src/TerminalMenus/REQUIRE +++ /dev/null @@ -1 +0,0 @@ -julia 0.6 diff --git a/stdlib/REPL/src/TerminalMenus/src/RadioMenu.jl b/stdlib/REPL/src/TerminalMenus/RadioMenu.jl similarity index 96% rename from stdlib/REPL/src/TerminalMenus/src/RadioMenu.jl rename to stdlib/REPL/src/TerminalMenus/RadioMenu.jl index 0217255ce4d3d..04f2937a06049 100644 --- a/stdlib/REPL/src/TerminalMenus/src/RadioMenu.jl +++ b/stdlib/REPL/src/TerminalMenus/RadioMenu.jl @@ -73,5 +73,5 @@ function writeLine(buf::IOBuffer, menu::RadioMenu, idx::Int, cursor::Bool) # print a ">" on the selected entry cursor ? print(buf, CONFIG[:cursor] ," ") : print(buf, " ") - print(buf, replace(menu.options[idx], "\n", "\\n")) + print(buf, replace(menu.options[idx], "\n" => "\\n")) end diff --git a/stdlib/REPL/src/TerminalMenus/src/TerminalMenus.jl b/stdlib/REPL/src/TerminalMenus/TerminalMenus.jl similarity index 70% rename from stdlib/REPL/src/TerminalMenus/src/TerminalMenus.jl rename to stdlib/REPL/src/TerminalMenus/TerminalMenus.jl index fa032e0262ced..d25a8acb5d2d8 100644 --- a/stdlib/REPL/src/TerminalMenus/src/TerminalMenus.jl +++ b/stdlib/REPL/src/TerminalMenus/TerminalMenus.jl @@ -1,11 +1,12 @@ -__precompile__() module TerminalMenus terminal = nothing # The user terminal +import REPL + function __init__() global terminal - terminal = Base.Terminals.TTYTerminal(get(ENV, "TERM", is_windows() ? "" : "dumb"), STDIN, STDOUT, STDERR) + terminal = REPL.Terminals.TTYTerminal(get(ENV, "TERM", Sys.iswindows() ? "" : "dumb"), STDIN, STDOUT, STDERR) end include("util.jl") diff --git a/stdlib/REPL/src/TerminalMenus/appveyor.yml b/stdlib/REPL/src/TerminalMenus/appveyor.yml deleted file mode 100644 index 19b36b92a3aac..0000000000000 --- a/stdlib/REPL/src/TerminalMenus/appveyor.yml +++ /dev/null @@ -1,47 +0,0 @@ -environment: - matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" - -## uncomment the following lines to allow failures on nightly julia -## (tests will run but not make your overall status red) -#matrix: -# allow_failures: -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" - -branches: - only: - - master - - /release-.*/ - -notifications: - - provider: Email - on_build_success: false - on_build_failure: false - on_build_status_changed: false - -install: - - ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" -# If there's a newer build queued for the same PR, cancel this one - - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` - https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` - Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` - throw "There are newer queued builds for this pull request, failing early." } -# Download most recent Julia Windows binary - - ps: (new-object net.webclient).DownloadFile( - $env:JULIA_URL, - "C:\projects\julia-binary.exe") -# Run installer silently, output to C:\projects\julia - - C:\projects\julia-binary.exe /S /D=C:\projects\julia - -build_script: -# Need to convert from shallow to complete for Pkg.clone to work - - IF EXIST .git\shallow (git fetch --unshallow) - - C:\projects\julia\bin\julia -e "versioninfo(); - Pkg.clone(pwd(), \"TerminalMenus\"); Pkg.build(\"TerminalMenus\")" - -test_script: - - C:\projects\julia\bin\julia -e "Pkg.test(\"TerminalMenus\")" diff --git a/stdlib/REPL/src/TerminalMenus/changelog.md b/stdlib/REPL/src/TerminalMenus/changelog.md deleted file mode 100644 index 28dc7daf74044..0000000000000 --- a/stdlib/REPL/src/TerminalMenus/changelog.md +++ /dev/null @@ -1,10 +0,0 @@ -# 0.0.2 - - - Add menu customization - - Add unicode and ascii UI sets - - Add wrap around top and bottom of menu (optional) - - Add better documentation and more comprehensive test cases - -# 0.0.1 - -Initial release. Includes RadioMenu and MultiSelectMenu diff --git a/stdlib/REPL/src/TerminalMenus/src/config.jl b/stdlib/REPL/src/TerminalMenus/config.jl similarity index 95% rename from stdlib/REPL/src/TerminalMenus/src/config.jl rename to stdlib/REPL/src/TerminalMenus/config.jl index db3f295ac68f8..ce9b479e86c5e 100644 --- a/stdlib/REPL/src/TerminalMenus/src/config.jl +++ b/stdlib/REPL/src/TerminalMenus/config.jl @@ -26,8 +26,8 @@ function config(;charset::Symbol = :na, down_arrow::Char = '\0', checked::String = "", unchecked::String = "", - supress_output::Union{Void, Bool}=nothing, - ctrl_c_interrupt::Union{Void, Bool}=nothing) + supress_output::Union{Nothing, Bool}=nothing, + ctrl_c_interrupt::Union{Nothing, Bool}=nothing) if !(charset in [:na, :ascii, :unicode]) error("charset should be :ascii or :unicode, recieved $charset") diff --git a/stdlib/REPL/src/TerminalMenus/src/util.jl b/stdlib/REPL/src/TerminalMenus/util.jl similarity index 93% rename from stdlib/REPL/src/TerminalMenus/src/util.jl rename to stdlib/REPL/src/TerminalMenus/util.jl index e56af21402008..eccd1ed0678e0 100644 --- a/stdlib/REPL/src/TerminalMenus/src/util.jl +++ b/stdlib/REPL/src/TerminalMenus/util.jl @@ -13,7 +13,7 @@ # Enable raw mode. Allows us to process keyboard inputs directly. function enableRawMode(term) try - Base.Terminals.raw!(term, true) + REPL.Terminals.raw!(term, true) return true catch err warn("TerminalMenus: Unable to enter raw mode: $err") @@ -24,7 +24,7 @@ end # Disable raw mode. Give control back to Julia REPL if interactive session. function disableRawMode(term) try - Base.Terminals.raw!(term, false) + REPL.Terminals.raw!(term, false) return true catch err warn("TerminalMenus: Unable to disable raw mode: $err") @@ -39,7 +39,8 @@ readNextChar(stream::IO=STDIN) = Char(read(stream,1)[1]) # Read the next key from STDIN. It is also able to read several bytes for # escaped keys such as the arrow keys, home/end keys, etc. # Escaped keys are returned using the `Key` enum. -function readKey(stream::IO=STDIN) ::UInt32 +readKey(stream::IO=STDIN) = UInt32(_readKey(stream)) +function _readKey(stream::IO=STDIN) c = readNextChar(stream) # Escape characters @@ -104,7 +105,7 @@ function readKey(stream::IO=STDIN) ::UInt32 elseif esc_a == 'H' return HOME_KEY elseif esc_a == 'F' - return END_KEY + return END_KEY end return '\x1b' diff --git a/stdlib/REPL/src/TerminalMenus/test/multiselect_menu.jl b/stdlib/REPL/test/TerminalMenus/multiselect_menu.jl similarity index 100% rename from stdlib/REPL/src/TerminalMenus/test/multiselect_menu.jl rename to stdlib/REPL/test/TerminalMenus/multiselect_menu.jl diff --git a/stdlib/REPL/src/TerminalMenus/test/radio_menu.jl b/stdlib/REPL/test/TerminalMenus/radio_menu.jl similarity index 100% rename from stdlib/REPL/src/TerminalMenus/test/radio_menu.jl rename to stdlib/REPL/test/TerminalMenus/radio_menu.jl diff --git a/stdlib/REPL/src/TerminalMenus/test/runtests.jl b/stdlib/REPL/test/TerminalMenus/runtests.jl similarity index 91% rename from stdlib/REPL/src/TerminalMenus/test/runtests.jl rename to stdlib/REPL/test/TerminalMenus/runtests.jl index 5e9dce14c6a1b..5fe9e2bfb4957 100644 --- a/stdlib/REPL/src/TerminalMenus/test/runtests.jl +++ b/stdlib/REPL/test/TerminalMenus/runtests.jl @@ -1,11 +1,12 @@ -using TerminalMenus -using Base.Test +import REPL +using REPL.TerminalMenus +using Test TerminalMenus.config(supress_output=true) function simulateInput(expectedResult, menu::TerminalMenus.AbstractMenu, keys...) # If we cannot write to the buffer, skip the test - !(:buffer in fieldnames(STDIN)) && return true + !(:buffer in fieldnames(typeof(STDIN))) && return true keydict = Dict(:up => "\e[A", :down => "\e[B", diff --git a/stdlib/REPL/test/runtests.jl b/stdlib/REPL/test/runtests.jl index 548018ece9ce9..8e90870c007ff 100644 --- a/stdlib/REPL/test/runtests.jl +++ b/stdlib/REPL/test/runtests.jl @@ -7,3 +7,6 @@ end module LineEditTest include("lineedit.jl") end +module TerminalMenusTest + include("TerminalMenus/runtests.jl") +end