Class: Fatty::StatusSession

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

Constant Summary collapse

DEFAULT_MAX_ROWS =
6

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) ⇒ StatusSession

Returns a new instance of StatusSession.



9
10
11
12
13
# File 'lib/fatty/session/status_session.rb', line 9

def initialize(id: nil)
  super
  @text = nil
  @role = :info
end

Instance Attribute Details

#roleObject (readonly)

Returns the value of attribute role.



7
8
9
# File 'lib/fatty/session/status_session.rb', line 7

def role
  @role
end

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'lib/fatty/session/status_session.rb', line 7

def text
  @text
end

Instance Method Details

#stateObject

Other public API methods



55
56
57
58
59
60
61
62
63
64
# File 'lib/fatty/session/status_session.rb', line 55

def state
  [
    text.dup.freeze,
    role.dup,
    renderer.screen.status_rect.row.dup,
    renderer.screen.status_rect.rows.dup,
    renderer.screen.status_rect.cols.dup,
    renderer.theme_version
  ]
end

#update(command) ⇒ Object

Session Protocol



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fatty/session/status_session.rb', line 19

def update(command)
  Fatty.debug(
    "StatusSession before action=#{command.action} text=#{text.inspect}",
    tag: :session,
  )
  log_update(command)
  old_rows = rows
  case command.action
  when :show
    set(command.payload)
  when :clear
    clear
  end
  Fatty.debug(
    "StatusSession after action=#{command.action} text=#{text.inspect}",
    tag: :session,
  )
  new_rows = rows
  commands = []
  if old_rows != new_rows
    commands << Command.terminal(:set_status_rows, rows: new_rows)
    commands << Command.terminal(:refresh_layout)
  end
  commands.compact
end

#viewObject



45
46
47
48
49
# File 'lib/fatty/session/status_session.rb', line 45

def view
  return unless visible?

  renderer.render_status(self)
end