Class: Clacky::UI2::ViewRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/clacky/ui2/view_renderer.rb

Overview

ViewRenderer coordinates all UI components and provides a unified rendering interface

Instance Method Summary collapse

Constructor Details

#initializeViewRenderer

Returns a new instance of ViewRenderer.



12
13
14
15
16
# File 'lib/clacky/ui2/view_renderer.rb', line 12

def initialize
  @message_component = Components::MessageComponent.new
  @tool_component = Components::ToolComponent.new
  @common_component = Components::CommonComponent.new
end

Instance Method Details

#render_assistant_message(content, timestamp: nil) ⇒ String

Render an assistant message

Parameters:

  • content (String)

    Message content

  • timestamp (Time, nil) (defaults to: nil)

    Optional timestamp

Returns:

  • (String)

    Rendered message



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/clacky/ui2/view_renderer.rb', line 36

def render_assistant_message(content, timestamp: nil)
  # Render markdown if content contains markdown syntax
  rendered_content = if MarkdownRenderer.markdown?(content)
    MarkdownRenderer.render(content)
  else
    content
  end

  @message_component.render(
    role: "assistant",
    content: rendered_content,
    timestamp: timestamp
  )
end

#render_error(message) ⇒ String

Render error message

Parameters:

  • message (String)

    Error message

Returns:

  • (String)

    Error message



147
148
149
# File 'lib/clacky/ui2/view_renderer.rb', line 147

def render_error(message)
  @common_component.render_error(message)
end

#render_progress(message) ⇒ String

Render progress message (stopped state, gray)

Parameters:

  • message (String)

    Progress message

Returns:

  • (String)

    Progress indicator



126
127
128
# File 'lib/clacky/ui2/view_renderer.rb', line 126

def render_progress(message)
  @common_component.render_progress(message)
end

#render_success(message) ⇒ String

Render success message

Parameters:

  • message (String)

    Success message

Returns:

  • (String)

    Success message



140
141
142
# File 'lib/clacky/ui2/view_renderer.rb', line 140

def render_success(message)
  @common_component.render_success(message)
end

#render_system_message(content, timestamp: nil, prefix_newline: true) ⇒ String

Render a system message

Parameters:

  • content (String)

    Message content

  • timestamp (Time, nil) (defaults to: nil)

    Optional timestamp

  • prefix_newline (Boolean) (defaults to: true)

    Whether to add newline before message

Returns:

  • (String)

    Rendered message



56
57
58
59
60
61
62
63
# File 'lib/clacky/ui2/view_renderer.rb', line 56

def render_system_message(content, timestamp: nil, prefix_newline: true)
  @message_component.render(
    role: "system",
    content: content,
    timestamp: timestamp,
    prefix_newline: prefix_newline
  )
end

#render_task_complete(iterations:, cost:, duration: nil, cache_tokens: nil, cache_requests: nil, cache_hits: nil) ⇒ String

Render task completion summary

Parameters:

  • iterations (Integer)

    Number of iterations

  • cost (Float)

    Cost in USD

  • duration (Float) (defaults to: nil)

    Duration in seconds

  • cache_tokens (Integer) (defaults to: nil)

    Cache read tokens

  • cache_requests (Integer) (defaults to: nil)

    Total cache requests count

  • cache_hits (Integer) (defaults to: nil)

    Cache hit requests count

Returns:

  • (String)

    Formatted completion summary



166
167
168
169
170
171
172
173
174
175
# File 'lib/clacky/ui2/view_renderer.rb', line 166

def render_task_complete(iterations:, cost:, duration: nil, cache_tokens: nil, cache_requests: nil, cache_hits: nil)
  @common_component.render_task_complete(
    iterations: iterations,
    cost: cost,
    duration: duration,
    cache_tokens: cache_tokens,
    cache_requests: cache_requests,
    cache_hits: cache_hits
  )
end

#render_thinkingString

Render thinking indicator

Returns:

  • (String)

    Thinking indicator



119
120
121
# File 'lib/clacky/ui2/view_renderer.rb', line 119

def render_thinking
  @common_component.render_thinking
end

#render_tool_call(tool_name:, formatted_call:) ⇒ String

Render a tool call

Parameters:

  • tool_name (String)

    Tool name

  • formatted_call (String)

    Formatted call description

Returns:

  • (String)

    Rendered tool call



69
70
71
72
73
74
75
# File 'lib/clacky/ui2/view_renderer.rb', line 69

def render_tool_call(tool_name:, formatted_call:)
  @tool_component.render(
    type: :call,
    tool_name: tool_name,
    formatted_call: formatted_call
  )
end

#render_tool_denied(tool_name:) ⇒ String

Render a tool denied message

Parameters:

  • tool_name (String)

    Tool name

Returns:

  • (String)

    Rendered tool denied



100
101
102
103
104
105
# File 'lib/clacky/ui2/view_renderer.rb', line 100

def render_tool_denied(tool_name:)
  @tool_component.render(
    type: :denied,
    tool_name: tool_name
  )
end

#render_tool_error(error:) ⇒ String

Render a tool error

Parameters:

  • error (String)

    Error message

Returns:

  • (String)

    Rendered tool error



90
91
92
93
94
95
# File 'lib/clacky/ui2/view_renderer.rb', line 90

def render_tool_error(error:)
  @tool_component.render(
    type: :error,
    error: error
  )
end

#render_tool_planned(tool_name:) ⇒ String

Render a tool planned message

Parameters:

  • tool_name (String)

    Tool name

Returns:

  • (String)

    Rendered tool planned



110
111
112
113
114
115
# File 'lib/clacky/ui2/view_renderer.rb', line 110

def render_tool_planned(tool_name:)
  @tool_component.render(
    type: :planned,
    tool_name: tool_name
  )
end

#render_tool_result(result:) ⇒ String

Render a tool result

Parameters:

  • result (String)

    Tool result

Returns:

  • (String)

    Rendered tool result



80
81
82
83
84
85
# File 'lib/clacky/ui2/view_renderer.rb', line 80

def render_tool_result(result:)
  @tool_component.render(
    type: :result,
    result: result
  )
end

#render_user_message(content, timestamp: nil, files: []) ⇒ String

Render a user message

Parameters:

  • content (String)

    Message content

  • timestamp (Time, nil) (defaults to: nil)

    Optional timestamp

  • files (Array<Hash>) (defaults to: [])

    Optional file hashes { name:, mime_type:, … }

Returns:

  • (String)

    Rendered message



23
24
25
26
27
28
29
30
# File 'lib/clacky/ui2/view_renderer.rb', line 23

def render_user_message(content, timestamp: nil, files: [])
  @message_component.render(
    role: "user",
    content: content,
    timestamp: timestamp,
    files: files
  )
end

#render_warning(message) ⇒ String

Render warning message

Parameters:

  • message (String)

    Warning message

Returns:

  • (String)

    Warning message



154
155
156
# File 'lib/clacky/ui2/view_renderer.rb', line 154

def render_warning(message)
  @common_component.render_warning(message)
end

#render_working(message) ⇒ String

Render working message (active state, yellow)

Parameters:

  • message (String)

    Progress message

Returns:

  • (String)

    Working indicator



133
134
135
# File 'lib/clacky/ui2/view_renderer.rb', line 133

def render_working(message)
  @common_component.render_working(message)
end