Class: RST::CursesController
- Inherits:
-
Object
- Object
- RST::CursesController
- Includes:
- Curses
- Defined in:
- lib/curses/curses_controller.rb
Overview
Controll the curses-lib
Constant Summary collapse
- COLORS =
Available colors provided by Curses
[ COLOR_BLACK,COLOR_RED,COLOR_GREEN,COLOR_YELLOW,COLOR_BLUE, COLOR_MAGENTA,COLOR_CYAN,COLOR_WHITE ]
public api collapse
-
#clear ⇒ Object
Clear the screen and rewrite the status-bar.
-
#initialize ⇒ CursesController
constructor
Initialize and register a finalizer to close curses whenever this object gets destroyed by the GC.
-
#noop ⇒ Object
No operation - called when an unknown key is pressed to show any response.
-
#print_screen(lines) ⇒ Object
Outputs array of lines from 0,0 to max-lines.
-
#status(message) ⇒ Object
update the status-line.
Constructor Details
#initialize ⇒ CursesController
Initialize and register a finalizer to close curses whenever this object gets destroyed by the GC.
24 25 26 27 28 |
# File 'lib/curses/curses_controller.rb', line 24 def initialize(*) init_curses ObjectSpace.define_finalizer( self, self.class.finalize ) clear end |
Instance Method Details
#clear ⇒ Object
Clear the screen and rewrite the status-bar
56 57 58 59 |
# File 'lib/curses/curses_controller.rb', line 56 def clear Curses.clear status "q=Quit c=Calendar <enter>=Clear screen" end |
#noop ⇒ Object
No operation - called when an unknown key is pressed to show any response
51 52 53 |
# File 'lib/curses/curses_controller.rb', line 51 def noop write(0,0,"NOOP #{Time.now.to_s}"+" "*5) end |
#print_screen(lines) ⇒ Object
Outputs array of lines from 0,0 to max-lines
32 33 34 35 36 37 38 39 |
# File 'lib/curses/curses_controller.rb', line 32 def print_screen(lines) color_pair = 1 lines.each_with_index do |line,lno| color_pair = color_pair == 1 ? 2 : 1 write(lno, 0, block_given? ? yield(line,lno) : line, color_pair) break if lno > height-3 end end |
#status(message) ⇒ Object
update the status-line
44 45 46 47 |
# File 'lib/curses/curses_controller.rb', line 44 def status() += '-' * (status_line_length - .length) write(status_line, 0, , 1 ) end |