Class: Marvi::Renderer::Curses

Inherits:
Object
  • Object
show all
Defined in:
lib/marvi/renderer/curses.rb

Constant Summary collapse

COLOR_PAIRS =
{
  cyan:          1,
  green:         2,
  yellow:        3,
  magenta:       4,
  white:         5,
  green_on_dark: 6,
  cyan_on_dark:  7
}.freeze
ITALIC_ATTR =
(::Curses::A_ITALIC) ? ::Curses::A_ITALIC : 0)

Instance Method Summary collapse

Instance Method Details

#render(markdown, file: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/marvi/renderer/curses.rb', line 21

def render(markdown, file: nil)
  @file     = file
  @markdown = markdown
  @lines    = ASTWalker.new.walk(markdown)
  @scroll   = 0

  with_safe_term { ::Curses.init_screen }
  ::Curses.start_color
  ::Curses.use_default_colors
  ::Curses.noecho
  ::Curses.cbreak
  ::Curses.stdscr.keypad(true)
  setup_colors
  draw

  catch(:quit) do
    loop { handle_key(::Curses.getch) }
  end
ensure
  ::Curses.close_screen
end