Skip to content

Commit e3c73bb

Browse files
authored
Add more fallbacks when terminfo is not available (#722)
Add xterm key bindings to comprehensive list Add fallback escape sequence of cursor hide/show
1 parent 9da2cbc commit e3c73bb

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/reline/io/ansi.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,14 @@ def set_default_key_bindings_terminfo(config)
114114

115115
def set_default_key_bindings_comprehensive_list(config)
116116
{
117+
# xterm
118+
[27, 91, 51, 126] => :key_delete, # kdch1
119+
[27, 91, 53, 126] => :ed_search_prev_history, # kpp
120+
[27, 91, 54, 126] => :ed_search_next_history, # knp
121+
117122
# Console (80x25)
118123
[27, 91, 49, 126] => :ed_move_to_beg, # Home
119124
[27, 91, 52, 126] => :ed_move_to_end, # End
120-
[27, 91, 51, 126] => :key_delete, # Del
121125

122126
# KDE
123127
# Del is 0x08
@@ -301,27 +305,27 @@ def move_cursor_down(x)
301305
end
302306

303307
def hide_cursor
308+
seq = "\e[?25l"
304309
if Reline::Terminfo.enabled? && Reline::Terminfo.term_supported?
305310
begin
306-
@output.write Reline::Terminfo.tigetstr('civis')
311+
seq = Reline::Terminfo.tigetstr('civis')
307312
rescue Reline::Terminfo::TerminfoError
308313
# civis is undefined
309314
end
310-
else
311-
# ignored
312315
end
316+
@output.write seq
313317
end
314318

315319
def show_cursor
320+
seq = "\e[?25h"
316321
if Reline::Terminfo.enabled? && Reline::Terminfo.term_supported?
317322
begin
318-
@output.write Reline::Terminfo.tigetstr('cnorm')
323+
seq = Reline::Terminfo.tigetstr('cnorm')
319324
rescue Reline::Terminfo::TerminfoError
320325
# cnorm is undefined
321326
end
322-
else
323-
# ignored
324327
end
328+
@output.write seq
325329
end
326330

327331
def erase_after_cursor

0 commit comments

Comments
 (0)