Class: Fatty::KeyTestSession

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

Instance Attribute Summary

Attributes inherited from Session

#counter, #keymap, #terminal, #views

Instance Method Summary collapse

Methods inherited from Session

#add_view, #handle_action, #handle_resize, #inspect, #keymap_contexts, #persist!, #resolve_action, #tick, #update

Methods included from Actionable

included

Constructor Details

#initialize(owner: nil) ⇒ KeyTestSession

Returns a new instance of KeyTestSession.



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

def initialize(owner: nil)
  super(keymap: nil, views: [])
  @owner = owner
end

Instance Method Details

#closeObject



51
52
53
54
55
56
# File 'lib/fatty/session/keytest_session.rb', line 51

def close
  write_suggestions!
  restore_owner_pager!
  terminal.clear_status if terminal.respond_to?(:clear_status)
  nil
end

#idObject



7
# File 'lib/fatty/session/keytest_session.rb', line 7

def id = :keytest

#init(terminal:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fatty/session/keytest_session.rb', line 14

def init(terminal:)
  super
  @suggestions = []
  @owner ||= terminal.focused_session
  show_quit_status
  force_scrolling_output!
  append <<~TEXT
    Key test mode

    Press keys to inspect Fatty's decoding and binding resolution.
    Press q, ESC, or C-g to leave key test mode.

  TEXT
  []
end

#update_key(ev) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fatty/session/keytest_session.rb', line 30

def update_key(ev)
  if quit_key?(ev)
    append "Leaving key test mode.\n\n"
    return [[:terminal, :pop_modal]]
  end

  # append "  TERM:      #{terminal_name}\n"
  append ev.report
  snippet = ev.suggested_snippet(terminal_name)
  append snippet + "\n"
  @suggestions << snippet unless snippet.empty?
  show_quit_status
  []
end

#view(screen:, renderer:) ⇒ Object



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

def view(screen:, renderer:)
  # Intentionally blank. The underlying shell session renders the output
  # pane; this modal only captures keys and appends diagnostic text.
  nil
end