Class: RubyRich::ToolBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_rich/tool_block.rb

Constant Summary collapse

STATES =
[:pending, :running, :done, :error, :cancelled, :denied].freeze

Instance Method Summary collapse

Constructor Details

#initialize(entry, width: 80) ⇒ ToolBlock

Returns a new instance of ToolBlock.



7
8
9
10
# File 'lib/ruby_rich/tool_block.rb', line 7

def initialize(entry, width: 80)
  @entry = entry
  @width = [width, 20].max
end

Instance Method Details

#renderObject



12
13
14
15
16
17
18
19
# File 'lib/ruby_rich/tool_block.rb', line 12

def render
  name = @entry.name || @entry.[:name] || "tool"
  status = normalize_status(@entry.status || :pending)
  header = "#{AnsiCode.color(color(status), true)}#{status_marker(status)} #{name} #{status}#{AnsiCode.reset}"
  return [header, "  #{summary(@entry.content)}", "  details collapsed; press Ctrl+O for full output"] if @entry.collapsed

  [header] + details(@entry.content)
end