From 0752fff2152c86caa67d7a0dafcfda3582fbf384 Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Mon, 7 Oct 2024 09:37:29 +0900 Subject: [PATCH] [ruby/reline] Add cursor keys for application keypad mode to default key bindings (https://github.com/ruby/reline/pull/719) * Add SS3 arrow sequence to default key bindings * Remove wrong KDE arrow sequence https://github.com/ruby/reline/commit/546a42522e --- lib/reline/io/ansi.rb | 23 ++++------------------- test/reline/test_ansi_without_terminfo.rb | 4 ---- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/lib/reline/io/ansi.rb b/lib/reline/io/ansi.rb index 82d2ee2371..cf0c1c1b31 100644 --- a/lib/reline/io/ansi.rb +++ b/lib/reline/io/ansi.rb @@ -75,7 +75,10 @@ class Reline::ANSI < Reline::IO def set_default_key_bindings_ansi_cursor(config) ANSI_CURSOR_KEY_BINDINGS.each do |char, (default_func, modifiers)| - bindings = [["\e[#{char}", default_func]] # CSI + char + bindings = [ + ["\e[#{char}", default_func], # CSI + char + ["\eO#{char}", default_func] # SS3 + char, application cursor key mode + ] if modifiers[:ctrl] # CSI + ctrl_key_modifier + char bindings << ["\e[1;5#{char}", modifiers[:ctrl]] @@ -123,27 +126,9 @@ class Reline::ANSI < Reline::IO [27, 91, 49, 126] => :ed_move_to_beg, # Home [27, 91, 52, 126] => :ed_move_to_end, # End - # KDE - # Del is 0x08 - [27, 71, 65] => :ed_prev_history, # ↑ - [27, 71, 66] => :ed_next_history, # ↓ - [27, 71, 67] => :ed_next_char, # → - [27, 71, 68] => :ed_prev_char, # ← - # urxvt / exoterm [27, 91, 55, 126] => :ed_move_to_beg, # Home [27, 91, 56, 126] => :ed_move_to_end, # End - - # GNOME - [27, 79, 72] => :ed_move_to_beg, # Home - [27, 79, 70] => :ed_move_to_end, # End - # Del is 0x08 - # Arrow keys are the same of KDE - - [27, 79, 65] => :ed_prev_history, # ↑ - [27, 79, 66] => :ed_next_history, # ↓ - [27, 79, 67] => :ed_next_char, # → - [27, 79, 68] => :ed_prev_char, # ← }.each_pair do |key, func| config.add_default_key_binding_by_keymap(:emacs, key, func) config.add_default_key_binding_by_keymap(:vi_insert, key, func) diff --git a/test/reline/test_ansi_without_terminfo.rb b/test/reline/test_ansi_without_terminfo.rb index 2db14cf0a0..62b1e7dec0 100644 --- a/test/reline/test_ansi_without_terminfo.rb +++ b/test/reline/test_ansi_without_terminfo.rb @@ -32,25 +32,21 @@ class Reline::ANSI::WithoutTerminfoTest < Reline::TestCase def test_up_arrow assert_key_binding("\e[A", :ed_prev_history) # Console (80x25) - assert_key_binding("\eGA", :ed_prev_history) # KDE assert_key_binding("\eOA", :ed_prev_history) end def test_down_arrow assert_key_binding("\e[B", :ed_next_history) # Console (80x25) - assert_key_binding("\eGB", :ed_next_history) # KDE assert_key_binding("\eOB", :ed_next_history) end def test_right_arrow assert_key_binding("\e[C", :ed_next_char) # Console (80x25) - assert_key_binding("\eGC", :ed_next_char) # KDE assert_key_binding("\eOC", :ed_next_char) end def test_left_arrow assert_key_binding("\e[D", :ed_prev_char) # Console (80x25) - assert_key_binding("\eGD", :ed_prev_char) # KDE assert_key_binding("\eOD", :ed_prev_char) end