From 3aeea2ad4e7c06d4ccb36548a18ef091b12cd4e1 Mon Sep 17 00:00:00 2001 From: Phillip Hellewell Date: Tue, 21 Mar 2023 08:48:25 -0600 Subject: [PATCH] Add key bindings for PgUp and PgDn (#509) * Add key bindings for PgUp, PgDn * Match behavior of readline 8.2 In the latest readline (8.2), page-up and page-down are bound to history-search-backward and history-search-forward by default. We would like reline to have the same default behavior. --- lib/reline/ansi.rb | 2 ++ test/reline/test_ansi_with_terminfo.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb index 42a3913387..06ea9efd09 100644 --- a/lib/reline/ansi.rb +++ b/lib/reline/ansi.rb @@ -8,6 +8,8 @@ class Reline::ANSI 'khome' => :ed_move_to_beg, 'kend' => :ed_move_to_end, 'kdch1' => :key_delete, + 'kpp' => :ed_search_prev_history, + 'knp' => :ed_search_next_history, 'kcuu1' => :ed_prev_history, 'kcud1' => :ed_next_history, 'kcuf1' => :ed_next_char, diff --git a/test/reline/test_ansi_with_terminfo.rb b/test/reline/test_ansi_with_terminfo.rb index a6c3a5e500..d7f61806a6 100644 --- a/test/reline/test_ansi_with_terminfo.rb +++ b/test/reline/test_ansi_with_terminfo.rb @@ -33,6 +33,20 @@ def test_kdch1 omit e.message end + # PgUp key + def test_kpp + assert_key_binding(Reline::Terminfo.tigetstr('kpp'), :ed_search_prev_history) + rescue Reline::Terminfo::TerminfoError => e + omit e.message + end + + # PgDn key + def test_knp + assert_key_binding(Reline::Terminfo.tigetstr('knp'), :ed_search_next_history) + rescue Reline::Terminfo::TerminfoError => e + omit e.message + end + # Up arrow key def test_kcuu1 assert_key_binding(Reline::Terminfo.tigetstr('kcuu1'), :ed_prev_history)