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 << string.first(width - 4) else @strings << string end refresh if do_update end |
#refresh ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/hobostove/panel.rb', line 52 def refresh @win.clear @win.box(0, 0) @strings.last(printable_area + @scroll).first(printable_area).each_with_index do |string, i| @win.setpos(i + 1, 2) @win.addstr(string) 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 |