Class: SwarmCLI::UI::Components::Panel

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_cli/ui/components/panel.rb

Overview

Renders highlighted panels for warnings, info, errors Uses top/bottom borders only (no sides per design constraint)

Constant Summary collapse

TYPE_CONFIGS =
{
  warning: { color: :yellow, icon: UI::Icons::WARNING },
  error: { color: :red, icon: UI::Icons::ERROR },
  info: { color: :cyan, icon: UI::Icons::INFO },
  success: { color: :green, icon: UI::Icons::SUCCESS },
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(pastel:, terminal_width: 80) ⇒ Panel

Returns a new instance of Panel.



16
17
18
19
# File 'lib/swarm_cli/ui/components/panel.rb', line 16

def initialize(pastel:, terminal_width: 80)
  @pastel = pastel
  @terminal_width = terminal_width
end

Instance Method Details

#render(type:, title:, lines:, indent: 0) ⇒ Object

Render panel with top/bottom borders

⚠️ CONTEXT WARNING Context usage: 81.4% (threshold: 80%) Tokens remaining: 74,523



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/swarm_cli/ui/components/panel.rb', line 27

def render(type:, title:, lines:, indent: 0)
  config = TYPE_CONFIGS[type] || TYPE_CONFIGS[:info]
  prefix = "  " * indent

  output = []

  # Title line with icon
  icon = config[:icon]
  colored_title = @pastel.public_send(config[:color], "#{icon} #{title}")
  output << "#{prefix}#{colored_title}"

  # Content lines
  lines.each do |line|
    output << "#{prefix}  #{line}"
  end

  output << "" # Blank line after panel

  output.join("\n")
end

#render_compact(type:, message:, indent: 0) ⇒ Object

Render compact panel (single line) ⚠️ Context approaching limit (81.4%)



50
51
52
53
54
55
56
57
58
# File 'lib/swarm_cli/ui/components/panel.rb', line 50

def render_compact(type:, message:, indent: 0)
  config = TYPE_CONFIGS[type] || TYPE_CONFIGS[:info]
  prefix = "  " * indent

  icon = config[:icon]
  colored_msg = @pastel.public_send(config[:color], "#{icon} #{message}")

  "#{prefix}#{colored_msg}"
end