From a13872010a92c9827e8e1d21c0eed8dadda2c895 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Mon, 25 Jun 2018 16:52:04 -0400 Subject: [PATCH] Upgrade to 0.7 alpha (#14) * Fix deprecations * Upgrade to 0.7 alpha * Address the remaining deprecations * Update travis to 0.7 --- .travis.yml | 2 +- README.md | 2 +- REQUIRE | 2 +- src/VT100.jl | 31 ++++++++++---------- test/TRTtest.jl | 3 +- test/TerminalRegressionTests.jl | 51 +++++++++++++++++---------------- test/runtests.jl | 8 +++--- 7 files changed, 50 insertions(+), 49 deletions(-) diff --git a/.travis.yml b/.travis.yml index e58e697..e70b9c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: julia os: - linux julia: - - 0.6 + - 0.7 - nightly notifications: email: false diff --git a/README.md b/README.md index 0d11054..b499820 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ pty = VT100.create_pty() # [Should pass pty.slave to C library, e.g. ncurses here] # Now obtain a debug dump of the screen state buf = IOBuffer() -VT100.dump(buf,DevNull,em) +VT100.dump(buf,devnull,em) # buf now contains the screen contents of the emulator ``` For more examples, see the test directory. diff --git a/REQUIRE b/REQUIRE index 8b3a805..bdbb597 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,3 @@ -julia 0.6 +julia 0.7-alpha ColorTypes 0.3.4 FixedPointNumbers 0.3.0 diff --git a/src/VT100.jl b/src/VT100.jl index b1e5525..cc37acb 100644 --- a/src/VT100.jl +++ b/src/VT100.jl @@ -4,14 +4,14 @@ module VT100 using ColorTypes using FixedPointNumbers -using Compat const RGB8 = RGB{N0f8} export ScreenEmulator, LineEmulator, Emulator, parse!, parse_cell!, Cell, parseall! import Base: convert, write -import Base.Terminals: cmove_right +import REPL +import REPL.Terminals: cmove_right import Base: start, next, done, setindex!, getindex, endof module Attributes @@ -141,7 +141,7 @@ mutable struct ScreenEmulator <: Emulator linedrawing::Bool function ScreenEmulator(width = 80, height = 24) this = new(Size(width, height),1, - Vector{String}(0),Vector{Line}(0),Cursor(1,1),Cell('\0'), + Vector{String}(),Vector{Line}(),Cursor(1,1),Cell('\0'), false, false, false) add_line!(this) this @@ -165,7 +165,7 @@ function cmove_right(em::ScreenEmulator, n) end function cmove_col(em::ScreenEmulator, n) if n == 0 - em.warn && println(STDERR, "BAD DATA: Columns are 1 indexed.") + em.warn && println(stderr, "BAD DATA: Columns are 1 indexed.") n = 1 end em.debug && println("Moving to col $n") @@ -230,7 +230,7 @@ function erase_screen(em) end function add_line!(em::Emulator) - a = Array{Cell}(0) + a = Array{Cell}(undef, 0) sizehint!(a, 80) push!(em.lines, a) em.debug && println("Adding line to emulator") @@ -257,7 +257,7 @@ const ExtendedContents = String[] # Render the contents of this emulator into another terminal. function render(term::IO, em::Emulator) - dump(term,DevNull,em) + dump(term,devnull,em) end # Dump the emulator contents as a plain-contents text file and a decorator file @@ -283,7 +283,7 @@ function dump(contents::IO, decorator::IO, em::Emulator, lines = nothing, decora # Write decorator template = Cell(cell,content='\0') if !haskey(decorator_map, template) - decorator_char = shift!(available_decorators) + decorator_char = popfirst!(available_decorators) decorator_map[template] = decorator_char end write(decorator, decorator_map[template]) @@ -330,7 +330,7 @@ function fill_lines(em, from, to) end function add_line!(em::Emulator, pos) - a = Array{Cell}(0) + a = Array{Cell}(undef, 0) sizehint!(a, 80) l = length(em.lines) if pos > l + 1 @@ -369,7 +369,7 @@ function readdec(io) elseif n == 0 return (c, -1) else - return (c, parse(Int, String(take!(decbuf)),10)) + return (c, parse(Int, String(take!(decbuf)), base=10)) end n += 1 end @@ -446,7 +446,7 @@ function parseSGR!(em::Emulator, params) end function parse!(em::Emulator, io::IO) - const debug = true + debug = true c = read(io, Char) if c == '\r' cmove_col(em, 1) @@ -554,18 +554,17 @@ function parse!(em::Emulator, io::IO) end -@static if is_unix() - type PTY +@static if Sys.isunix() + mutable struct PTY em::ScreenEmulator master::Base.TTY slave::RawFD fdm::RawFD end + const O_RDWR = Base.Filesystem.JL_O_RDWR + const O_NOCTTY = Base.Filesystem.JL_O_NOCTTY function create_pty(parse = true) - const O_RDWR = Base.Filesystem.JL_O_RDWR - const O_NOCTTY = Base.Filesystem.JL_O_NOCTTY - fdm = ccall(:posix_openpt,Cint,(Cint,),O_RDWR|O_NOCTTY) fdm == -1 && error("Failed to open PTY master") rc = ccall(:grantpt,Cint,(Cint,),fdm) @@ -582,7 +581,7 @@ end pty = PTY(ScreenEmulator(), master, slave, RawFD(fdm)) parse && @async parseall!(pty.em,master) - finalizer(pty, close) + finalizer(close, pty) pty end diff --git a/test/TRTtest.jl b/test/TRTtest.jl index 13a0030..da33333 100644 --- a/test/TRTtest.jl +++ b/test/TRTtest.jl @@ -7,5 +7,6 @@ TerminalRegressionTests.automated_test( print(emuterm, "Please enter your name: ") name = strip(readline(emuterm)) print(emuterm, "\nHello $name. Do you like tests? ") - @assert strip(readline(emuterm)) == "Yes!!" + resp = strip(readline(emuterm)) + @assert resp == "Yes!!" end diff --git a/test/TerminalRegressionTests.jl b/test/TerminalRegressionTests.jl index 507e2bd..fb995bf 100644 --- a/test/TerminalRegressionTests.jl +++ b/test/TerminalRegressionTests.jl @@ -1,5 +1,6 @@ module TerminalRegressionTests using VT100 + import REPL function load_outputs(file) outputs = String[] @@ -31,7 +32,7 @@ module TerminalRegressionTests continue elseif line[1] == '|' array = is_output ? outputs : decorators - array[end] = string(array[end],isempty(array[end])?"":"\n",line[2:end]) + array[end] = string(array[end],isempty(array[end]) ? "" : "\n",line[2:end]) else error("Unrecognized first character \"$(line[1])\"") end @@ -39,7 +40,7 @@ module TerminalRegressionTests outputs, decorators end - mutable struct EmulatedTerminal <: Base.Terminals.UnixTerminal + mutable struct EmulatedTerminal <: REPL.Terminals.UnixTerminal input_buffer::IOBuffer out_stream::Base.TTY pty::VT100.PTY @@ -58,7 +59,7 @@ module TerminalRegressionTests end end function Base.wait(term::EmulatedTerminal) - if !term.waiting || nb_available(term.input_buffer) != 0 + if !term.waiting || bytesavailable(term.input_buffer) != 0 wait(term.step) end end @@ -72,7 +73,7 @@ module TerminalRegressionTests end Base.eof(term::EmulatedTerminal) = false function Base.read(term::EmulatedTerminal, ::Type{Char}) - if nb_available(term.input_buffer) == 0 + if bytesavailable(term.input_buffer) == 0 term.waiting = true notify(term.step) wait(term.filled) @@ -80,21 +81,21 @@ module TerminalRegressionTests term.waiting = false read(term.input_buffer, Char) end - function Base.readuntil(term::EmulatedTerminal, delim::UInt8) - if nb_available(term.input_buffer) == 0 + function Base.readuntil(term::EmulatedTerminal, delim::UInt8; kwargs...) + if bytesavailable(term.input_buffer) == 0 term.waiting = true notify(term.step) wait(term.filled) end term.waiting = false - readuntil(term.input_buffer, delim) + readuntil(term.input_buffer, delim; kwargs...) end - Base.Terminals.raw!(t::EmulatedTerminal, raw::Bool) = + REPL.Terminals.raw!(t::EmulatedTerminal, raw::Bool) = ccall(:jl_tty_set_mode, - Int32, (Ptr{Void},Int32), + Int32, (Ptr{Cvoid},Int32), t.out_stream.handle, raw) != -1 - Base.Terminals.pipe_reader(t::EmulatedTerminal) = t.input_buffer - Base.Terminals.pipe_writer(t::EmulatedTerminal) = t.out_stream + REPL.Terminals.pipe_reader(t::EmulatedTerminal) = t.input_buffer + REPL.Terminals.pipe_writer(t::EmulatedTerminal) = t.out_stream function _compare(output, outbuf) result = outbuf == output @@ -113,7 +114,7 @@ module TerminalRegressionTests elseif c == '\n' println() else - print_with_color(:red, STDOUT, "█") + print_with_color(:red, stdout, "█") end end error() @@ -127,9 +128,9 @@ module TerminalRegressionTests VT100.dump(buf,decoratorbuf,em) outbuf = take!(buf) decoratorbuf = take!(decoratorbuf) - _compare(Vector{UInt8}(output), outbuf) || return false + _compare(Vector{UInt8}(codeunits(output)), outbuf) || return false decorator === nothing && return true - _compare(Vector{UInt8}(decorator), decoratorbuf) + _compare(Vector{UInt8}(codeunits(decorator)), decoratorbuf) end function process_all_buffered(emuterm) @@ -138,17 +139,17 @@ module TerminalRegressionTests # kernel and being available to epoll. We write a sentintel value # here and wait for it to be read back. sentinel = Ref{UInt32}(0xffffffff) - ccall(:write, Void, (Cint, Ptr{UInt32}, Csize_t), emuterm.pty.slave, sentinel, sizeof(UInt32)) + ccall(:write, Cvoid, (Cint, Ptr{UInt32}, Csize_t), emuterm.pty.slave, sentinel, sizeof(UInt32)) Base.process_events(false) # Read until we get our sentinel - while nb_available(emuterm.pty.master) < sizeof(UInt32) || + while bytesavailable(emuterm.pty.master) < sizeof(UInt32) || reinterpret(UInt32, emuterm.pty.master.buffer.data[(emuterm.pty.master.buffer.size-3):emuterm.pty.master.buffer.size])[] != sentinel[] emuterm.aggressive_yield || yield() Base.process_events(false) - sleep(0.01) + sleep(0.01) end data = IOBuffer(readavailable(emuterm.pty.master)[1:(end-4)]) - while nb_available(data) > 0 + while bytesavailable(data) > 0 VT100.parse!(emuterm.terminal, data) end end @@ -165,15 +166,15 @@ module TerminalRegressionTests f(emuterm) Base.notify(c) catch err - Base.showerror(STDERR, err, catch_backtrace()) + Base.showerror(stderr, err, catch_backtrace()) Base.notify_error(c, err) end t2 = @async try for input in inputs wait(emuterm); emuterm.aggressive_yield || @assert emuterm.waiting - output = shift!(outputs) - decorator = isempty(decorators) ? nothing : shift!(decorators) + output = popfirst!(outputs) + decorator = isempty(decorators) ? nothing : popfirst!(decorators) @assert !eof(emuterm.pty.master) process_all_buffered(emuterm) compare(emuterm.terminal, output, decorator) @@ -181,14 +182,14 @@ module TerminalRegressionTests end Base.notify(c) catch err - Base.showerror(STDERR, err, catch_backtrace()) + Base.showerror(stderr, err, catch_backtrace()) Base.notify_error(c, err) end while !istaskdone(t1) || !istaskdone(t2) wait(c) end end - + function create_automated_test(f, outputpath, inputs; aggressive_yield=false) emuterm = EmulatedTerminal() emuterm.aggressive_yield = aggressive_yield @@ -200,7 +201,7 @@ module TerminalRegressionTests f(emuterm) Base.notify(c) catch err - Base.showerror(STDERR, err, catch_backtrace()) + Base.showerror(stderr, err, catch_backtrace()) Base.notify_error(c, err) end t2 = @async try @@ -229,7 +230,7 @@ module TerminalRegressionTests end Base.notify(c) catch err - Base.showerror(STDERR, err, catch_backtrace()) + Base.showerror(stderr, err, catch_backtrace()) Base.notify_error(c, err) end while !istaskdone(t1) || !istaskdone(t2) diff --git a/test/runtests.jl b/test/runtests.jl index 6158fb2..ad280eb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using VT100 -using Base.Test +using Test failed_tests = 0 for test in [ @@ -12,16 +12,16 @@ for test in [ open(f->(parseall!(em,f)),string(basepath,".raw.in")) else @assert isfile(string(basepath,".in")) - open(f->(parseall!(em,IOBuffer(unescape_string(readstring(f))))), + open(f->(parseall!(em,IOBuffer(unescape_string(read(f, String))))), string(basepath,".in")) end output = open(read,string(basepath,".out")) buf = IOBuffer() - VT100.dump(buf,DevNull,em) + VT100.dump(buf,devnull,em) outbuf = take!(buf) if outbuf != output print_with_color(:red, "Failed test $test\n") - failed_tests += 1 + global failed_tests += 1 println(output) println(outbuf) println(String(output))