Class: Potty::Application
- Inherits:
-
Object
- Object
- Potty::Application
- Defined in:
- lib/potty/application.rb
Overview
Main application wrapper: owns the view stack, the tick loop, and a Surface (the render target). Mode picks the surface:
:curses (default) — full-screen curses display, input via getch.
:inline — N lines redrawn in place under the cursor via ANSI,
no init_screen, terminal stays cooked (input
ignored; host drives quit). Good for progress UIs.
Instance Attribute Summary collapse
-
#surface ⇒ Object
readonly
Returns the value of attribute surface.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#tick_interval ⇒ Object
When set (milliseconds), the event loop wakes every interval even without input, advancing time-based widgets (Animator, Countdown).
-
#view_stack ⇒ Object
readonly
Returns the value of attribute view_stack.
-
#window_manager ⇒ Object
readonly
Returns the value of attribute window_manager.
Instance Method Summary collapse
-
#initialize(mode: :curses, lines: nil, theme: nil) ⇒ Application
constructor
A new instance of Application.
- #pop_view ⇒ Object
-
#push_view(view) ⇒ Object
View navigation.
- #quit ⇒ Object
- #refresh_all ⇒ Object (also: #redraw)
-
#resume ⇒ Object
Resume after suspension.
-
#run(root_view) ⇒ Object
Start the application with root view.
-
#suspend ⇒ Object
Suspend the surface for an external process (e.g., shelling out).
-
#tick ⇒ Object
Advance time-based widgets and repaint.
Constructor Details
#initialize(mode: :curses, lines: nil, theme: nil) ⇒ Application
Returns a new instance of Application.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/potty/application.rb', line 28 def initialize(mode: :curses, lines: nil, theme: nil) @view_stack = [] @running = false @theme = theme || Theme.new @mode = mode @lines = lines # Kept for back-compat: curses-mode consumers that draw straight to # window_manager.stdscr or read its dimensions. @window_manager = (mode == :curses ? WindowManager.new : nil) @surface = nil @tick_interval = nil end |
Instance Attribute Details
#surface ⇒ Object (readonly)
Returns the value of attribute surface.
20 21 22 |
# File 'lib/potty/application.rb', line 20 def surface @surface end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
20 21 22 |
# File 'lib/potty/application.rb', line 20 def theme @theme end |
#tick_interval ⇒ Object
When set (milliseconds), the event loop wakes every interval even without input, advancing time-based widgets (Animator, Countdown). Leave nil for a purely blocking, input-driven loop (the default). ~33-50ms gives smooth animation. Required for :inline.
26 27 28 |
# File 'lib/potty/application.rb', line 26 def tick_interval @tick_interval end |
#view_stack ⇒ Object (readonly)
Returns the value of attribute view_stack.
20 21 22 |
# File 'lib/potty/application.rb', line 20 def view_stack @view_stack end |
#window_manager ⇒ Object (readonly)
Returns the value of attribute window_manager.
20 21 22 |
# File 'lib/potty/application.rb', line 20 def window_manager @window_manager end |
Instance Method Details
#pop_view ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/potty/application.rb', line 60 def pop_view return if @view_stack.size <= 1 view = @view_stack.pop view.deactivate @view_stack.last&.activate(self) refresh_all end |
#push_view(view) ⇒ Object
View navigation
53 54 55 56 57 58 |
# File 'lib/potty/application.rb', line 53 def push_view(view) @view_stack.last&.deactivate @view_stack.push(view) view.activate(self) refresh_all end |
#quit ⇒ Object
69 70 71 |
# File 'lib/potty/application.rb', line 69 def quit @running = false end |
#refresh_all ⇒ Object Also known as: redraw
73 74 75 76 77 |
# File 'lib/potty/application.rb', line 73 def refresh_all @surface.erase current_view&.render @surface.present end |
#resume ⇒ Object
Resume after suspension.
94 95 96 97 98 |
# File 'lib/potty/application.rb', line 94 def resume @surface&.start current_view&.activate(self) refresh_all end |
#run(root_view) ⇒ Object
Start the application with root view
42 43 44 45 46 47 48 49 50 |
# File 'lib/potty/application.rb', line 42 def run(root_view) @surface = build_surface @surface.start push_view(root_view) @running = true event_loop ensure @surface&.finalize end |
#suspend ⇒ Object
Suspend the surface for an external process (e.g., shelling out).
89 90 91 |
# File 'lib/potty/application.rb', line 89 def suspend @surface&.finalize end |
#tick ⇒ Object
Advance time-based widgets and repaint. Called automatically each event-loop frame; also public so a host that drives its own loop can pump animation/countdowns itself.
83 84 85 86 |
# File 'lib/potty/application.rb', line 83 def tick current_view&.tick(Time.now) refresh_all end |