Class: Fatty::Session

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Actionable

included

Constructor Details

#initialize(id: nil, keymap: nil) ⇒ Session

Returns a new instance of Session.



19
20
21
22
23
# File 'lib/fatty/session.rb', line 19

def initialize(id: nil, keymap: nil)
  @id = id || default_id
  @keymap = keymap
  @counter = Counter.new
end

Instance Attribute Details

#counterObject (readonly)

Returns the value of attribute counter.



17
18
19
# File 'lib/fatty/session.rb', line 17

def counter
  @counter
end

#idObject (readonly)

Returns the value of attribute id.



17
18
19
# File 'lib/fatty/session.rb', line 17

def id
  @id
end

#keymapObject (readonly)

Returns the value of attribute keymap.



17
18
19
# File 'lib/fatty/session.rb', line 17

def keymap
  @keymap
end

#terminalObject (readonly)

Returns the value of attribute terminal.



17
18
19
# File 'lib/fatty/session.rb', line 17

def terminal
  @terminal
end

Instance Method Details

#closeObject



44
45
# File 'lib/fatty/session.rb', line 44

def close
end

#handle_resizeObject



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

#rendererObject



59
60
61
# File 'lib/fatty/session.rb', line 59

def renderer
  terminal.renderer
end

#screenObject



63
64
65
# File 'lib/fatty/session.rb', line 63

def screen
  terminal.screen
end

#tickObject



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

#viewObject

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