Class: Fatty::AlertSession

Inherits:
Session
  • Object
show all
Defined in:
lib/fatty/session/alert_session.rb

Overview

A pinned, non-interactive overlay session responsible for rendering alerts.

Instance Attribute Summary collapse

Attributes inherited from Session

#counter, #id, #keymap, #terminal

Instance Method Summary collapse

Methods inherited from Session

#close, #handle_resize, #init, #persist!, #renderer, #screen, #tick

Methods included from Actionable

included

Constructor Details

#initialize(id: nil) ⇒ AlertSession

Returns a new instance of AlertSession.



8
9
10
11
# File 'lib/fatty/session/alert_session.rb', line 8

def initialize(id: nil)
  super
  @current = nil
end

Instance Attribute Details

#currentObject (readonly)

Returns the value of attribute current.



6
7
8
# File 'lib/fatty/session/alert_session.rb', line 6

def current
  @current
end

Instance Method Details

#stateObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/fatty/session/alert_session.rb', line 32

def state
  [
    current&.text.dup.freeze,
    current&.role,
    current&.details,
    renderer.screen.alert_rect.row,
    renderer.screen.alert_rect.cols,
    renderer.theme_version
  ]
end

#update(command) ⇒ Object

Session Protocol



17
18
19
20
21
22
23
24
25
26
# File 'lib/fatty/session/alert_session.rb', line 17

def update(command)
  Fatty.debug("AlertSession#update: action: #{command.action} alert: #{command.payload[:alert].inspect}")
  case command.action
  when :show
    show_from_payload(command.payload[:alert] || command.payload)
  when :clear
    @current = nil unless @current&.sticky?
  end
  []
end

#viewObject



28
29
30
# File 'lib/fatty/session/alert_session.rb', line 28

def view
  renderer.render_alert(self)
end