Class: Legion::TTY::Components::ToolPanel

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

Constant Summary collapse

ICONS =
{
  running: "\u27F3",
  complete: "\u2713",
  failed: "\u2717"
}.freeze
STATUS_COLORS =
{
  running: :info,
  complete: :success,
  failed: :error
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(name:, args:, status: :running, duration: nil, result: nil, error: nil) ⇒ ToolPanel

rubocop:disable Metrics/ParameterLists



22
23
24
25
26
27
28
29
30
# File 'lib/legion/tty/components/tool_panel.rb', line 22

def initialize(name:, args:, status: :running, duration: nil, result: nil, error: nil)
  @name     = name
  @args     = args
  @status   = status
  @duration = duration
  @result   = result
  @error    = error
  @expanded = status == :failed
end

Instance Method Details

#collapseObject



41
42
43
# File 'lib/legion/tty/components/tool_panel.rb', line 41

def collapse
  @expanded = false
end

#expandObject



37
38
39
# File 'lib/legion/tty/components/tool_panel.rb', line 37

def expand
  @expanded = true
end

#expanded?Boolean

rubocop:enable Metrics/ParameterLists

Returns:

  • (Boolean)


33
34
35
# File 'lib/legion/tty/components/tool_panel.rb', line 33

def expanded?
  @expanded
end

#render(width: 80) ⇒ Object



49
50
51
52
53
# File 'lib/legion/tty/components/tool_panel.rb', line 49

def render(width: 80)
  lines = [header_line(width)]
  lines << body_line if @expanded && body_content
  lines.join("\n")
end

#toggleObject



45
46
47
# File 'lib/legion/tty/components/tool_panel.rb', line 45

def toggle
  @expanded = !@expanded
end