Skip to content

Commit

Permalink
If terminfo could not be found, set Reline::Terminfo.enabled == false
Browse files Browse the repository at this point in the history
Fix ruby#447 ruby#543

This problem occurs when Fiddle can be loaded, curses can be loaded, and TERM is not registered in Terminfo.
It should also occur at hardcopy terminals and when Terminfo information is low, but no such reports have been received.

Reline should not abort the process because of missing Terminfo.
Reline proceeds with `Reline::Terminfo.enabled == false` when fiddle or curses cannot be loaded.
https://github.com/ruby/reline/blob/ebab2875f1226f877376558d8758bc0e2a1776c7/lib/reline/terminfo.rb#L156-L160

And does the same when Terminfo is present but TERM is not.

You can check the operation with `TERM=foo bundle exec bin/console`.
  • Loading branch information
ima1zumi committed Apr 5, 2024
1 parent 1d65696 commit 579727b
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 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
@enabled = 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
@enabled = false
end
end

Expand Down Expand Up @@ -149,7 +137,7 @@ def self.tigetnum(capname)
end

def self.enabled?
true
@enabled
end
end if Reline::Terminfo.curses_dl

Expand Down

0 comments on commit 579727b

Please sign in to comment.