Class: Legion::TTY::Components::SessionPicker
- Inherits:
-
Object
- Object
- Legion::TTY::Components::SessionPicker
- Includes:
- Logging::Helper
- Defined in:
- lib/legion/tty/components/session_picker.rb
Instance Method Summary collapse
-
#initialize(session_store:) ⇒ SessionPicker
constructor
A new instance of SessionPicker.
- #select_with_prompt(output: $stdout) ⇒ Object
Constructor Details
#initialize(session_store:) ⇒ SessionPicker
Returns a new instance of SessionPicker.
11 12 13 |
# File 'lib/legion/tty/components/session_picker.rb', line 11 def initialize(session_store:) @session_store = session_store end |
Instance Method Details
#select_with_prompt(output: $stdout) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/legion/tty/components/session_picker.rb', line 15 def select_with_prompt(output: $stdout) sessions = @session_store.list return nil if sessions.empty? require 'tty-prompt' prompt = ::TTY::Prompt.new(output: output) choices = sessions.map do |s| { name: "#{s[:name]} (#{s[:message_count]} msgs, #{s[:saved_at]})", value: s[:name] } end choices << { name: '+ New session', value: :new } prompt.select('Select session:', choices, per_page: 10) rescue ::TTY::Reader::InputInterrupt, Interrupt => e log.debug { "session picker cancelled: #{e.}" } nil end |