Skip to content

Commit

Permalink
Add cursor keys for application keypad mode to default key bindings (#…
Browse files Browse the repository at this point in the history
…719)

* Add SS3 arrow sequence to default key bindings

* Remove wrong KDE arrow sequence
  • Loading branch information
tompng authored Oct 7, 2024
1 parent 9844b99 commit 546a425
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
23 changes: 4 additions & 19 deletions lib/reline/io/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def set_bracketed_paste_key_bindings(config)

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]]
Expand Down Expand Up @@ -123,27 +126,9 @@ def set_default_key_bindings_comprehensive_list(config)
[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)
Expand Down
4 changes: 0 additions & 4 deletions test/reline/test_ansi_without_terminfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,21 @@ def test_delete

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

Expand Down

0 comments on commit 546a425

Please sign in to comment.