Module: Lab
- Defined in:
- lib/lab.rb
Defined Under Namespace
Classes: Attr
Instance Attribute Summary collapse
-
#attr_buffer ⇒ Object
Returns the value of attribute attr_buffer.
-
#buffer ⇒ Object
Returns the value of attribute buffer.
Instance Method Summary collapse
- #addstr(str) ⇒ Object
- #attr_buffer_line(w) ⇒ Object
-
#clear ⇒ Object
see caller - unneeded, as its a hack anyway.
- #extend_attr_buffer(w, h) ⇒ Object
- #extend_buffer(x, y, str) ⇒ Object
- #init_buffer_abstraction ⇒ Object
- #maxx ⇒ Object
- #maxy ⇒ Object
- #set_attr(boldness, fg_color, bg_color) ⇒ Object
-
#setpos(y, x) ⇒ Object
swapped in curses interface.
Instance Attribute Details
#attr_buffer ⇒ Object
Returns the value of attribute attr_buffer.
33 34 35 |
# File 'lib/lab.rb', line 33 def attr_buffer @attr_buffer end |
#buffer ⇒ Object
Returns the value of attribute buffer.
33 34 35 |
# File 'lib/lab.rb', line 33 def buffer @buffer end |
Instance Method Details
#addstr(str) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/lab.rb', line 102 def addstr str return if $lab_disabled extend_buffer @x, @y, str extend_attr_buffer @x + 1, @y + 1 if @x == @buffer[@y].length @buffer[@y] << str else line = @buffer[@y] line[@x, str.length] = str end # todo - fill in attr_buffer with nil's for runs of colour? @twt.invalidate_scan @y, @x, (@x + str.length) @attr_buffer[@y][@x] = @attr (@x+1).upto(@x + str.length) { |x| @attr_buffer[@y][x] = nil } if str.length > 1 @x += str.length end |
#attr_buffer_line(w) ⇒ Object
69 70 71 72 73 |
# File 'lib/lab.rb', line 69 def attr_buffer_line w tmp = [] w.times { tmp << Attr.new } tmp end |
#clear ⇒ Object
see caller - unneeded, as its a hack anyway
40 41 42 43 44 45 |
# File 'lib/lab.rb', line 40 def clear return if $lab_disabled @buffer = [""] @attr_buffer = [] @twt.invalidate_all end |
#extend_attr_buffer(w, h) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/lab.rb', line 75 def extend_attr_buffer w, h if !@attr_buffer.empty? and (@attr_buffer[0].length < w) 0.upto(@attr_buffer.length) { |idx| tmp = attr_buffer_line(w - (@attr_buffer[idx].length rescue 0)) @attr_buffer[idx] = [] if @attr_buffer[idx].nil? @attr_buffer[idx] += tmp } end if @attr_buffer.length < h (h - @attr_buffer.length).times { @attr_buffer << attr_buffer_line(w) } end end |
#extend_buffer(x, y, str) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/lab.rb', line 91 def extend_buffer x, y, str if @buffer.length <= y (y - @buffer.length + 1).times { @buffer << "" } end if @buffer[y].length <= (str.length + x) @buffer[y] << " " * ((str.length + x) - @buffer[y].length) end end |
#init_buffer_abstraction ⇒ Object
35 36 37 |
# File 'lib/lab.rb', line 35 def init_buffer_abstraction clear end |
#maxx ⇒ Object
47 |
# File 'lib/lab.rb', line 47 def maxx; @twt.maxx; end |
#maxy ⇒ Object
49 |
# File 'lib/lab.rb', line 49 def maxy; @twt.maxy; end |
#set_attr(boldness, fg_color, bg_color) ⇒ Object
56 57 58 59 60 |
# File 'lib/lab.rb', line 56 def set_attr boldness, fg_color, bg_color return if $lab_disabled @attr = Attr.new boldness, fg_color, bg_color # puts "#{boldness}, #{fg_color}, #{bg_color}" end |
#setpos(y, x) ⇒ Object
swapped in curses interface
51 52 53 54 |
# File 'lib/lab.rb', line 51 def setpos y, x # swapped in curses interface @twt.x, @twt.y = x, y @x, @y = x, y end |