From b83c83cbb832f52852d11ced4cf1f53bf3169b4c Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Fri, 21 Jul 2017 21:09:09 +0200 Subject: [PATCH] revert some stuff (#90) * Revert "add noop for buffer of IOBuffer (#88)" This reverts commit 22d54acff6604f6098f59730767b8857c05e8cc2. * Revert "only run certain test on linux" This reverts commit a6d98ef5be60b3479a0f6b01c6b512d6365b5aac. * Revert "Fix a number of instances of flickering (#86)" This reverts commit 52aa257967531612213a229a0958e033a017cdf0. --- src/BracketInserter.jl | 28 +++---- src/repl.jl | 76 +++++++++---------- test/REQUIRE | 1 - test/flicker.jl | 20 ----- test/flicker/simple.multiout | 140 ----------------------------------- test/runtests.jl | 3 - 6 files changed, 50 insertions(+), 218 deletions(-) delete mode 100644 test/REQUIRE delete mode 100644 test/flicker.jl delete mode 100644 test/flicker/simple.multiout diff --git a/src/BracketInserter.jl b/src/BracketInserter.jl index 13138a5..697e5ba 100644 --- a/src/BracketInserter.jl +++ b/src/BracketInserter.jl @@ -44,19 +44,19 @@ function insert_into_keymap!(D::Dict) # If we enter a left bracket automatically complete it if the next # char is a whitespace or a right bracket D[l] = (s, o...) -> begin - edit_insert(buffer(s), l) + edit_insert(s, l) if AUTOMATIC_BRACKET_MATCH[] && (eof(buffer(s)) || peek(buffer(s)) in right_brackets_ws) - edit_insert(buffer(s), r) - edit_move_left(buffer(s)) + edit_insert(s, r) + edit_move_left(s) end rewrite_with_ANSI(s) end # If we enter a right bracket and the next char is that right bracket just move right D[r] = (s, o...) -> begin if AUTOMATIC_BRACKET_MATCH[] && !eof(buffer(s)) && peek(buffer(s)) == r - edit_move_right(buffer(s)) + edit_move_right(s) else - edit_insert(buffer(s), r) + edit_insert(s, r) end rewrite_with_ANSI(s) end @@ -68,15 +68,15 @@ function insert_into_keymap!(D::Dict) b = buffer(s) # Next char is the quote symbol so just move right if AUTOMATIC_BRACKET_MATCH[] && !eof(b) && peek(b) == v - edit_move_right(buffer(s)) + edit_move_right(s) elseif AUTOMATIC_BRACKET_MATCH[] && ((position(b) > 0 && leftpeek(b) in all_brackets_ws && (eof(b) || peek(b) in right_brackets_ws)) || ((!eof(b) && peek(b) in right_brackets_ws) || b.size == 0) && (position(b) == 0 || leftpeek(b) in left_brackets_ws)) - edit_insert(buffer(s), v) - edit_insert(buffer(s), v) - edit_move_left(buffer(s)) + edit_insert(s, v) + edit_insert(s, v) + edit_move_left(s) else - edit_insert(buffer(s), v) + edit_insert(s, v) end rewrite_with_ANSI(s) end @@ -101,14 +101,14 @@ function insert_into_keymap!(D::Dict) if AUTOMATIC_BRACKET_MATCH[] && !eof(buffer(s)) && position(buffer(s)) != 0 i = findfirst(left_brackets2, str[prevind(str, position(b) + 1)]) if i != 0 && peek(b) == right_brackets2[i] - edit_move_right(buffer(s)) - edit_backspace(buffer(s)) - edit_backspace(buffer(s)) + edit_move_right(s) + edit_backspace(s) + edit_backspace(s) rewrite_with_ANSI(s) return end end - edit_backspace(buffer(s)) + edit_backspace(s) end rewrite_with_ANSI(s) end diff --git a/src/repl.jl b/src/repl.jl index 4edc56c..e25a09f 100644 --- a/src/repl.jl +++ b/src/repl.jl @@ -34,77 +34,72 @@ function rewrite_with_ANSI(s, cursormove::Bool = false) mode = s end - outbuf = IOBuffer() - termbuf = Base.Terminals.TerminalBuffer(outbuf) - # Hide the cursor - LineEdit.write(outbuf, "\e[?25l") - LineEdit.clear_input_area(termbuf, mode) + LineEdit.write(terminal(s), "\e[?25l") # Hide the cursor + LineEdit.clear_input_area(terminal(s), mode) # Extract the cursor index in character count cursoridx = length(String(buffer(s).data[1:p])) l = strwidth(get_prompt(s)) - if !isa(s, LineEdit.SearchState) - LineEdit.write_prompt(termbuf, mode) - LineEdit.write(termbuf, "\e[0m") # Reset any formatting from Julia so that we start with a clean slate - end # Insert colorized text from running the passes + b = IOBuffer() tokens = collect(Lexers.Lexer(buffer(s))) apply_passes!(PASS_HANDLER, tokens, cursoridx, cursormove) - untokenize_with_ANSI(outbuf, PASS_HANDLER , tokens, l) + untokenize_with_ANSI(b, PASS_HANDLER , tokens, l) + if !isa(s, LineEdit.SearchState) + LineEdit.write_prompt(terminal(s), mode) + LineEdit.write(terminal(s), "\e[0m") # Reset any formatting from Julia so that we start with a clean slate + end + write(terminal(s), String(take!(b))) # Reset the buffer since the Lexer messed with it (maybe the Lexer should reset it on done) seek(buffer(s), p) # Our cursor now seems to be out of place, we run the already existing refresh_multi_line code to put it where it belongs. # Maybe it is possible to save the cursor and just restore it but that is probably Terminal dependent... - mode.ias = refresh_multi_line(termbuf, terminal(s), buffer(s), mode.ias, l) - LineEdit.write(outbuf, "\e[?25h") # Show the cursor - write(terminal(s), take!(outbuf)) + obuff = IOBuffer() + q = Base.Terminals.TerminalBuffer(obuff) + mode.ias = refresh_multi_line(q, terminal(s), buffer(s), mode.ias, l) + write(terminal(s), take!(obuff)) + LineEdit.write(terminal(s), "\e[?25h") # Show the cursor flush(terminal(s)) end -buffer(io::IOBuffer) = io - function create_keybindings() D = Dict{Any, Any}() - D['\b'] = (s, data, c) -> if LineEdit.edit_backspace(buffer(s)) - rewrite_with_ANSI(s) - else - beep(terminal(s)) - end - D["*"] = (s, data, c) -> (LineEdit.edit_insert(buffer(s), c); rewrite_with_ANSI(s)) - D["^B"] = (s, data, c) -> (LineEdit.edit_move_left(buffer(s)) ;rewrite_with_ANSI(s)) - D["^F"] = (s, data, c) -> (LineEdit.edit_move_right(buffer(s)) ;rewrite_with_ANSI(s)) + D['\b'] = (s, data, c) -> (LineEdit.edit_backspace(s); rewrite_with_ANSI(s)) + D["*"] = (s, data, c) -> (LineEdit.edit_insert(s, c); rewrite_with_ANSI(s)) + D["^B"] = (s, data, c) -> (LineEdit.edit_move_left(s) ;rewrite_with_ANSI(s)) + D["^F"] = (s, data, c) -> (LineEdit.edit_move_right(s) ;rewrite_with_ANSI(s)) # Meta B - D["\eb"] = (s, data, c) -> (LineEdit.edit_move_word_left(buffer(s)) ; rewrite_with_ANSI(s)) + D["\eb"] = (s, data, c) -> (LineEdit.edit_move_word_left(s) ; rewrite_with_ANSI(s)) # Meta F - D["\ef"] = (s, data, c) -> (LineEdit.edit_move_word_right(buffer(s)); rewrite_with_ANSI(s)) + D["\ef"] = (s, data, c) -> (LineEdit.edit_move_word_right(s); rewrite_with_ANSI(s)) # Meta Enter - D["\e\r"] = (s, data, c) -> (LineEdit.edit_insert(buffer(s), '\n'); rewrite_with_ANSI(s)) + D["\e\r"] = (s, data, c) -> (LineEdit.edit_insert(s, '\n'); rewrite_with_ANSI(s)) D["^A"] = (s, data, c) -> (LineEdit.move_line_start(s); rewrite_with_ANSI(s)) D["^E"] = (s, data, c) -> (LineEdit.move_line_end(s); rewrite_with_ANSI(s)) - D["\e[H"] = (s, data, c) -> (LineEdit.move_input_start(buffer(s)); rewrite_with_ANSI(s)) - D["\e[F"] = (s, data, c) -> (LineEdit.move_input_end(buffer(s)); rewrite_with_ANSI(s)) + D["\e[H"] = (s, data, c) -> (LineEdit.move_input_start(s); rewrite_with_ANSI(s)) + D["\e[F"] = (s, data, c) -> (LineEdit.move_input_end(s); rewrite_with_ANSI(s)) D["^L"] = (s, data, c) -> (Terminals.clear(terminal(s)); rewrite_with_ANSI(s)) - D["^W"] = (s, data, c) -> LineEdit.edit_werase(buffer(s)) + D["^W"] = (s, data, c) -> LineEdit.edit_werase(s) # Right Arrow - D["\e[C"] = (s, data, c)->(LineEdit.edit_move_right(buffer(s)); rewrite_with_ANSI(s)) + D["\e[C"] = (s, data, c)->(LineEdit.edit_move_right(s); rewrite_with_ANSI(s)) # Left Arrow - D["\e[D"] = (s, data, c)->(LineEdit.edit_move_left(buffer(s)); rewrite_with_ANSI(s)) + D["\e[D"] = (s, data, c)->(LineEdit.edit_move_left(s); rewrite_with_ANSI(s)) # Up Arrow # Delete - D["\e[3~"] = (s, data, c)->(LineEdit.edit_delete(buffer(s)); rewrite_with_ANSI(s)) - D["^T"] = (s, data, c)->(LineEdit.edit_transpose(buffer(s)); rewrite_with_ANSI(s)) - D["\ed"] = (s, data, c)->(LineEdit.edit_delete_next_word(buffer(s)); rewrite_with_ANSI(s)) - D["\e\b"] = (s, data, c)->(LineEdit.edit_delete_prev_word(buffer(s)); rewrite_with_ANSI(s)) + D["\e[3~"] = (s, data, c)->(LineEdit.edit_delete(s); rewrite_with_ANSI(s)) + D["^T"] = (s, data, c)->(LineEdit.edit_transpose(s); rewrite_with_ANSI(s)) + D["\ed"] = (s, data, c)->(LineEdit.edit_delete_next_word(s); rewrite_with_ANSI(s)) + D["\e\b"] = (s, data, c)->edit_delete_prev_word(s) D["^N"] = (s,data,c)->(LineEdit.history_next(s, mode(s).hist); rewrite_with_ANSI(s)) D["^P"] = (s,data,c)->(LineEdit.history_prev(s, mode(s).hist); rewrite_with_ANSI(s)) D["^D"] = (s, data, c)->begin if buffer(s).size > 0 - LineEdit.edit_delete(buffer(s)); rewrite_with_ANSI(s) + LineEdit.edit_delete(s); rewrite_with_ANSI(s) else println(terminal(s)) return :abort @@ -128,7 +123,7 @@ function create_keybindings() end return :done else - edit_insert(buffer(s), '\n') + edit_insert(s, '\n') rewrite_with_ANSI(s) end end @@ -260,18 +255,19 @@ end NEW_KEYBINDINGS = create_keybindings() -function insert_keybindings(repl = Base.active_repl) +function insert_keybindings() + repl = Base.active_repl mirepl = isdefined(repl,:mi) ? repl.mi : repl main_mode = mirepl.interface.modes[1] p = mirepl.interface.modes[5] NEW_KEYBINDINGS["\e[A"] = (s,o...)-> begin - LineEdit.edit_move_up(buffer(s)) || LineEdit.enter_prefix_search(s, p, true) + LineEdit.edit_move_up(s) || LineEdit.enter_prefix_search(s, p, true) Prompt.rewrite_with_ANSI(s) end # Down Arrow NEW_KEYBINDINGS["\e[B"] = (s,o...)-> begin - LineEdit.edit_move_down(buffer(s)) || LineEdit.enter_prefix_search(s, p, false) + LineEdit.edit_move_down(s) || LineEdit.enter_prefix_search(s, p, false) Prompt.rewrite_with_ANSI(s) end diff --git a/test/REQUIRE b/test/REQUIRE deleted file mode 100644 index d3e33be..0000000 --- a/test/REQUIRE +++ /dev/null @@ -1 +0,0 @@ -VT100 0.2.0 diff --git a/test/flicker.jl b/test/flicker.jl deleted file mode 100644 index 0f2d101..0000000 --- a/test/flicker.jl +++ /dev/null @@ -1,20 +0,0 @@ -using OhMyREPL - -include(Pkg.dir("VT100","test","TerminalRegressionTests.jl")) - -const thisdir = dirname(@__FILE__) -TerminalRegressionTests.automated_test( - joinpath(thisdir,"flicker/simple.multiout"), - # Test a bunch of intersting cases: - # - Typing out keywords - # - Inserting/deleting braces - # - Newlines - # and try to make sure nothing flickers - [c for c in "function foo(a = b())\nend\n\x4"], - aggressive_yield=true) do emuterm - repl = Base.REPL.LineEditREPL(emuterm) - repl.specialdisplay = val->display(Base.REPL.REPLDisplay(repl), val) - repl.interface = Base.REPL.setup_interface(repl) - OhMyREPL.Prompt.insert_keybindings(repl) - Base.REPL.run_repl(repl) -end diff --git a/test/flicker/simple.multiout b/test/flicker/simple.multiout deleted file mode 100644 index e3b597c..0000000 --- a/test/flicker/simple.multiout +++ /dev/null @@ -1,140 +0,0 @@ -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> --------------------------------------------------- -|AAAAAAA -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> f --------------------------------------------------- -|AAAAAAAB -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> fu --------------------------------------------------- -|AAAAAAABB -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> fun --------------------------------------------------- -|AAAAAAABBB -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> func --------------------------------------------------- -|AAAAAAABBBB -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> funct --------------------------------------------------- -|AAAAAAABBBBB -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> functi --------------------------------------------------- -|AAAAAAABBBBBB -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> functio --------------------------------------------------- -|AAAAAAABBBBBBB -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function --------------------------------------------------- -|AAAAAAABBBBBBBB -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function --------------------------------------------------- -|AAAAAAABBBBBBBBC -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function f --------------------------------------------------- -|AAAAAAABBBBBBBBCC -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function fo --------------------------------------------------- -|AAAAAAABBBBBBBBCCC -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo --------------------------------------------------- -|AAAAAAABBBBBBBBCCCC -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo() --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDEE -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a) --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECE -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a ) --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCE -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a =) --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCBE -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a = ) --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCBCE -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a = b) --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCBCCE -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a = b()) --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCBCFGGE -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a = b()) --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCBCFGGE -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a = b()) --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCBCFGGE -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a = b()) -| --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCBCFGGE -|CCCCCCC -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a = b()) -| e -| --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCBCFGGE -|CCCCCCCC -| -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a = b()) -| en -| -| --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCBCFGGE -|CCCCCCCCC -| -| -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a = b()) -| end -| -| -| --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCBCFGGE -|CCCCCCCBBB -| -| -| -++++++++++++++++++++++++++++++++++++++++++++++++++ -|julia> function foo(a = b()) -| end -| -| -| -| -| --------------------------------------------------- -|AAAAAAABBBBBBBBCDDDECCBCFGGE -|CCCCCCCBBB -| -| -| -| -| \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 64d79f4..fc7ed40 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,7 +1,4 @@ withenv("FORCE_COLOR" => true) do - if is_linux() - include("flicker.jl") - end include("test_custompass.jl") include("test_bracketmatch.jl") include("test_highlighter.jl")