Class: Fatty::Session
- Inherits:
-
Object
- Object
- Fatty::Session
- Includes:
- Actionable
- Defined in:
- lib/fatty/session.rb
Overview
Base class for stateful runtime components.
Charm/Bubbletea-style contract:
init(terminal:) => commands
update(message) => commands
view(screen:, renderer:, terminal:) => renders only (no return contract)
Where commands is an Array (possibly empty). Terminal is responsible for
executing commands after each update cycle.
Direct Known Subclasses
AlertSession, ISearchSession, KeyTestSession, ModalSession, OutputSession, SearchSession, ShellSession, StatusSession
Instance Attribute Summary collapse
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#keymap ⇒ Object
readonly
Returns the value of attribute keymap.
-
#terminal ⇒ Object
readonly
Returns the value of attribute terminal.
Instance Method Summary collapse
- #close ⇒ Object
- #handle_resize ⇒ Object
-
#init(terminal:) ⇒ Object
Called once when the session becomes active (e.g. pushed).
-
#initialize(id: nil, keymap: nil) ⇒ Session
constructor
A new instance of Session.
-
#persist! ⇒ Object
Save any state we want saved on quit, error, etc.
- #renderer ⇒ Object
- #screen ⇒ Object
- #tick ⇒ Object
-
#update(command) ⇒ Object
Handle an incoming Command, which can carry an action or a KeyEvent.
-
#view ⇒ Object
By default, does nothing.
Methods included from Actionable
Constructor Details
Instance Attribute Details
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
17 18 19 |
# File 'lib/fatty/session.rb', line 17 def counter @counter end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
17 18 19 |
# File 'lib/fatty/session.rb', line 17 def id @id end |
#keymap ⇒ Object (readonly)
Returns the value of attribute keymap.
17 18 19 |
# File 'lib/fatty/session.rb', line 17 def keymap @keymap end |
#terminal ⇒ Object (readonly)
Returns the value of attribute terminal.
17 18 19 |
# File 'lib/fatty/session.rb', line 17 def terminal @terminal end |
Instance Method Details
#close ⇒ Object
44 45 |
# File 'lib/fatty/session.rb', line 44 def close end |
#handle_resize ⇒ Object
47 48 49 |
# File 'lib/fatty/session.rb', line 47 def handle_resize [] end |
#init(terminal:) ⇒ Object
Called once when the session becomes active (e.g. pushed). Subclasses may override to kick off timers/async work, etc.
27 28 29 30 |
# File 'lib/fatty/session.rb', line 27 def init(terminal:) @terminal = terminal [] end |
#persist! ⇒ Object
Save any state we want saved on quit, error, etc.
52 53 |
# File 'lib/fatty/session.rb', line 52 def persist! end |
#renderer ⇒ Object
59 60 61 |
# File 'lib/fatty/session.rb', line 59 def renderer terminal.renderer end |
#screen ⇒ Object
63 64 65 |
# File 'lib/fatty/session.rb', line 63 def screen terminal.screen end |
#tick ⇒ Object
55 56 57 |
# File 'lib/fatty/session.rb', line 55 def tick false end |
#update(command) ⇒ Object
Handle an incoming Command, which can carry an action or a KeyEvent. On execution, those can return one or more Commands, which update returns to its caller for further dispatch.
35 36 37 |
# File 'lib/fatty/session.rb', line 35 def update(command) # raise NotImplementedError, "#{self.class} must implement \#update" end |
#view ⇒ Object
By default, does nothing. Subclasses can override, but should not mutate state here.
41 42 |
# File 'lib/fatty/session.rb', line 41 def view end |