Skip to content

Commit

Permalink
Upgrade to 0.7 alpha (#14)
Browse files Browse the repository at this point in the history
* Fix deprecations

* Upgrade to 0.7 alpha

* Address the remaining deprecations

* Update travis to 0.7
  • Loading branch information
Keno authored Jun 25, 2018
1 parent 61773bf commit a138720
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: julia
os:
- linux
julia:
- 0.6
- 0.7
- nightly
notifications:
email: false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.6
julia 0.7-alpha
ColorTypes 0.3.4
FixedPointNumbers 0.3.0
31 changes: 15 additions & 16 deletions src/VT100.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion test/TRTtest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
51 changes: 26 additions & 25 deletions test/TerminalRegressionTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module TerminalRegressionTests
using VT100
import REPL

function load_outputs(file)
outputs = String[]
Expand Down Expand Up @@ -31,15 +32,15 @@ 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
end
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
Expand All @@ -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
Expand All @@ -72,29 +73,29 @@ 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)
end
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
Expand All @@ -113,7 +114,7 @@ module TerminalRegressionTests
elseif c == '\n'
println()
else
print_with_color(:red, STDOUT, "")
print_with_color(:red, stdout, "")
end
end
error()
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -165,30 +166,30 @@ 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)
print(emuterm.input_buffer, input); notify(emuterm.filled)
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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using VT100
using Base.Test
using Test

failed_tests = 0
for test in [
Expand All @@ -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))
Expand Down

0 comments on commit a138720

Please sign in to comment.