From f2aeedb6b8b3d9d60bd07608f08c62cf1e963826 Mon Sep 17 00:00:00 2001 From: tompng Date: Mon, 10 Jun 2024 22:55:29 +0900 Subject: [PATCH] Add more fallbacks when terminfo is not available Add xterm key bindings to comprehensive list Add fallback escape sequence of cursor hide/show --- 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 @@ def set_default_key_bindings_terminfo(config) 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 @@ def move_cursor_down(x) 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