Module: RubyText
- Defined in:
- lib/version.rb,
lib/rubytext.rb,
lib/rubytext.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.0.38"- Path =
File.(File.join(File.dirname(__FILE__)))
- Colors =
[:black, :blue, :cyan, :green, :magenta, :red, :white, :yellow]
Class Method Summary collapse
- .hide_cursor ⇒ Object
- .menu(r: 0, c: 0, items:) ⇒ Object
-
.method_missing(name, *args) ⇒ Object
For passing through arbitrary method calls to the lower level...
- .restback(high, wide, r, c) ⇒ Object
- .saveback(high, wide, r, c) ⇒ Object
- .set(*args) ⇒ Object
- .show_cursor ⇒ Object
- .show_cursor! ⇒ Object
- .start(*args, log: nil, fg: nil, bg: nil) ⇒ Object
Instance Method Summary collapse
Class Method Details
.hide_cursor ⇒ Object
179 180 181 |
# File 'lib/rubytext.rb', line 179 def self.hide_cursor X.curs_set(0) end |
.menu(r: 0, c: 0, items:) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/rubytext.rb', line 211 def self.(r: 0, c: 0, items:) high = items.size + 2 wide = items.map(&:length).max + 2 saveback(high, wide, r, c) @mywin = RubyText.window(high, wide, r, c, true, fg: :white, bg: :blue) RubyText.set(:raw) X.stdscr.keypad(true) RubyText.hide_cursor sel = 0 max = items.size - 1 loop do items.each.with_index do |item, row| @mywin.go row, 0 color = sel == row ? :yellow : :white @mywin.puts color, " #{item} " end ch = getch case ch when X::KEY_UP sel -= 1 if sel > 0 when X::KEY_DOWN sel += 1 if sel < max when 27 restback(high, wide, r, c) return nil when 10 restback(high, wide, r, c) return sel end end end |
.method_missing(name, *args) ⇒ Object
For passing through arbitrary method calls to the lower level...
166 167 168 169 170 171 172 173 |
# File 'lib/rubytext.rb', line 166 def self.method_missing(name, *args) debug "method_missing: #{name} #{args.inspect}" if name[0] == '_' X.send(name[1..-1], *args) else raise "#{name} #{args.inspect}" # NoMethodError end end |
.restback(high, wide, r, c) ⇒ Object
201 202 203 204 205 206 207 208 209 |
# File 'lib/rubytext.rb', line 201 def self.restback(high, wide, r, c) 0.upto(high) do |h| 0.upto(wide) do |w| STDSCR[h+r, w+c] = @save.shift end end STDSCR.go *@pos STDSCR.refresh end |
.saveback(high, wide, r, c) ⇒ Object
191 192 193 194 195 196 197 198 199 |
# File 'lib/rubytext.rb', line 191 def self.saveback(high, wide, r, c) @pos = STDSCR.rc @save = [] 0.upto(high) do |h| 0.upto(wide) do |w| @save << STDSCR[h+r, w+c] end end end |
.set(*args) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/rubytext.rb', line 122 def self.set(*args) # Allow a block? standard = [:cbreak, :raw, :echo, :keypad] @flags = [] # FIXME can set/reset individually. hmmm args.each do |arg| if standard.include? arg flag = arg.to_s @flags << arg flag.sub!(/_/, "no") X.send(flag) else @flags << arg case arg when :cursor X.show_cursor when :_cursor, :nocursor X.hide_cursor end end end end |
.show_cursor ⇒ Object
183 184 185 |
# File 'lib/rubytext.rb', line 183 def self.show_cursor X.curs_set(1) end |
.show_cursor! ⇒ Object
187 188 189 |
# File 'lib/rubytext.rb', line 187 def self.show_cursor! X.curs_set(2) # Doesn't work? end |
.start(*args, log: nil, fg: nil, bg: nil) ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/rubytext.rb', line 153 def self.start(*args, log: nil, fg: nil, bg: nil) $debug = File.new(log, "w") if log Object.const_set(:STDSCR, RubyText::Window.main(fg: fg, bg: bg)) $stdscr = STDSCR fg, bg, cp = fb2cp(fg, bg) self.set(:_echo, :cbreak, :raw) # defaults # X.stdscr.keypad(true) self.set(*args) # override defaults end |
Instance Method Details
#rest_flags ⇒ Object
149 150 151 |
# File 'lib/rubytext.rb', line 149 def rest_flags @flags = @fstack.pop end |
#save_flags ⇒ Object
144 145 146 147 |
# File 'lib/rubytext.rb', line 144 def save_flags @fstack ||= [] @fstack.push @flags end |