diff --git a/.travis.yml b/.travis.yml index 6d6b810..f3e1d16 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ os: - linux - osx julia: - - 0.6 + - 0.7 - nightly notifications: email: false diff --git a/REQUIRE b/REQUIRE index 137767a..8ee5b74 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1,2 @@ -julia 0.6 +julia 0.7- +Compat 0.55.0 diff --git a/appveyor.yml b/appveyor.yml index 19b36b9..1fb41f1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,16 +1,16 @@ 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" + - julia_version: 0.7 + - julia_version: latest -## uncomment the following lines to allow failures on nightly julia +# 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" +# allow_failures: +# - julia_version: latest + +platform: + - x86 + - x64 branches: only: @@ -24,24 +24,12 @@ notifications: 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 + - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1")) 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\")" + - echo "%JL_BUILD_SCRIPT%" + - C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%" test_script: - - C:\projects\julia\bin\julia -e "Pkg.test(\"TerminalMenus\")" + - echo "%JL_TEST_SCRIPT%" + - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" diff --git a/src/AbstractMenu.jl b/src/AbstractMenu.jl index 367e184..9adbac3 100644 --- a/src/AbstractMenu.jl +++ b/src/AbstractMenu.jl @@ -100,7 +100,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) function advance_cursor() if cursor < length(options(m)) @@ -217,7 +217,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) @@ -257,7 +257,7 @@ function printMenu(out, m::AbstractMenu, cursor::Int; init::Bool=false) print(buf, " ") end - term_width = Base.Terminals.width(TerminalMenus.terminal) + term_width = REPL.Terminals.width(TerminalMenus.terminal) writeLine(buf, m, i, i == cursor, term_width) diff --git a/src/MultiSelectMenu.jl b/src/MultiSelectMenu.jl index e35baec..08d6a86 100644 --- a/src/MultiSelectMenu.jl +++ b/src/MultiSelectMenu.jl @@ -97,7 +97,7 @@ function writeLine(buf::IOBuffer, menu::MultiSelectMenu, idx::Int, cursor::Bool, print(buf, CONFIG[status], " ") padding = length(CONFIG[status]) + 1 - line = replace(menu.options[idx], "\n", "\\n") + line = replace(menu.options[idx], "\n" => "\\n") line = trimWidth(line, term_width, !cursor, cursor_len + padding) print(buf, line) diff --git a/src/RadioMenu.jl b/src/RadioMenu.jl index efbdca0..7e53c98 100644 --- a/src/RadioMenu.jl +++ b/src/RadioMenu.jl @@ -75,7 +75,7 @@ function writeLine(buf::IOBuffer, menu::RadioMenu, idx::Int, cursor::Bool, term_ cursor ? print(buf, CONFIG[:cursor]) : print(buf, repeat(" ", cursor_len)) print(buf, " ") # Space between cursor and text - line = replace(menu.options[idx], "\n", "\\n") + line = replace(menu.options[idx], "\n" => "\\n") line = trimWidth(line, term_width, !cursor, cursor_len) print(buf, line) diff --git a/src/TerminalMenus.jl b/src/TerminalMenus.jl index fa032e0..d0fe987 100644 --- a/src/TerminalMenus.jl +++ b/src/TerminalMenus.jl @@ -1,11 +1,12 @@ -__precompile__() module TerminalMenus +using Compat +using REPL terminal = nothing # The user terminal 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"), Base.stdin, Base.stdout, Base.stderr) end include("util.jl") diff --git a/src/config.jl b/src/config.jl index db3f295..ce9b479 100644 --- a/src/config.jl +++ b/src/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/src/util.jl b/src/util.jl index b8128e6..6e6d2fe 100644 --- a/src/util.jl +++ b/src/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") @@ -45,13 +45,13 @@ function trimWidth(str::String, term_width::Int, trim_right=true, pad::Int=2) end -# Reads a single byte from STDIN -readNextChar(stream::IO=STDIN) = Char(read(stream,1)[1]) +# Reads a single byte from stdin +readNextChar(stream::IO=Base.stdin) = Char(read(stream,1)[1]) -# Read the next key from STDIN. It is also able to read several bytes for +# 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 +function readKey(stream::IO=Base.stdin) ::UInt32 c = readNextChar(stream) # Escape characters @@ -60,11 +60,11 @@ function readKey(stream::IO=STDIN) ::UInt32 esc_a = readNextChar(stream) if esc_a == 'v' # M-v - return PAGE_UP + return UInt32(PAGE_UP) elseif esc_a == '<' # M-< - return HOME_KEY + return UInt32(HOME_KEY) elseif esc_a == '>' # M-> - return END_KEY + return UInt32(END_KEY) end stream.buffer.size < 3 && return '\x1b' @@ -77,57 +77,57 @@ function readKey(stream::IO=STDIN) ::UInt32 if esc_c == '~' if esc_b == '1' - return HOME_KEY + return UInt32(HOME_KEY) elseif esc_b == '4' - return END_KEY + return UInt32(END_KEY) elseif esc_b == '3' - return DEL_KEY + return UInt32(DEL_KEY) elseif esc_b == '5' - return PAGE_UP + return UInt32(PAGE_UP) elseif esc_b == '6' - return PAGE_DOWN + return UInt32(PAGE_DOWN) elseif esc_b == '7' - return HOME_KEY + return UInt32(HOME_KEY) elseif esc_b == '8' - return END_KEY + return UInt32(END_KEY) else - return '\x1b' + return UInt32('\x1b') end end else # Arrow keys if esc_b == 'A' - return ARROW_UP + return UInt32(ARROW_UP) elseif esc_b == 'B' - return ARROW_DOWN + return UInt32(ARROW_DOWN) elseif esc_b == 'C' - return ARROW_RIGHT + return UInt32(ARROW_RIGHT) elseif esc_b == 'D' - return ARROW_LEFT + return UInt32(ARROW_LEFT) elseif esc_b == 'H' - return HOME_KEY + return UInt32(HOME_KEY) elseif esc_b == 'F' - return END_KEY + return UInt32(END_KEY) else - return '\x1b' + return UInt32('\x1b') end end elseif esc_a == 'H' - return HOME_KEY + return UInt32(HOME_KEY) elseif esc_a == 'F' - return END_KEY + return UInt32(END_KEY) end - return '\x1b' + return UInt32('\x1b') elseif c == '\x16' # C-v - return PAGE_DOWN + return UInt32(PAGE_DOWN) elseif c == '\x10' # C-p - return ARROW_UP + return UInt32(ARROW_UP) elseif c == '\x0e' # C-n - return ARROW_DOWN + return UInt32(ARROW_DOWN) else - return c + return UInt32(c) end end diff --git a/test/runtests.jl b/test/runtests.jl index 5e9dce1..2241e8b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,11 +1,11 @@ using TerminalMenus -using Base.Test +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(Base.stdin))) && return true keydict = Dict(:up => "\e[A", :down => "\e[B", @@ -13,9 +13,9 @@ function simulateInput(expectedResult, menu::TerminalMenus.AbstractMenu, keys... for key in keys if isa(key, Symbol) - write(STDIN.buffer, keydict[key]) + write(Base.stdin.buffer, keydict[key]) else - write(STDIN.buffer, "$key") + write(Base.stdin.buffer, "$key") end end