Class: SwarmCLI::UI::Components::ContentBlock
- Inherits:
-
Object
- Object
- SwarmCLI::UI::Components::ContentBlock
- Defined in:
- lib/swarm_cli/ui/components/content_block.rb
Overview
Renders multi-line content blocks with indentation
Instance Method Summary collapse
-
#initialize(pastel:) ⇒ ContentBlock
constructor
A new instance of ContentBlock.
-
#render_hash(data, indent: 0, label: nil, truncate: false, max_value_length: 300) ⇒ Object
Render key-value pairs as indented block Arguments: file_path: "config.yml" mode: "read".
-
#render_list(items, indent: 0, bullet: UI::Icons::BULLET, color: :white) ⇒ Object
Render list items • Item 1 • Item 2.
-
#render_text(text, indent: 0, color: :white, truncate: false, max_lines: nil, max_chars: nil) ⇒ Object
Render multi-line text with indentation.
Constructor Details
#initialize(pastel:) ⇒ ContentBlock
Returns a new instance of ContentBlock.
8 9 10 |
# File 'lib/swarm_cli/ui/components/content_block.rb', line 8 def initialize(pastel:) @pastel = pastel end |
Instance Method Details
#render_hash(data, indent: 0, label: nil, truncate: false, max_value_length: 300) ⇒ Object
Render key-value pairs as indented block Arguments: file_path: "config.yml" mode: "read"
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/swarm_cli/ui/components/content_block.rb', line 16 def render_hash(data, indent: 0, label: nil, truncate: false, max_value_length: 300) return "" if data.nil? || data.empty? lines = [] prefix = " " * indent # Optional label lines << "#{prefix}#{@pastel.dim("#{label}:")}" if label # Render each key-value pair data.each do |key, value| formatted_value = format_value(value, truncate: truncate, max_length: max_value_length) lines << "#{prefix} #{@pastel.cyan("#{key}:")} #{formatted_value}" end lines.join("\n") end |
#render_list(items, indent: 0, bullet: UI::Icons::BULLET, color: :white) ⇒ Object
Render list items • Item 1 • Item 2
68 69 70 71 72 73 74 75 76 |
# File 'lib/swarm_cli/ui/components/content_block.rb', line 68 def render_list(items, indent: 0, bullet: UI::Icons::BULLET, color: :white) return "" if items.nil? || items.empty? prefix = " " * indent items.map do |item| "#{prefix} #{@pastel.public_send(color, "#{bullet} #{item}")}" end.join("\n") end |
#render_text(text, indent: 0, color: :white, truncate: false, max_lines: nil, max_chars: nil) ⇒ Object
Render multi-line text with indentation
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/swarm_cli/ui/components/content_block.rb', line 35 def render_text(text, indent: 0, color: :white, truncate: false, max_lines: nil, max_chars: nil) return "" if text.nil? || text.empty? prefix = " " * indent content = text # Strip system reminders content = Formatters::Text.strip_system_reminders(content) return "" if content.empty? # Apply truncation if requested if truncate content, truncation_msg = Formatters::Text.truncate( content, lines: max_lines, chars: max_chars, ) end # Render lines lines = content.split("\n").map do |line| "#{prefix} #{@pastel.public_send(color, line)}" end # Add truncation message if present lines << "#{prefix} #{@pastel.dim(truncation_msg)}" if truncation_msg lines.join("\n") end |