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.



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

def initialize(app)
  @app = app
end

Instance Method Details

#run(input: $stdin, output: $stdout, depth: ColorDepth.detect, tick: 0.1, mouse: Screen.mouse_default) ⇒ Object



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

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

    screen.render(@app.view(screen.size))
    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(@app.view(screen.size))
    end
  end
end