Class: Hobostove::Panel
- Inherits:
-
Struct
- Object
- Struct
- Hobostove::Panel
- Defined in:
- lib/hobostove/panel.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#options ⇒ Object
Returns the value of attribute options.
-
#startx ⇒ Object
Returns the value of attribute startx.
-
#starty ⇒ Object
Returns the value of attribute starty.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #<<(string, do_update = true) ⇒ Object
-
#initialize(*args) ⇒ Panel
constructor
A new instance of Panel.
- #refresh ⇒ Object
- #refresh! ⇒ Object
- #scroll_down ⇒ Object
- #scroll_up ⇒ Object
- #wrap_lines? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Panel
Returns a new instance of Panel.
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/hobostove/panel.rb', line 3 def initialize(*args) super @win = Curses::Window.new(height, width, starty, startx) @win.box(0, 0) Curses.refresh @win.refresh @strings = [] @scroll = 0 end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height
2 3 4 |
# File 'lib/hobostove/panel.rb', line 2 def height @height end |
#options ⇒ Object
Returns the value of attribute options
2 3 4 |
# File 'lib/hobostove/panel.rb', line 2 def @options end |
#startx ⇒ Object
Returns the value of attribute startx
2 3 4 |
# File 'lib/hobostove/panel.rb', line 2 def startx @startx end |
#starty ⇒ Object
Returns the value of attribute starty
2 3 4 |
# File 'lib/hobostove/panel.rb', line 2 def starty @starty end |
#width ⇒ Object
Returns the value of attribute width
2 3 4 |
# File 'lib/hobostove/panel.rb', line 2 def width @width end |
Instance Method Details
#<<(string, do_update = true) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/hobostove/panel.rb', line 24 def <<(string, do_update = true) if wrap_lines? @strings << Line(string.first(width - 4)) else @strings << Line(string) end refresh if do_update end |
#refresh ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hobostove/panel.rb', line 52 def refresh @win.clear @win.box(0, 0) printable_lines.each_with_index do |line, i| @win.setpos(i + 1, 2) line.segments.each do |segment| color = case segment.color when :cyan Curses::COLOR_CYAN else Curses::COLOR_WHITE end @win.attron(Curses.color_pair(color) | Curses::A_NORMAL) do @win.addstr(segment.body) end end end refresh! end |
#refresh! ⇒ Object
48 49 50 |
# File 'lib/hobostove/panel.rb', line 48 def refresh! @win.refresh end |
#scroll_down ⇒ Object
41 42 43 44 45 46 |
# File 'lib/hobostove/panel.rb', line 41 def scroll_down if @scroll > 0 @scroll -= 1 end refresh end |
#scroll_up ⇒ Object
34 35 36 37 38 39 |
# File 'lib/hobostove/panel.rb', line 34 def scroll_up if @strings.size > printable_area + @scroll @scroll += 1 end refresh end |
#wrap_lines? ⇒ Boolean
20 21 22 |
# File 'lib/hobostove/panel.rb', line 20 def wrap_lines? ![:nowrap] end |