Class: Legion::TTY::Components::InputBar

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/tty/components/input_bar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#completionsObject (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_thinkingObject



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

#prompt_stringObject



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_lineObject



22
23
24
# File 'lib/legion/tty/components/input_bar.rb', line 22

def read_line
  @reader.read_line(prompt_string)
end

#show_thinkingObject



26
27
28
# File 'lib/legion/tty/components/input_bar.rb', line 26

def show_thinking
  @thinking = true
end

#thinking?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/legion/tty/components/input_bar.rb', line 34

def thinking?
  @thinking
end