Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue processing even if terminfo database couldn't be found #673

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/reline/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def self.move_cursor_down(x)
end

def self.hide_cursor
if Reline::Terminfo.enabled?
if Reline::Terminfo.enabled? && Reline::Terminfo.term_supported?
begin
@@output.write Reline::Terminfo.tigetstr('civis')
rescue Reline::Terminfo::TerminfoError
Expand All @@ -327,7 +327,7 @@ def self.hide_cursor
end

def self.show_cursor
if Reline::Terminfo.enabled?
if Reline::Terminfo.enabled? && Reline::Terminfo.term_supported?
begin
@@output.write Reline::Terminfo.tigetstr('cnorm')
rescue Reline::Terminfo::TerminfoError
Expand Down
21 changes: 7 additions & 14 deletions lib/reline/terminfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,11 @@ module Reline::Terminfo
def self.setupterm(term, fildes)
errret_int = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
ret = @setupterm.(term, fildes, errret_int)
errret = errret_int[0, Fiddle::SIZEOF_INT].unpack1('i')
case ret
when 0 # OK
0
@term_supported = true
when -1 # ERR
case errret
when 1
raise TerminfoError.new('The terminal is hardcopy, cannot be used for curses applications.')
when 0
raise TerminfoError.new('The terminal could not be found, or that it is a generic type, having too little information for curses applications to run.')
when -1
raise TerminfoError.new('The terminfo database could not be found.')
else # unknown
-1
end
else # unknown
-2
@term_supported = false
end
end

Expand Down Expand Up @@ -148,9 +136,14 @@ def self.tigetnum(capname)
num
end

# NOTE: This means Fiddle and curses are enabled.
def self.enabled?
true
end

def self.term_supported?
@term_supported
end
end if Reline::Terminfo.curses_dl

module Reline::Terminfo
Expand Down
2 changes: 1 addition & 1 deletion test/reline/test_ansi_with_terminfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ def test_more_emacs
assert_key_binding("\e ", :em_set_mark, [:emacs])
assert_key_binding("\C-x\C-x", :em_exchange_mark, [:emacs])
end
end if Reline::Terminfo.enabled?
end if Reline::Terminfo.enabled? && Reline::Terminfo.term_supported?
2 changes: 1 addition & 1 deletion test/reline/test_terminfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ def test_tigetnum_with_error
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetnum('unknown') }
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetnum(nil) }
end
end if Reline::Terminfo.enabled?
end if Reline::Terminfo.enabled? && Reline::Terminfo.term_supported?
Loading