Class: SwarmCLI::UI::Components::UsageStats
- Inherits:
-
Object
- Object
- SwarmCLI::UI::Components::UsageStats
- Defined in:
- lib/swarm_cli/ui/components/usage_stats.rb
Overview
Renders usage statistics (tokens, cost, context percentage)
Instance Method Summary collapse
-
#initialize(pastel:) ⇒ UsageStats
constructor
A new instance of UsageStats.
-
#render(tokens:, cost:, context_pct: nil, remaining: nil, cumulative: nil) ⇒ Object
Render usage line with all available metrics 5,922 tokens │ $0.0016 │ 1.5% used, 394,078 remaining.
-
#render_compact(tokens:, cost:, context_pct: nil) ⇒ Object
Render compact stats for prompt display 15.2K tokens • $0.045 • 3.8% context.
Constructor Details
#initialize(pastel:) ⇒ UsageStats
Returns a new instance of UsageStats.
8 9 10 |
# File 'lib/swarm_cli/ui/components/usage_stats.rb', line 8 def initialize(pastel:) @pastel = pastel end |
Instance Method Details
#render(tokens:, cost:, context_pct: nil, remaining: nil, cumulative: nil) ⇒ Object
Render usage line with all available metrics 5,922 tokens │ $0.0016 │ 1.5% used, 394,078 remaining
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/swarm_cli/ui/components/usage_stats.rb', line 14 def render(tokens:, cost:, context_pct: nil, remaining: nil, cumulative: nil) parts = [] # Token count (always shown) parts << "#{Formatters::Number.format(tokens)} tokens" # Cost (always shown if > 0) parts << Formatters::Cost.format(cost, pastel: @pastel) if cost > 0 # Context tracking (if available) if context_pct colored_pct = color_context_percentage(context_pct) parts << if remaining "#{colored_pct} used, #{Formatters::Number.compact(remaining)} remaining" else "#{colored_pct} used" end elsif cumulative # Model doesn't have context limit, show cumulative parts << "#{Formatters::Number.compact(cumulative)} cumulative" end @pastel.dim(parts.join(" #{@pastel.dim("│")} ")) end |
#render_compact(tokens:, cost:, context_pct: nil) ⇒ Object
Render compact stats for prompt display 15.2K tokens • $0.045 • 3.8% context
42 43 44 45 46 47 48 49 50 |
# File 'lib/swarm_cli/ui/components/usage_stats.rb', line 42 def render_compact(tokens:, cost:, context_pct: nil) parts = [] parts << "#{Formatters::Number.compact(tokens)} tokens" if tokens > 0 parts << Formatters::Cost.format_plain(cost) if cost > 0 parts << "#{context_pct} context" if context_pct parts.join(" • ") end |