Class: Foruiman::TUI::Renderer
- Inherits:
-
Object
- Object
- Foruiman::TUI::Renderer
- Defined in:
- lib/foruiman/tui/renderer.rb
Constant Summary collapse
- HELP =
[ ["↔ NAVIGATE", "Tab / Shift-Tab", "Change tab", "← → or h l"], [nil, "1–9 / 0", "Select a process / all logs", nil], ["≡ READ LOGS", "↑ ↓ or k j", "Scroll a line", nil], [nil, "PgUp / PgDn", "Scroll a page", "Ctrl-U / Ctrl-D"], [nil, "g / Home", "Oldest retained line", nil], [nil, "f / G / End", "Follow newest output", nil], [nil, "Space", "Pause / resume following", nil], ["⚙ PROCESSES", "r / R", "Restart selected / all", "r on all restarts all"], [nil, "s / S", "Start/stop selected / stop all", "s on all stops all"], ["⌨ INPUT", "i", "Edit a command; Enter sends", "Ctrl-X returns to Foruiman"], ["◇ SESSION", "? / Escape", "Close help", nil], [nil, "q / Ctrl-C", "Stop processes and quit", nil] ].freeze
Class Method Summary collapse
- .expanded?(rows:, columns:) ⇒ Boolean
- .log_height(rows:, columns:, input: false) ⇒ Object
- .truncate(text, columns) ⇒ Object
- .width(text) ⇒ Object
Instance Method Summary collapse
-
#initialize(theme: Theme.new) ⇒ Renderer
constructor
A new instance of Renderer.
- #render(state, engine, rows:, columns:) ⇒ Object
Constructor Details
Class Method Details
.expanded?(rows:, columns:) ⇒ Boolean
30 31 32 |
# File 'lib/foruiman/tui/renderer.rb', line 30 def self.(rows:, columns:) rows >= 14 && columns >= 60 end |
.log_height(rows:, columns:, input: false) ⇒ Object
34 35 36 37 38 |
# File 'lib/foruiman/tui/renderer.rb', line 34 def self.log_height(rows:, columns:, input: false) return 0 if rows < 6 || columns < 24 rows - ((rows: rows, columns: columns) ? 7 : 5) - (input && rows >= 8 ? 2 : 0) end |
Instance Method Details
#render(state, engine, rows:, columns:) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/foruiman/tui/renderer.rb', line 40 def render(state, engine, rows:, columns:) @width = [columns - 1, 1].max @inside = [@width - 4, 0].max @height = self.class.log_height(rows: rows, columns: columns, input: state.input?) return tiny_frame(state, engine, rows) if @height.zero? lines = [header(engine)] if self.class.(rows: rows, columns: columns) hint = @inside >= 70 ? " Tab switch · 1–9 / 0 select " : "" lines << border(@theme.paint(" processes ", :muted, bold: true), @theme.paint(hint, :faint)) lines << panel(tab_row(state, engine, @inside - 2)) lines << border("", "", bottom: true) else lines << " #{@theme.paint('│', :border)} #{tab_row(state, engine, @inside - 2)}" end lines << log_header(state, engine) lines.concat(state.help ? help_rows : log_rows(state, engine)) lines << (state, engine) lines.concat(input_rows(state)) if state.input? && rows >= 8 lines << controls(state, engine) frame(lines, rows) end |