Class: Legion::TTY::Components::InputBar
- Inherits:
-
Object
- Object
- Legion::TTY::Components::InputBar
- Defined in:
- lib/legion/tty/components/input_bar.rb
Instance Attribute Summary collapse
-
#completions ⇒ Object
readonly
Returns the value of attribute completions.
Instance Method Summary collapse
- #clear_thinking ⇒ Object
- #complete(partial) ⇒ Object
- #history ⇒ Object
-
#initialize(name: 'User', reader: nil, completions: []) ⇒ InputBar
constructor
A new instance of InputBar.
- #prompt_string ⇒ Object
- #read_line ⇒ Object
- #show_thinking ⇒ Object
- #thinking? ⇒ Boolean
Constructor Details
#initialize(name: 'User', reader: nil, completions: []) ⇒ InputBar
Returns a new instance of InputBar.
11 12 13 14 15 16 |
# File 'lib/legion/tty/components/input_bar.rb', line 11 def initialize(name: 'User', reader: nil, completions: []) @name = name @completions = completions @reader = reader || build_default_reader @thinking = false end |
Instance Attribute Details
#completions ⇒ Object (readonly)
Returns the value of attribute completions.
9 10 11 |
# File 'lib/legion/tty/components/input_bar.rb', line 9 def completions @completions end |
Instance Method Details
#clear_thinking ⇒ Object
30 31 32 |
# File 'lib/legion/tty/components/input_bar.rb', line 30 def clear_thinking @thinking = false end |
#complete(partial) ⇒ Object
38 39 40 41 42 |
# File 'lib/legion/tty/components/input_bar.rb', line 38 def complete(partial) return [] if partial.nil? || partial.empty? @completions.select { |c| c.start_with?(partial) }.sort end |
#history ⇒ Object
44 45 46 47 48 |
# File 'lib/legion/tty/components/input_bar.rb', line 44 def history return [] unless @reader.respond_to?(:history) @reader.history.to_a end |
#prompt_string ⇒ Object
18 19 20 |
# File 'lib/legion/tty/components/input_bar.rb', line 18 def prompt_string "#{Theme.c(:accent, @name)} #{Theme.c(:primary, '>')} " end |
#read_line ⇒ Object
22 23 24 |
# File 'lib/legion/tty/components/input_bar.rb', line 22 def read_line @reader.read_line(prompt_string) end |
#show_thinking ⇒ Object
26 27 28 |
# File 'lib/legion/tty/components/input_bar.rb', line 26 def show_thinking @thinking = true end |
#thinking? ⇒ Boolean
34 35 36 |
# File 'lib/legion/tty/components/input_bar.rb', line 34 def thinking? @thinking end |