Class: TuiTui::Runtime

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

Overview

Small Elm-style loop: render, read one event, fold it through the app, repeat.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Runtime

Returns a new instance of Runtime.



9
10
11
# File 'lib/tui_tui/runtime.rb', line 9

def initialize(app)
  @app = app
end

Instance Method Details

#run(input: $stdin, output: $stdout, depth: ColorDepth.detect, tick: 0.1, mouse: Screen.mouse_default, box: ENV["TUITUI_BOX"]) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tui_tui/runtime.rb', line 13

def run(input: $stdin, output: $stdout, depth: ColorDepth.detect, tick: 0.1, mouse: Screen.mouse_default, box: ENV["TUITUI_BOX"])
  Screen.run(input: input, output: output, depth: depth, mouse: mouse, box: box) do |screen|
    raise "tui_tui: not a terminal" if screen.nil?

    screen.render(view(screen))
    loop do
      event = screen.events.next_event(tick: tick)
      break if event.is_a?(EofEvent)
      next if inert_tick?(event)

      screen.invalidate if wants_redraw?(event)
      result = @app.update(event)
      break if result == :quit || result.nil?

      @app = result
      flush_clipboard(screen)
      screen.render(view(screen))
    end
  end
end