Class: RubynCode::CLI::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/cli/renderer.rb

Constant Summary collapse

DIFF_TOOLS =
%w[edit_file write_file].freeze
DIFF_RESULT_LIMIT =
2000
DEFAULT_RESULT_LIMIT =
500
DIFF_COLORS =
{
  /\A  \+ / => :green,
  /\A  - / => :red,
  /\A  @@ / => :cyan,
  /\A(?:Created|Updated|Edited) / => :yellow
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRenderer

Returns a new instance of Renderer.



8
9
10
# File 'lib/rubyn_code/cli/renderer.rb', line 8

def initialize
  @pastel = Pastel.new
end

Instance Attribute Details

#yolo=(value) ⇒ Object (writeonly)

Sets the attribute yolo

Parameters:

  • value

    the value to set the attribute yolo to.



12
13
14
# File 'lib/rubyn_code/cli/renderer.rb', line 12

def yolo=(value)
  @yolo = value
end

Instance Method Details

#agent_message(name, text) ⇒ Object



54
55
56
# File 'lib/rubyn_code/cli/renderer.rb', line 54

def agent_message(name, text)
  puts @pastel.bold.magenta("[#{name}]") + " #{text}"
end

#cost_summary(session_cost:, daily_cost:, tokens:) ⇒ Object



88
89
90
91
92
93
# File 'lib/rubyn_code/cli/renderer.rb', line 88

def cost_summary(session_cost:, daily_cost:, tokens:)
  puts @pastel.bold('Cost Summary:')
  puts format('  Session: $%.4f', session_cost)
  puts format('  Today:   $%.4f', daily_cost)
  puts "  Tokens:  #{tokens[:input]} in / #{tokens[:output]} out"
end

#display(response) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubyn_code/cli/renderer.rb', line 14

def display(response)
  return if response.nil?

  text = case response
         when String then response
         when ->(r) { r.respond_to?(:text) } then response.text
         else response.to_s
         end

  return if text.nil? || text.strip.empty?

  puts
  puts render_markdown(text)
  puts
end

#error(text) ⇒ Object



66
67
68
# File 'lib/rubyn_code/cli/renderer.rb', line 66

def error(text)
  puts @pastel.red(text)
end

#info(text) ⇒ Object



74
75
76
# File 'lib/rubyn_code/cli/renderer.rb', line 74

def info(text)
  puts @pastel.blue(text)
end

#promptObject



95
96
97
98
99
# File 'lib/rubyn_code/cli/renderer.rb', line 95

def prompt
  return @pastel.bold.green('rubyn ') + @pastel.bold.red('YOLO') + @pastel.bold.green(' > ') if @yolo

  @pastel.bold.green('rubyn > ')
end

#success(text) ⇒ Object



62
63
64
# File 'lib/rubyn_code/cli/renderer.rb', line 62

def success(text)
  puts @pastel.green(text)
end

#system_message(text) ⇒ Object



58
59
60
# File 'lib/rubyn_code/cli/renderer.rb', line 58

def system_message(text)
  puts @pastel.dim.italic(text)
end

#tool_call(name, params) ⇒ Object



30
31
32
# File 'lib/rubyn_code/cli/renderer.rb', line 30

def tool_call(name, params)
  puts @pastel.cyan("  > #{name}: #{format_params(params)}")
end

#tool_result(name, output) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubyn_code/cli/renderer.rb', line 38

def tool_result(name, output)
  raw = output.to_s

  if DIFF_TOOLS.include?(name.to_s)
    render_diff_result(raw[0...DIFF_RESULT_LIMIT].lines)
  else
    truncated = raw[0...DEFAULT_RESULT_LIMIT]
    lines = truncated.lines
    if lines.length > 6
      render_truncated_result(lines)
    else
      puts @pastel.dim("    #{truncated.strip.gsub("\n", "\n    ")}")
    end
  end
end

#warning(text) ⇒ Object



70
71
72
# File 'lib/rubyn_code/cli/renderer.rb', line 70

def warning(text)
  puts @pastel.yellow(text)
end

#welcomeObject



78
79
80
81
82
83
84
85
86
# File 'lib/rubyn_code/cli/renderer.rb', line 78

def welcome
  puts @pastel.bold.cyan('╔══════════════════════════════════════╗')
  puts @pastel.bold.cyan("║         Rubyn Code v#{RubynCode::VERSION}")
  puts @pastel.bold.cyan('║  Ruby & Rails Agentic Assistant      ║')
  puts @pastel.bold.cyan('╚══════════════════════════════════════╝')
  puts
  puts @pastel.dim('Type /help for commands, /quit to exit')
  puts
end