Class: RubynCode::CLI::Renderer
- Inherits:
-
Object
- Object
- RubynCode::CLI::Renderer
- 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
-
#yolo ⇒ Object
writeonly
Sets the attribute yolo.
Instance Method Summary collapse
- #agent_message(name, text) ⇒ Object
- #cost_summary(session_cost:, daily_cost:, tokens:) ⇒ Object
- #display(response) ⇒ Object
- #error(text) ⇒ Object
- #info(text) ⇒ Object
-
#initialize ⇒ Renderer
constructor
A new instance of Renderer.
- #prompt ⇒ Object
- #success(text) ⇒ Object
- #system_message(text) ⇒ Object
- #tool_call(name, params) ⇒ Object
- #tool_result(name, output) ⇒ Object
- #warning(text) ⇒ Object
- #welcome ⇒ Object
Constructor Details
#initialize ⇒ Renderer
Returns a new instance of Renderer.
9 10 11 12 |
# File 'lib/rubyn_code/cli/renderer.rb', line 9 def initialize @pastel = Pastel.new @rouge_formatter = Rouge::Formatters::Terminal256.new(theme: Rouge::Themes::Monokai.new) end |
Instance Attribute Details
#yolo=(value) ⇒ Object (writeonly)
Sets the attribute yolo
14 15 16 |
# File 'lib/rubyn_code/cli/renderer.rb', line 14 def yolo=(value) @yolo = value end |
Instance Method Details
#agent_message(name, text) ⇒ Object
56 57 58 |
# File 'lib/rubyn_code/cli/renderer.rb', line 56 def (name, text) puts @pastel.bold.magenta("[#{name}]") + " #{text}" end |
#cost_summary(session_cost:, daily_cost:, tokens:) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/rubyn_code/cli/renderer.rb', line 90 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rubyn_code/cli/renderer.rb', line 16 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
68 69 70 |
# File 'lib/rubyn_code/cli/renderer.rb', line 68 def error(text) puts @pastel.red(text) end |
#info(text) ⇒ Object
76 77 78 |
# File 'lib/rubyn_code/cli/renderer.rb', line 76 def info(text) puts @pastel.blue(text) end |
#prompt ⇒ Object
97 98 99 100 101 |
# File 'lib/rubyn_code/cli/renderer.rb', line 97 def prompt return @pastel.bold.green('rubyn ') + @pastel.bold.red('YOLO') + @pastel.bold.green(' > ') if @yolo @pastel.bold.green('rubyn > ') end |
#success(text) ⇒ Object
64 65 66 |
# File 'lib/rubyn_code/cli/renderer.rb', line 64 def success(text) puts @pastel.green(text) end |
#system_message(text) ⇒ Object
60 61 62 |
# File 'lib/rubyn_code/cli/renderer.rb', line 60 def (text) puts @pastel.dim.italic(text) end |
#tool_call(name, params) ⇒ Object
32 33 34 |
# File 'lib/rubyn_code/cli/renderer.rb', line 32 def tool_call(name, params) puts @pastel.cyan(" > #{name}: #{format_params(params)}") end |
#tool_result(name, output) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubyn_code/cli/renderer.rb', line 40 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
72 73 74 |
# File 'lib/rubyn_code/cli/renderer.rb', line 72 def warning(text) puts @pastel.yellow(text) end |
#welcome ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/rubyn_code/cli/renderer.rb', line 80 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 |