Class: HandyToolbox::Screen
- Inherits:
-
Object
- Object
- HandyToolbox::Screen
- Defined in:
- lib/handy_toolbox/screen.rb
Constant Summary collapse
- SPACE =
' '.freeze
Instance Attribute Summary collapse
-
#scroll ⇒ Object
readonly
Returns the value of attribute scroll.
Instance Method Summary collapse
- #clear ⇒ Object
- #close ⇒ Object
- #draw ⇒ Object
- #header(title) ⇒ Object
- #init ⇒ Object
-
#initialize(default_colors: false) ⇒ Screen
constructor
A new instance of Screen.
- #text_at(x, y, str) ⇒ Object
Constructor Details
#initialize(default_colors: false) ⇒ Screen
Returns a new instance of Screen.
10 11 12 |
# File 'lib/handy_toolbox/screen.rb', line 10 def initialize(default_colors: false) @default_colors = default_colors end |
Instance Attribute Details
#scroll ⇒ Object (readonly)
Returns the value of attribute scroll.
8 9 10 |
# File 'lib/handy_toolbox/screen.rb', line 8 def scroll @scroll end |
Instance Method Details
#clear ⇒ Object
27 28 29 30 |
# File 'lib/handy_toolbox/screen.rb', line 27 def clear scroll.reset Curses.clear end |
#close ⇒ Object
58 59 60 |
# File 'lib/handy_toolbox/screen.rb', line 58 def close Curses.close_screen end |
#draw ⇒ Object
32 33 34 35 36 37 |
# File 'lib/handy_toolbox/screen.rb', line 32 def draw @max_y = 0 yield @scroll.update(@max_y) Curses.refresh end |
#header(title) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/handy_toolbox/screen.rb', line 39 def header(title) title = " #{title}"[0, Curses.cols - 1] title = title.ljust(Curses.cols, SPACE) Ui.reverse do if scroll.fits_into_pane?(-scroll.top) Ui.text_at(0, -scroll.top, title) end end end |
#init ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/handy_toolbox/screen.rb', line 14 def init Curses.init_screen Curses.start_color Curses.use_default_colors if @default_colors Ui.hide_cursor Curses.cbreak Curses.crmode Curses.noecho Curses.nonl Curses.stdscr.keypad(true) @scroll = Scroll.new end |