Class: Blight::RunsLoop

Inherits:
Object
  • Object
show all
Defined in:
lib/blight.rb

Instance Method Summary collapse

Instance Method Details

#run(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/blight.rb', line 6

def run(options = {})
  config = default_options.merge(options)

  begin
    Ncurses.initscr
    Ncurses.raw
    Ncurses.start_color if config[:color]
    config[:echo] ? Ncurses.echo : Ncurses.noecho

    yield window = Window.new

    while window.open?
      key = Ncurses.stdscr.getch
      config[:listeners].each { |l| l.listen({value: key.chr}, window) }
    end

  ensure
    Ncurses.endwin
  end
end