initial 1.0 fixes

1.0-fixes
Nick 2019-05-15 23:54:19 -04:00
parent 001ba14378
commit 6644ceae76
8 changed files with 59 additions and 56 deletions

View File

@ -1 +1,2 @@
julia 0.6
REPL

View File

@ -28,7 +28,7 @@ function acorn(filename::String; rel::Bool=true)
setStatusMessage(ed, "HELP: ctrl-p: command mode | ctrl-q: quit | ctrl-s: save")
Base.Terminals.raw!(ed.term, true)
REPL.Terminals.raw!(ed.term, true)
try
@ -42,7 +42,7 @@ function acorn(filename::String; rel::Bool=true)
end
Base.Terminals.raw!(ed.term, false)
REPL.Terminals.raw!(ed.term, false)
return nothing
end

View File

@ -5,9 +5,9 @@ module EditorConfig
## Parameter ##
###############
type Parameter{T}
struct Parameter{T}
value::T
validate::Union{Function, Void}
validate::Union{Function, Nothing}
desc::String # Used when calling help <param name>
end

View File

@ -1,4 +1,4 @@
type Command
struct Command
name::Symbol
help::String
cmd::Function

View File

@ -45,7 +45,7 @@ function findCallback(ed::Editor, query::String, key::Char)
end
row = ed.rows[current]
loc = search(row.chars, query)
loc = findfirst(row.chars, query)
if loc != 0:-1
last_match = current
ed.csr.y = current

View File

