Class: RubyText::Window
- Inherits:
-
Object
- Object
- RubyText::Window
- Defined in:
- lib/rubytext.rb,
lib/rubytext.rb
Instance Attribute Summary collapse
-
#bg ⇒ Object
readonly
Returns the value of attribute bg.
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#fg ⇒ Object
readonly
Returns the value of attribute fg.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#win ⇒ Object
readonly
Returns the value of attribute win.
Class Method Summary collapse
- .colors(win, fg, bg) ⇒ Object
- .main(fg: nil, bg: nil) ⇒ Object
- .make(cwin, high, wide, r0, c0, border) ⇒ Object
Instance Method Summary collapse
- #[](r, c) ⇒ Object
- #[]=(r, c, char) ⇒ Object
- #boxme ⇒ Object
- #clear ⇒ Object
- #crlf ⇒ Object
- #delegate_output(sym, *args) ⇒ Object
- #down ⇒ Object
- #go(r, c) ⇒ Object
-
#initialize(high = nil, wide = nil, r0 = 1, c0 = 1, border = false, fg = nil, bg = nil) ⇒ Window
constructor
A new instance of Window.
- #output(&block) ⇒ Object
- #p(*args) ⇒ Object
- #print(*args) ⇒ Object
- #puts(*args) ⇒ Object
- #rc ⇒ Object
- #rcprint(r, c, *args) ⇒ Object
- #rcprint!(r, c, *args) ⇒ Object
- #refresh ⇒ Object
Constructor Details
#initialize(high = nil, wide = nil, r0 = 1, c0 = 1, border = false, fg = nil, bg = nil) ⇒ Window
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/rubytext.rb', line 183 def initialize(high=nil, wide=nil, r0=1, c0=1, border=false, fg=nil, bg=nil) debug "RT::Win.init: #{[high, wide, r0, c0, border]}" @wide, @high, @r0, @c0 = wide, high, r0, c0 @border, @fg, @bg = border, fg, bg @win = X::Window.new(high, wide, r0, c0) debug "outer = #{@win.inspect}" debug "@border = #@border" debug "Calling 'colors': #{[@win, fg, bg]}" RubyText::Window.colors(@win, fg, bg) if @border @win.box(Vert, Horiz) @outer = @win @outer.refresh debug "About to call again: params = #{[high-2, wide-2, r0+1, c0+1]}" @win = X::Window.new(high-2, wide-2, r0+1, c0+1) # , false, fg, bg) # relative now?? RubyText::Window.colors(@win, fg, bg) else @outer = @win end @rows, @cols = @win.maxy, @win.maxx # unnecessary really... @width, @height = @cols + 2, @rows + 2 if @border @win.refresh end |
Instance Attribute Details
#bg ⇒ Object (readonly)
Returns the value of attribute bg.
181 182 183 |
# File 'lib/rubytext.rb', line 181 def bg @bg end |
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
181 182 183 |
# File 'lib/rubytext.rb', line 181 def cols @cols end |
#fg ⇒ Object (readonly)
Returns the value of attribute fg.
181 182 183 |
# File 'lib/rubytext.rb', line 181 def fg @fg end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
181 182 183 |
# File 'lib/rubytext.rb', line 181 def height @height end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
181 182 183 |
# File 'lib/rubytext.rb', line 181 def rows @rows end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
181 182 183 |
# File 'lib/rubytext.rb', line 181 def width @width end |
#win ⇒ Object (readonly)
Returns the value of attribute win.
181 182 183 |
# File 'lib/rubytext.rb', line 181 def win @win end |
Class Method Details
.colors(win, fg, bg) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/rubytext.rb', line 62 def self.colors(win, fg, bg) cfg, cbg, cp = fb2cp(fg, bg) X.init_pair(cp, cfg, cbg) win.color_set(cp|X::A_NORMAL) num = win.maxx * win.maxy win.addstr(' '*num) win.setpos(0, 0) win.refresh end |
.main(fg: nil, bg: nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rubytext.rb', line 72 def self.main(fg: nil, bg: nil) debug "Entering Window.main (#{fg}, #{bg}) => " @main_win = X.init_screen X.start_color colors(@main_win, fg, bg) debug "About to call .make" rows, cols = @main_win.maxy, @main_win.maxx @screen = self.make(@main_win, rows, cols, 0, 0, false) @screen end |
.make(cwin, high, wide, r0, c0, border) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rubytext.rb', line 83 def self.make(cwin, high, wide, r0, c0, border) debug "make: #{[cwin, high, wide, r0, c0, border]}" obj = self.allocate debug "Allocate returned a #{obj.class}" obj.instance_eval do debug " Inside instance_eval..." @outer = @win = cwin @wide, @high, @r0, @c0 = wide, high, r0, c0 @border = border @rows, @cols = high, wide @width, @height = @cols + 2, @rows + 2 if @border end obj end |
Instance Method Details
#[](r, c) ⇒ Object
285 286 287 288 289 290 291 292 |
# File 'lib/rubytext.rb', line 285 def [](r, c) save = self.rc @win.setpos r, c ch = @win.inch @win.setpos *save ch # go(r, c) { ch = @win.inch } end |
#[]=(r, c, char) ⇒ Object
294 295 296 297 |
# File 'lib/rubytext.rb', line 294 def []=(r, c, char) @win.setpos(r, c) @win.addstr(char[0]) end |
#boxme ⇒ Object
299 300 301 302 |
# File 'lib/rubytext.rb', line 299 def boxme @outer.box(Vert, Horiz) @outer.refresh end |
#clear ⇒ Object
270 271 272 273 274 275 276 277 |
# File 'lib/rubytext.rb', line 270 def clear win = @win num = win.maxx * win.maxy win.setpos(0, 0) win.addstr(' '*num) win.setpos(0, 0) win.refresh end |
#crlf ⇒ Object
261 262 263 264 |
# File 'lib/rubytext.rb', line 261 def crlf r, c = rc go r+1, 0 end |
#delegate_output(sym, *args) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/rubytext.rb', line 207 def delegate_output(sym, *args) args = [""] if args.empty? # debug "#{sym}: args = #{args.inspect}" if sym == :p args.map!(&:inspect) else args.map!(&:to_s) end str = sprintf(*args) flag = true if sym != :print && str[-1] != "\n" # color-handling code here str.each_char do |ch| ch == "\n" ? crlf : @win.addch(ch) end # @win.addstr(str) crlf if flag @win.refresh end |
#down ⇒ Object
256 257 258 259 |
# File 'lib/rubytext.rb', line 256 def down r, c = rc go r+1, c end |
#go(r, c) ⇒ Object
247 248 249 250 251 252 253 254 |
# File 'lib/rubytext.rb', line 247 def go(r, c) save = self.rc @win.setpos(r, c) if block_given? yield go(*save) # No block here! end end |
#output(&block) ⇒ Object
279 280 281 282 283 |
# File 'lib/rubytext.rb', line 279 def output(&block) $stdscr = self block.call $stdscr = STDSCR end |
#p(*args) ⇒ Object
234 235 236 |
# File 'lib/rubytext.rb', line 234 def p(*args) delegate_output(:p, *args) end |
#print(*args) ⇒ Object
230 231 232 |
# File 'lib/rubytext.rb', line 230 def print(*args) delegate_output(:print, *args) end |
#puts(*args) ⇒ Object
226 227 228 |
# File 'lib/rubytext.rb', line 226 def puts(*args) delegate_output(:puts, *args) end |
#rc ⇒ Object
266 267 268 |
# File 'lib/rubytext.rb', line 266 def rc [@win.cury, @win.curx] end |
#rcprint(r, c, *args) ⇒ Object
238 239 240 |
# File 'lib/rubytext.rb', line 238 def rcprint(r, c, *args) self.go(r, c) { self.print *args } end |
#rcprint!(r, c, *args) ⇒ Object
242 243 244 245 |
# File 'lib/rubytext.rb', line 242 def rcprint!(r, c, *args) @win.setpos(r, c) # Cursor isn't restored self.print *args end |
#refresh ⇒ Object
304 305 306 |
# File 'lib/rubytext.rb', line 304 def refresh @win.refresh end |