Skip to content

Commit

Permalink
Do not insert ESC and unassigned ESC+key to input buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Mar 23, 2023
1 parent 957fe49 commit 09fcf0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1571,11 +1571,13 @@ def wrap_method_call(method_symbol, method_obj, key, with_operator = false)
return if key.char >= 128 # maybe, first byte of multi byte
method_symbol = @config.editing_mode.get_method(key.combined_char)
if key.with_meta and method_symbol == :ed_unassigned
# split ESC + key
method_symbol = @config.editing_mode.get_method("\e".ord)
process_key("\e".ord, method_symbol)
method_symbol = @config.editing_mode.get_method(key.char)
process_key(key.char, method_symbol)
if @config.editing_mode_is?(:vi_command, :vi_insert)
# split ESC + key in vi mode
method_symbol = @config.editing_mode.get_method("\e".ord)
process_key("\e".ord, method_symbol)
method_symbol = @config.editing_mode.get_method(key.char)
process_key(key.char, method_symbol)
end
else
process_key(key.combined_char, method_symbol)
end
Expand Down Expand Up @@ -3345,4 +3347,7 @@ def finish
@mark_pointer = new_pointer
end
alias_method :exchange_point_and_mark, :em_exchange_mark

private def em_meta_next(key)
end
end
14 changes: 14 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ def test_mode_string_vi_changing
EOC
end

def test_esc_input
omit if Reline::IOGate.win?
start_terminal(5, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("def\C-aabc")
write("\e") # single ESC
sleep 1
write("A")
write("B\eAC") # ESC + A (M-A, specified ed_unassigned in Reline::KeyActor::Emacs)
assert_screen(<<~EOC)
Multiline REPL.
prompt> abcABCdef
EOC
end

def test_prompt_with_escape_sequence
ENV['RELINE_TEST_PROMPT'] = "\1\e[30m\2prompt> \1\e[m\2"
start_terminal(5, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
Expand Down

0 comments on commit 09fcf0a

Please sign in to comment.