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
- .clear(win) ⇒ Object
- .colors(win, fg, bg) ⇒ Object
- .colors!(win, fg, bg) ⇒ Object
- .main(fg: nil, bg: nil) ⇒ Object
- .make(cwin, high, wide, r0, c0, border, fg: :white, bg: :black) ⇒ Object
Instance Method Summary collapse
- #[](r, c) ⇒ Object
- #[]=(r, c, char) ⇒ Object
- #boxme ⇒ Object
- #center(row, str) ⇒ 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
Returns a new instance of Window.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/rubytext.rb', line 170 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) # self.clear(@main_win) 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.
57 58 59 |
# File 'lib/rubytext.rb', line 57 def bg @bg end |
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
168 169 170 |
# File 'lib/rubytext.rb', line 168 def cols @cols end |
#fg ⇒ Object (readonly)
Returns the value of attribute fg.
57 58 59 |
# File 'lib/rubytext.rb', line 57 def fg @fg end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
168 169 170 |
# File 'lib/rubytext.rb', line 168 def height @height end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
168 169 170 |
# File 'lib/rubytext.rb', line 168 def rows @rows end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
168 169 170 |
# File 'lib/rubytext.rb', line 168 def width @width end |
#win ⇒ Object (readonly)
Returns the value of attribute win.
168 169 170 |
# File 'lib/rubytext.rb', line 168 def win @win end |
Class Method Details
.clear(win) ⇒ Object
265 266 267 268 269 270 271 |
# File 'lib/rubytext.rb', line 265 def self.clear(win) num = win.maxx * win.maxy win.setpos(0, 0) win.addstr(' '*num) win.setpos(0, 0) win.refresh end |
.colors(win, fg, bg) ⇒ Object
59 60 61 62 63 |
# File 'lib/rubytext.rb', line 59 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) end |
.colors!(win, fg, bg) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/rubytext.rb', line 65 def self.colors!(win, fg, bg) colors(win, fg, bg) num = win.maxx * win.maxy win.setpos(0, 0) win.addstr(' '*num) win.setpos(0, 0) win.refresh end |
.main(fg: nil, bg: nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rubytext.rb', line 74 def self.main(fg: nil, bg: nil) @main_win = X.init_screen debug(@main_win.inspect) X.start_color colors!(@main_win, fg, bg) rows, cols = @main_win.maxy, @main_win.maxx @screen = self.make(@main_win, rows, cols, 0, 0, false, fg: fg, bg: bg) # FIXME Why is this hard to inline? # @win = @main_win # obj = self.allocate # obj.instance_eval do # @outer = @win = @main_win # @wide, @high, @r0, @c0 = cols, rows, 0, 0 # @fg, @bg = fg, bg # @border = false # @rows, @cols = @high, @wide # @width, @height = @cols + 2, @rows + 2 if @border # end # @win = @main_win # FIXME? # obj @screen end |
.make(cwin, high, wide, r0, c0, border, fg: :white, bg: :black) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rubytext.rb', line 98 def self.make(cwin, high, wide, r0, c0, border, fg: :white, bg: :black) obj = self.allocate obj.instance_eval do debug " Inside instance_eval..." @outer = @win = cwin @wide, @high, @r0, @c0 = wide, high, r0, c0 @fg, @bg = fg, bg @border = border @rows, @cols = high, wide @width, @height = @cols + 2, @rows + 2 if @border end obj end |
Instance Method Details
#[](r, c) ⇒ Object
288 289 290 291 292 293 294 295 |
# File 'lib/rubytext.rb', line 288 def [](r, c) save = self.rc @win.setpos r, c ch = @win.inch @win.setpos *save ch.chr # go(r, c) { ch = @win.inch } end |
#[]=(r, c, char) ⇒ Object
297 298 299 300 301 |
# File 'lib/rubytext.rb', line 297 def []=(r, c, char) @win.setpos(r, c) @win.addstr(char[0]) @win.refresh end |
#boxme ⇒ Object
303 304 305 306 |
# File 'lib/rubytext.rb', line 303 def boxme @outer.box(Vert, Horiz) @outer.refresh end |
#center(row, str) ⇒ Object
195 196 197 198 |
# File 'lib/rubytext.rb', line 195 def center(row, str) n = @win.maxx - str.length rcprint row, n/2, str end |
#clear ⇒ Object
273 274 275 276 277 278 279 280 |
# File 'lib/rubytext.rb', line 273 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
256 257 258 259 |
# File 'lib/rubytext.rb', line 256 def crlf r, c = rc go r+1, 0 end |
#delegate_output(sym, *args) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/rubytext.rb', line 200 def delegate_output(sym, *args) args = [""] if args.empty? debug "delegate: colors are #@fg, #@bg" RubyText::Window.colors(@win, @fg, @bg) # FIXME? # 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
251 252 253 254 |
# File 'lib/rubytext.rb', line 251 def down r, c = rc go r+1, c end |
#go(r, c) ⇒ Object
242 243 244 245 246 247 248 249 |
# File 'lib/rubytext.rb', line 242 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
282 283 284 285 286 |
# File 'lib/rubytext.rb', line 282 def output(&block) $stdscr = self block.call $stdscr = STDSCR end |
#p(*args) ⇒ Object
229 230 231 |
# File 'lib/rubytext.rb', line 229 def p(*args) delegate_output(:p, *args) end |
#print(*args) ⇒ Object
225 226 227 |
# File 'lib/rubytext.rb', line 225 def print(*args) delegate_output(:print, *args) end |
#puts(*args) ⇒ Object
221 222 223 |
# File 'lib/rubytext.rb', line 221 def puts(*args) delegate_output(:puts, *args) end |
#rc ⇒ Object
261 262 263 |
# File 'lib/rubytext.rb', line 261 def rc [@win.cury, @win.curx] end |
#rcprint(r, c, *args) ⇒ Object
233 234 235 |
# File 'lib/rubytext.rb', line 233 def rcprint(r, c, *args) self.go(r, c) { self.print *args } end |
#rcprint!(r, c, *args) ⇒ Object
237 238 239 240 |
# File 'lib/rubytext.rb', line 237 def rcprint!(r, c, *args) @win.setpos(r, c) # Cursor isn't restored self.print *args end |
#refresh ⇒ Object
308 309 310 |
# File 'lib/rubytext.rb', line 308 def refresh @win.refresh end |