Module: Reline::Terminfo
- Extended by:
- Fiddle::Importer
- Defined in:
- lib/reline/terminfo.rb,
lib/reline/terminfo.rb,
lib/reline/terminfo.rb
Defined Under Namespace
Classes: StringWithTiparm, TerminfoError
Class Method Summary
collapse
Class Method Details
.curses_dl ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/reline/terminfo.rb', line 32
def self.curses_dl
return @curses_dl unless @curses_dl == false
if Fiddle.const_defined?(:TYPE_VARIADIC)
curses_dl_files.each do |curses_name|
result = Fiddle::Handle.new(curses_name)
rescue Fiddle::DLError
next
else
@curses_dl = result
break
end
end
@curses_dl = nil if @curses_dl == false
@curses_dl
end
|
.curses_dl_files ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/reline/terminfo.rb', line 17
def self.curses_dl_files
case RUBY_PLATFORM
when /mingw/, /mswin/
[]
when /cygwin/
%w[cygncursesw-10.dll cygncurses-10.dll]
when /darwin/
%w[libncursesw.dylib libcursesw.dylib libncurses.dylib libcurses.dylib]
else
%w[libncursesw.so libcursesw.so libncurses.so libcurses.so]
end
end
|
.enabled? ⇒ Boolean
151
152
153
|
# File 'lib/reline/terminfo.rb', line 151
def self.enabled?
true
end
|
.setupterm(term, fildes) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/reline/terminfo.rb', line 80
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 0
when -1 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 -1
end
else -2
end
end
|
.tigetflag(capname) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/reline/terminfo.rb', line 127
def self.tigetflag(capname)
raise TerminfoError, "capname is not String: #{capname.inspect}" unless capname.is_a?(String)
flag = @tigetflag.(capname).to_i
case flag
when -1
raise TerminfoError, "not boolean capability: #{capname}"
when 0
raise TerminfoError, "can't find capability: #{capname}"
end
flag
end
|
.tigetnum(capname) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/reline/terminfo.rb', line 139
def self.tigetnum(capname)
raise TerminfoError, "capname is not String: #{capname.inspect}" unless capname.is_a?(String)
num = @tigetnum.(capname).to_i
case num
when -2
raise TerminfoError, "not numeric capability: #{capname}"
when -1
raise TerminfoError, "can't find capability: #{capname}"
end
num
end
|
.tigetstr(capname) ⇒ Object
109
110
111
112
113
114
115
116
117
|
# File 'lib/reline/terminfo.rb', line 109
def self.tigetstr(capname)
raise TerminfoError, "capname is not String: #{capname.inspect}" unless capname.is_a?(String)
capability = @tigetstr.(capname)
case capability.to_i
when 0, -1
raise TerminfoError, "can't find capability: #{capname}"
end
StringWithTiparm.new(capability.to_s)
end
|
.tiparm(str, *args) ⇒ Object
119
120
121
122
123
124
125
|
# File 'lib/reline/terminfo.rb', line 119
def self.tiparm(str, *args)
new_args = []
args.each do |a|
new_args << Fiddle::TYPE_INT << a
end
@tiparm.(str, *new_args).to_s
end
|