Class: RST::CursesController

Inherits:
Object
  • Object
show all
Includes:
Curses
Defined in:
lib/curses/curses_controller.rb

Overview

Controll the curses-lib

Examples:

cc = CursesController.new
cc.print_scren( ['Line 1', 'Line 2', ...] )
cc.clear
cc.status 'It works'

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

Constructor Details

#initializeCursesController

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

#clearObject

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

#noopObject

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

Outputs array of lines from 0,0 to max-lines

Parameters:

  • lines (Array)
    • lines to output



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

Parameters:



44
45
46
47
# File 'lib/curses/curses_controller.rb', line 44

def status(message)
  message += '-' * (status_line_length - message.length)
  write(status_line, 0, message, 1 )
end