Class: TUI::Decorators::BaseDecorator
- Inherits:
-
Object
- Object
- TUI::Decorators::BaseDecorator
- Includes:
- Formatting
- Defined in:
- lib/tui/decorators/base_decorator.rb
Direct Known Subclasses
BashDecorator, EditDecorator, ReadDecorator, ThinkDecorator, WebGetDecorator, WriteDecorator
Constant Summary collapse
- ICON =
wrench
"\u{1F527}"- CHECKMARK =
"\u2713"- RETURN_ARROW =
"\u21A9"- ERROR_ICON =
"\u274C"
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
-
.for(data) ⇒ BaseDecorator
Factory returning the per-tool decorator for the given data hash.
Instance Method Summary collapse
-
#color ⇒ String
Unified color for all tool call headers.
-
#icon ⇒ String
Icon for this tool type.
-
#initialize(data) ⇒ BaseDecorator
constructor
A new instance of BaseDecorator.
-
#render(tui) ⇒ Array<RatatuiRuby::Widgets::Line>
Renders the event, dispatching by role to the appropriate method.
-
#render_call(tui) ⇒ Array<RatatuiRuby::Widgets::Line>
Generic tool call rendering — icon, tool name, and indented input.
-
#render_response(tui) ⇒ Array<RatatuiRuby::Widgets::Line>
Generic tool response rendering — success/failure indicator and content.
-
#render_think(tui) ⇒ Array<RatatuiRuby::Widgets::Line>
Think rendering — delegated to ThinkDecorator, but base provides a fallback that renders as a generic tool call.
-
#response_color ⇒ String
Color for tool response content.
Methods included from Formatting
#format_ns_timestamp, #format_token_label, #preserve_indentation, #token_count_color
Constructor Details
#initialize(data) ⇒ BaseDecorator
Returns a new instance of BaseDecorator.
52 53 54 |
# File 'lib/tui/decorators/base_decorator.rb', line 52 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
50 51 52 |
# File 'lib/tui/decorators/base_decorator.rb', line 50 def data @data end |
Class Method Details
.for(data) ⇒ BaseDecorator
Factory returning the per-tool decorator for the given data hash.
61 62 63 64 |
# File 'lib/tui/decorators/base_decorator.rb', line 61 def self.for(data) tool = resolve_tool(data) decorator_for(tool).new(data) end |
Instance Method Details
#color ⇒ String
Unified color for all tool call headers. Keeps tool invocations visually distinct from conversation messages (user/assistant/thought).
142 143 144 |
# File 'lib/tui/decorators/base_decorator.rb', line 142 def color Settings.theme_color_accent end |
#icon ⇒ String
Icon for this tool type. Subclasses override with tool-specific icons.
135 136 137 |
# File 'lib/tui/decorators/base_decorator.rb', line 135 def icon ICON end |
#render(tui) ⇒ Array<RatatuiRuby::Widgets::Line>
Renders the event, dispatching by role to the appropriate method.
70 71 72 73 74 75 76 |
# File 'lib/tui/decorators/base_decorator.rb', line 70 def render(tui) case data["role"].to_s when "tool_call" then render_call(tui) when "tool_response" then render_response(tui) when "think" then render_think(tui) end end |
#render_call(tui) ⇒ Array<RatatuiRuby::Widgets::Line>
Generic tool call rendering — icon, tool name, and indented input. Subclasses override for tool-specific presentation.
83 84 85 86 87 88 89 90 91 |
# File 'lib/tui/decorators/base_decorator.rb', line 83 def render_call(tui) style = tui.style(fg: color) header = build_call_header lines = [tui.line(spans: [tui.span(content: header, style: style)])] data["input"].to_s.split("\n", -1).each do |line| lines << tui.line(spans: [tui.span(content: preserve_indentation(" #{line}"), style: style)]) end lines end |
#render_response(tui) ⇒ Array<RatatuiRuby::Widgets::Line>
Generic tool response rendering — success/failure indicator and content. Token counts get their own color-coded span so expensive responses visually jump out in debug mode. Subclasses override for tool-specific presentation.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/tui/decorators/base_decorator.rb', line 100 def render_response(tui) indicator = (data["success"] == false) ? ERROR_ICON : CHECKMARK tool_id = data["tool_use_id"] tokens = data["tokens"] style = tui.style(fg: response_color) = [] << "[#{tool_id}]" if tool_id << indicator prefix = " #{RETURN_ARROW} #{.join(" ")} " content_lines = data["content"].to_s.split("\n", -1) first_line_spans = [tui.span(content: prefix, style: style)] if tokens tok_label = format_token_label(tokens, data["estimated"]) first_line_spans << tui.span(content: "#{tok_label} ", style: tui.style(fg: token_count_color(tokens))) end first_line_spans << tui.span(content: content_lines.first.to_s, style: style) lines = [tui.line(spans: first_line_spans)] content_lines.drop(1).each { |line| lines << tui.line(spans: [tui.span(content: preserve_indentation(" #{line}"), style: style)]) } lines end |
#render_think(tui) ⇒ Array<RatatuiRuby::Widgets::Line>
Think rendering — delegated to ThinkDecorator, but base provides a fallback that renders as a generic tool call.
129 130 131 |
# File 'lib/tui/decorators/base_decorator.rb', line 129 def render_think(tui) render_call(tui) end |
#response_color ⇒ String
Color for tool response content. Subclasses override for tool-specific colors.
148 149 150 |
# File 'lib/tui/decorators/base_decorator.rb', line 148 def response_color Settings.theme_color_text end |