From 1d0d8a89d404147f23b3d3ed1e1353be8adc2f2b Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Tue, 11 Jun 2024 00:31:28 +0900 Subject: [PATCH] [ruby/reline] Add more fallbacks when terminfo is not available (https://github.com/ruby/reline/pull/722) Add xterm key bindings to comprehensive list Add fallback escape sequence of cursor hide/show https://github.com/ruby/reline/commit/e3c73bbe26 --- lib/reline/io/ansi.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/reline/io/ansi.rb b/lib/reline/io/ansi.rb index 2b5a5c5786..30a89bc471 100644 --- a/lib/reline/io/ansi.rb +++ b/lib/reline/io/ansi.rb @@ -114,10 +114,14 @@ class Reline::ANSI < Reline::IO def set_default_key_bindings_comprehensive_list(config) { + # xterm + [27, 91, 51, 126] => :key_delete, # kdch1 + [27, 91, 53, 126] => :ed_search_prev_history, # kpp + [27, 91, 54, 126] => :ed_search_next_history, # knp + # Console (80x25) [27, 91, 49, 126] => :ed_move_to_beg, # Home [27, 91, 52, 126] => :ed_move_to_end, # End - [27, 91, 51, 126] => :key_delete, # Del # KDE # Del is 0x08 @@ -301,27 +305,27 @@ class Reline::ANSI < Reline::IO end def hide_cursor + seq = "\e[?25l" if Reline::Terminfo.enabled? && Reline::Terminfo.term_supported? begin - @output.write Reline::Terminfo.tigetstr('civis') + seq = Reline::Terminfo.tigetstr('civis') rescue Reline::Terminfo::TerminfoError # civis is undefined end - else - # ignored end + @output.write seq end def show_cursor + seq = "\e[?25h" if Reline::Terminfo.enabled? && Reline::Terminfo.term_supported? begin - @output.write Reline::Terminfo.tigetstr('cnorm') + seq = Reline::Terminfo.tigetstr('cnorm') rescue Reline::Terminfo::TerminfoError # cnorm is undefined end - else - # ignored end + @output.write seq end def erase_after_cursor