Class: CursesRenderer
- Inherits:
-
Object
- Object
- CursesRenderer
- Defined in:
- lib/delve/display/curses_renderer.rb
Constant Summary collapse
- @@colors =
{ :black => Curses::COLOR_BLACK, :red => Curses::COLOR_RED, :blue => Curses::COLOR_BLUE, :white => Curses::COLOR_WHITE, :cyan => Curses::COLOR_CYAN, :green => Curses::COLOR_GREEN, :magenta => Curses::COLOR_MAGENTA, :yellow => Curses::COLOR_YELLOW }
Instance Method Summary collapse
- #draw(x, y, char, fg, bg) ⇒ Object
- #exit ⇒ Object
- #height ⇒ Object
- #init ⇒ Object
- #render(data) ⇒ Object
- #width ⇒ Object
Instance Method Details
#draw(x, y, char, fg, bg) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/delve/display/curses_renderer.rb', line 38 def draw(x, y, char, fg, bg) pair = "#{fg.to_s},#{bg.to_s}" if !@pairs.include? pair @pairs.push pair Curses.init_pair(@pairs.index(pair)+1, @@colors[fg], @@colors[bg]) end # Seem to need to flip x and y index = @pairs.index(pair)+1 Curses.setpos(y, x) Curses.attron(Curses.color_pair(index)) do begin Curses.addstr(char) rescue TypeError => e raise 'The char was ' + char.to_s end end end |
#exit ⇒ Object
25 26 27 |
# File 'lib/delve/display/curses_renderer.rb', line 25 def exit Curses.close_screen end |
#height ⇒ Object
60 61 62 |
# File 'lib/delve/display/curses_renderer.rb', line 60 def height Curses.lines end |
#init ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/delve/display/curses_renderer.rb', line 16 def init Curses.init_screen Curses.start_color Curses.nl Curses.noecho Curses.curs_set 0 @pairs = Array.new end |
#render(data) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/delve/display/curses_renderer.rb', line 29 def render(data) Curses.clear data.keys.each do |key| draw_data = data[key] draw(draw_data[:x], draw_data[:y], draw_data[:char], draw_data[:foreground], draw_data[:background]) end Curses.refresh end |
#width ⇒ Object
56 57 58 |
# File 'lib/delve/display/curses_renderer.rb', line 56 def width Curses.cols end |