Class: IGMarkets::CLI::CursesWindow
- Inherits:
-
Object
- Object
- IGMarkets::CLI::CursesWindow
- Defined in:
- lib/ig_markets/cli/curses_window.rb
Overview
This helper class supports the display of text in a fullscreen curses window.
Class Method Summary collapse
-
.available? ⇒ Boolean
Returns whether curses support is available.
- .prepare ⇒ Object
Instance Method Summary collapse
-
#clear ⇒ Object
Clears the contents of this curses window and resets the cursor to the top left.
-
#initialize ⇒ CursesWindow
constructor
Initializes this fullscreen curses window.
-
#print_lines(*lines) ⇒ Object
Prints the specified lines in this fullscreen curses window.
-
#refresh ⇒ Object
Refreshes this curses window so its content is updated on the screen.
Constructor Details
#initialize ⇒ CursesWindow
Initializes this fullscreen curses window.
8 9 10 11 12 13 |
# File 'lib/ig_markets/cli/curses_window.rb', line 8 def initialize self.class.prepare @window = Curses::Window.new 0, 0, 0, 0 @position = [0, 0] end |
Class Method Details
.available? ⇒ Boolean
Returns whether curses support is available. On Windows the ‘curses’ gem is optional and so this class may not be usable.
45 46 47 48 49 50 |
# File 'lib/ig_markets/cli/curses_window.rb', line 45 def available? require 'curses' true rescue LoadError false end |
.prepare ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ig_markets/cli/curses_window.rb', line 52 def prepare raise IGMarketsError, 'curses gem is not installed' unless available? return if @prepared Curses.noecho Curses.nonl Curses.stdscr.nodelay = 1 Curses.init_screen Curses.start_color 8.times { |color| Curses.init_pair (30 + color), color, 0 } @prepared = true end |
Instance Method Details
#clear ⇒ Object
Clears the contents of this curses window and resets the cursor to the top left.
16 17 18 19 |
# File 'lib/ig_markets/cli/curses_window.rb', line 16 def clear @window.clear @position = [0, 0] end |
#print_lines(*lines) ⇒ Object
Prints the specified lines in this fullscreen curses window.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ig_markets/cli/curses_window.rb', line 29 def print_lines(*lines) change_foreground_color nil lines.flatten.each do |line| print_next_line_segment line until line.empty? @position[0] += 1 @position[1] = 0 end end |
#refresh ⇒ Object
Refreshes this curses window so its content is updated on the screen.
22 23 24 |
# File 'lib/ig_markets/cli/curses_window.rb', line 22 def refresh @window.refresh end |