Skip to content

Commit

Permalink
Merge pull request #21 from staticfloat/sf/0.7
Browse files Browse the repository at this point in the history
Fixes for 0.7+
  • Loading branch information
Nicholas Paul authored Aug 10, 2018
2 parents f40395c + 1b82f38 commit d359049
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- nightly
notifications:
email: false
Expand Down
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.6
julia 0.7-
Compat 0.55.0
40 changes: 14 additions & 26 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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%"
6 changes: 3 additions & 3 deletions src/AbstractMenu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/MultiSelectMenu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/RadioMenu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/TerminalMenus.jl
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
4 changes: 2 additions & 2 deletions src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
62 changes: 31 additions & 31 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
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",
:enter => "\r")

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

Expand Down

0 comments on commit d359049

Please # to comment.