Class: Clacky::UI2::Components::CommonComponent

Inherits:
BaseComponent show all
Defined in:
lib/clacky/ui2/components/common_component.rb

Overview

CommonComponent renders common UI elements (progress, success, error, warning)

Instance Method Summary collapse

Methods inherited from BaseComponent

#initialize, #render, render

Constructor Details

This class inherits a constructor from Clacky::UI2::Components::BaseComponent

Instance Method Details

#render_error(message) ⇒ String

Render error message

Parameters:

  • message (String)

    Error message

Returns:

  • (String)

    Error message



48
49
50
51
52
# File 'lib/clacky/ui2/components/common_component.rb', line 48

def render_error(message)
  symbol = format_symbol(:error)
  text = format_text(message, :error)
  "#{symbol} #{text}"
end

#render_progress(message) ⇒ String

Render progress indicator (stopped state, gray)

Parameters:

  • message (String)

    Progress message

Returns:

  • (String)

    Progress indicator



21
22
23
24
25
# File 'lib/clacky/ui2/components/common_component.rb', line 21

def render_progress(message)
  symbol = format_symbol(:thinking)
  text = format_text(message, :thinking)
  "#{symbol} #{text}"
end

#render_success(message) ⇒ String

Render success message

Parameters:

  • message (String)

    Success message

Returns:

  • (String)

    Success message



39
40
41
42
43
# File 'lib/clacky/ui2/components/common_component.rb', line 39

def render_success(message)
  symbol = format_symbol(:success)
  text = format_text(message, :success)
  "#{symbol} #{text}"
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



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/clacky/ui2/components/common_component.rb', line 71

def render_task_complete(iterations:, cost:, duration: nil, cache_tokens: nil, cache_requests: nil, cache_hits: nil)
  lines = []
  lines << ""
  lines << @pastel.dim("" * 60)
  lines << render_success("Task Complete")
  lines << ""

  # Display each stat on a separate line
  lines << "  Iterations: #{iterations}"
  lines << "  Cost: $#{cost.round(4)}"
  lines << "  Duration: #{duration.round(1)}s" if duration

  # Display cache information if available
  if cache_tokens && cache_tokens > 0
    lines << "  Cache Tokens: #{cache_tokens} tokens"
  end

  if cache_requests && cache_requests > 0
    hit_rate = cache_hits > 0 ? ((cache_hits.to_f / cache_requests) * 100).round(1) : 0
    lines << "  Cache Requests: #{cache_requests} (#{cache_hits} hits, #{hit_rate}% hit rate)"
  end

  lines.join("\n")
end

#render_thinkingString

Render thinking indicator

Returns:

  • (String)

    Thinking indicator



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

def render_thinking
  symbol = format_symbol(:thinking)
  text = format_text("Thinking...", :thinking)
  "#{symbol} #{text}"
end

#render_warning(message) ⇒ String

Render warning message

Parameters:

  • message (String)

    Warning message

Returns:

  • (String)

    Warning message



57
58
59
60
61
# File 'lib/clacky/ui2/components/common_component.rb', line 57

def render_warning(message)
  symbol = format_symbol(:warning)
  text = format_text(message, :warning)
  "#{symbol} #{text}"
end

#render_working(message) ⇒ String

Render working indicator (active state, yellow)

Parameters:

  • message (String)

    Progress message

Returns:

  • (String)

    Working indicator



30
31
32
33
34
# File 'lib/clacky/ui2/components/common_component.rb', line 30

def render_working(message)
  symbol = format_symbol(:working)
  text = format_text(message, :working)
  "#{symbol} #{text}"
end