Class: Foruiman::TUI::Application
- Inherits:
-
Object
- Object
- Foruiman::TUI::Application
- Defined in:
- lib/foruiman/tui/application.rb
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #handle(key, height) ⇒ Object
-
#initialize(engine, terminal: Terminal.new, renderer: Renderer.new) ⇒ Application
constructor
A new instance of Application.
- #run ⇒ Object
Constructor Details
#initialize(engine, terminal: Terminal.new, renderer: Renderer.new) ⇒ Application
Returns a new instance of Application.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/foruiman/tui/application.rb', line 12 def initialize(engine, terminal: Terminal.new, renderer: Renderer.new) @engine = engine @terminal = terminal @renderer = renderer @keyboard = Keyboard.new @state = State.new(engine.processes.map(&:name)) @last_frame = nil @next_frame_at = 0 @was_shutting_down = false @feedback_until = 0 end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
10 11 12 |
# File 'lib/foruiman/tui/application.rb', line 10 def state @state end |
Instance Method Details
#handle(key, height) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/foruiman/tui/application.rb', line 52 def handle(key, height) return if @engine.shutting_down? if key.is_a?(Integer) state.select(key.zero? ? state.tabs.size - 1 : key - 1) return end buffer = @engine.logs[state.name] case key when :next then state.move(1) when :previous then state.move(-1) when :up then state..scroll(-1, buffer, height) when :down then state..scroll(1, buffer, height) when :page_up then state..scroll(-height, buffer, height) when :page_down then state..scroll(height, buffer, height) when :home then state..home(buffer) when :end, :follow then state..follow when :toggle_follow then state..toggle(buffer, height) when :help then state.help = !state.help when :escape then state.help = false when :restart then control(key) when :stop then toggle_process when :input then begin_input when :restart_all, :stop_all control_all(key == :restart_all ? :restart : :stop) when :quit then @engine.shutdown end end |
#run ⇒ Object
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 49 50 |
# File 'lib/foruiman/tui/application.rb', line 24 def run @engine.manage_input! @terminal.session do @engine.run(keep_open: true) do rows, columns = @terminal.size @engine.resize_inputs(rows, columns) detach_unavailable_input input = @terminal.read @engine.shutdown if input.nil? height = [Renderer.log_height(rows: rows, columns: columns, input: state.input?), 1].max read_keys(input.is_a?(String) ? input : "", height) state.feedback = nil if monotonic >= @feedback_until next if monotonic < @next_frame_at && @was_shutting_down == @engine.shutting_down? @was_shutting_down = @engine.shutting_down? @next_frame_at = monotonic + (1.0 / 30) frame = @renderer.render(state, @engine, rows: rows, columns: columns) if frame != @last_frame @terminal.draw(frame) @last_frame = frame end end end ensure @engine.close end |