Class: Hutils::CursesVisualizer
- Inherits:
-
Object
- Object
- Hutils::CursesVisualizer
- Defined in:
- lib/hutils/curses_visualizer.rb
Instance Method Summary collapse
-
#initialize(colors:, compact:, highlights:, root:) ⇒ CursesVisualizer
constructor
A new instance of CursesVisualizer.
- #run ⇒ Object
Constructor Details
#initialize(colors:, compact:, highlights:, root:) ⇒ CursesVisualizer
Returns a new instance of CursesVisualizer.
5 6 7 8 9 10 |
# File 'lib/hutils/curses_visualizer.rb', line 5 def initialize(colors:, compact:, highlights:, root:) @colors = colors @highlights = highlights @line_buffer = [] @root = root end |
Instance Method Details
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hutils/curses_visualizer.rb', line 12 def run Curses.cbreak # no need for a newline to get type chars Curses.curs_set(0) # invisible Curses.noecho # don't echo character on a getch Curses.start_color Curses.use_default_colors Curses.init_pair(COLOR_KEY, -1, Curses::COLOR_BLUE) Curses.init_pair(COLOR_HIGHLIGHT, Curses::COLOR_BLACK, Curses::COLOR_YELLOW) Curses.init_screen trap("SIGINT", "SIGTERM") do Curses.close_screen # @todo: curses shutdown? $stdout.puts "Caught deadly signal" $stdout.flush exit(0) end # set root node as "expanded" @root.[:expanded] = true @need_repaint = true @selected_line = 0 build_line_buffer loop do if @need_repaint build_line_buffer paint @need_repaint = false end handle_key end end |