Skip to content

Commit

Permalink
Add more fallbacks when terminfo is not available (#722)
Browse files Browse the repository at this point in the history
Add xterm key bindings to comprehensive list
Add fallback escape sequence of cursor hide/show
  • Loading branch information
tompng authored Jun 10, 2024
1 parent 9da2cbc commit e3c73bb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/reline/io/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e3c73bb

Please sign in to comment.