@ -1,10 +1,12 @@
# """ Clear the screen, print an error message, and kill the program """
# function die(msg)
# write(STDOUT, "\x1b[2J")
# write(STDOUT, "\x1b[H")
# write(Base.stdout, "\x1b[2J")
# write(Base.stdout, "\x1b[H")
# error(msg)
# end
using REPL
using Printf
##########
# CURSOR #
@ -56,7 +58,7 @@ mutable struct Editor
rows::Rows
"terminal hosting this editor"
term::Base.Terminals.TTYTerminal
term::REPL.Terminals.TTYTerminal
"used by commands to store variables"
params::Dict{Symbol, Dict{Symbol, Any}}
@ -76,7 +78,7 @@ function Editor()
csr = Cursor(1,1,1)
rows = Rows()
term = Base.Terminals.TTYTerminal(get(ENV, "TERM", @static is_windows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
term = REPL.Terminals.TTYTerminal(get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb"), Base.Base.stdin, Base.Base.stdout, Base.stderr)
params = Dict{Symbol, Dict{Symbol, Any}}()
@ -324,9 +326,9 @@ end
function refreshScreen(ed::Editor)
# Update terminal size
ed.height = Base.Terminals.height(ed.term) - 2 # status + msg bar = 2
@static is_windows() ? (ed.height -= 1) : ed.height
ed.width = Base.Terminals.width(ed.term)
ed.height = REPL.Terminals.height(ed.term) - 2 # status + msg bar = 2
@static Sys.iswindows() ? (ed.height -= 1) : ed.height
ed.width = REPL.Terminals.width(ed.term)
scroll(ed)
@ -339,12 +341,12 @@ function refreshScreen(ed::Editor)
drawStatusBar(ed, buf)
drawStatusMessage(ed, buf)
@printf(buf, "\x1b[%d;%dH", ed.csr.y-ed.rowoff,
Printf.@printf(buf, "\x1b[%d;%dH", ed.csr.y-ed.rowoff,
ed.csr.rx-ed.coloff)
write(buf, "\x1b[?25h") # ?25h: Show cursor
write(STDOUT, String(take!(buf)))
write(Base.stdout, String(take!(buf)))
end
function editorPrompt(ed::Editor, prompt::String;
@ -358,7 +360,7 @@ function editorPrompt(ed::Editor, prompt::String;
if showcursor
# Position the cursor at the end of the line
@printf(STDOUT, "\x1b[%d;%dH", 999, length(statusmsg)+1)
Printf.@printf(Base.stdout, "\x1b[%d;%dH", 999, length(statusmsg)+1)
end
c = Char(readKey())
@ -508,8 +510,8 @@ function editorQuit(ed::Editor; force::Bool=false)
setStatusMessage(ed,
"File has unsaved changes. Save changes or use <ctrl-p>'quit !' to quit anyway.")
else
write(STDOUT, "\x1b[2J")
write(STDOUT, "\x1b[H")
write(Base.stdout, "\x1b[2J")
write(Base.stdout, "\x1b[H")
ed.quit = true
!isinteractive() && exit(0)
end

View File

@ -22,7 +22,7 @@ function update!(row::Row)
end
# Allocate an array of characters
updated = Array{Char, 1}(length(row.chars) + tabs*(configGet(:tab_stop)-1))
updated = Array{Char, 1}(undef, length(row.chars) + tabs*(configGet(:tab_stop)-1))
# copy the characters into the updated array
idx = 1

View File

@ -1,7 +1,7 @@
import Base.==
@enum(Key,
BACKSPACE = (@static is_windows() ? 8 : 127),
BACKSPACE = (@static Sys.iswindows() ? 8 : 127),
ARROW_LEFT = 1000,
ARROW_RIGHT,
ARROW_UP,
@ -29,109 +29,109 @@ ctrl_key(c::Char)::UInt32 = UInt32(c) & 0x1f
# For debugging
function printNextKey()
term = Base.Terminals.TTYTerminal(get(ENV, "TERM", @static is_windows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
Base.Terminals.raw!(term, true)
term = REPL.Terminals.TTYTerminal(get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb"), Base.stdin, Base.stdout, Base.stderr)
REPL.Terminals.raw!(term, true)
c = readNextChar()
print("Code: $(UInt32(c)), Char: $(Char(c))")
Base.Terminals.raw!(term, true)
REPL.Terminals.raw!(term, true)
return nothing
end
readNextChar() = Char(read(STDIN,1)[1])
readNextChar() = Char(read(Base.stdin,1)[1])
function readKey() ::UInt32
c = readNextChar()
# Escape characters
if c == '\x1b'
STDIN.buffer.size < 3 && return '\x1b'
Base.stdin.buffer.size < 3 && return '\x1b'
esc_a = readNextChar()
esc_b = readNextChar()
if esc_a == '['
if esc_b >= '0' && esc_b <= '9'
STDIN.buffer.size < 4 && return '\x1b'
Base.stdin.buffer.size < 4 && return '\x1b'
esc_c = readNextChar()
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
elseif esc_c == ';'
STDIN.buffer.size < 6 && return '\x1b'
Base.stdin.buffer.size < 6 && return '\x1b'
esc_d = readNextChar()
esc_e = readNextChar()
if esc_d == '2'
# shift + arrorw
if esc_e == 'A'
return S_ARROW_UP
return UInt32(S_ARROW_UP)
elseif esc_e == 'B'
return S_ARROW_DOWN
return UInt32(S_ARROW_DOWN)
elseif esc_e == 'C'
return S_ARROW_RIGHT
return UInt32(S_ARROW_RIGHT)
elseif esc_e == 'D'
return S_ARROW_LEFT
return UInt32(S_ARROW_LEFT)
else
return '\x1b'
return UInt32('\x1b')
end
elseif esc_d == '5'
# Ctrl + arrow
if esc_e == 'A'
return C_ARROW_UP
return UInt32(C_ARROW_UP)
elseif esc_e == 'B'
return C_ARROW_DOWN
return UInt32(C_ARROW_DOWN)
elseif esc_e == 'C'
return C_ARROW_RIGHT
return UInt32(C_ARROW_RIGHT)
elseif esc_e == 'D'
return C_ARROW_LEFT
return UInt32(C_ARROW_LEFT)
else
return '\x1b'
return UInt32('\x1b')
end
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 == 'O'
if esc_a == 'H'
return HOME_KEY
return UInt32(HOME_KEY)
elseif esc_a == 'F'
return END_KEY
return UInt32(END_KEY)
end
end
return '\x1b'
return UInt32('\x1b')
else
return c;
return UInt32(c;)
end
end