Class: Rubino::UI::PrinterBase

Inherits:
Base
  • Object
show all
Defined in:
lib/rubino/ui/printer_base.rb

Overview

Shared printing behaviour for terminal-based UI adapters.

Subclasses must implement #color_for(role) returning a Pastel method name (e.g. :cyan, :green) so that message formatting stays here while each adapter controls its own color scheme.

Direct Known Subclasses

CLI

Instance Method Summary collapse

Methods inherited from Base

#ask, #assistant_text, #blocking_human_input?, #body, #box_close, #box_open, #confirm, #confirm_destructive, #hint_row, #input_injected, #note, #panel_line, #queued, #replay_user_input, #select, #separator, #table, #thinking_started, #tool_body, #turn_interrupted

Constructor Details

#initializePrinterBase

Returns a new instance of PrinterBase.



13
14
15
# File 'lib/rubino/ui/printer_base.rb', line 13

def initialize
  @pastel = Pastel.new
end

Instance Method Details

#blank_lineObject



55
# File 'lib/rubino/ui/printer_base.rb', line 55

def blank_line = $stdout.puts

#compression_finished(metadata, at: nil) ⇒ Object



46
47
48
49
# File 'lib/rubino/ui/printer_base.rb', line 46

def compression_finished(, at: nil)
  saved = [:saved_tokens] || 0
  puts_colored(color_for(:muted), "  ⟳ Context compacted (saved #{saved} tokens)")
end

#compression_started(at: nil) ⇒ Object



42
43
44
# File 'lib/rubino/ui/printer_base.rb', line 42

def compression_started(at: nil)
  puts_colored(color_for(:muted), "  ⟳ Compacting context...")
end

#error(message) ⇒ Object



20
# File 'lib/rubino/ui/printer_base.rb', line 20

def error(message)   = puts_colored(color_for(:error),   "#{message}")

#info(message) ⇒ Object



17
# File 'lib/rubino/ui/printer_base.rb', line 17

def info(message)    = puts_colored(color_for(:info), message)

#job_enqueued(_type) ⇒ Object



51
# File 'lib/rubino/ui/printer_base.rb', line 51

def job_enqueued(_type) = nil

#job_finished(_type) ⇒ Object



53
# File 'lib/rubino/ui/printer_base.rb', line 53

def job_finished(_type) = nil

#job_started(_type) ⇒ Object



52
# File 'lib/rubino/ui/printer_base.rb', line 52

def job_started(_type)  = nil

#mode_changed(name, previous: nil) ⇒ Object

Default fallback. CLI overrides to render the ‘┄ HH:MM · mode → plan ┄` free-line variant.



59
60
61
62
# File 'lib/rubino/ui/printer_base.rb', line 59

def mode_changed(name, previous: nil)
  arrow = previous && previous != name ? " #{previous}#{name}" : " #{name}"
  puts_colored(color_for(:muted), "  ⟳ mode#{arrow}")
end

#status(message) ⇒ Object



21
# File 'lib/rubino/ui/printer_base.rb', line 21

def status(message)  = puts_colored(color_for(:status),  message)

#stream(chunk) ⇒ Object



23
24
25
26
27
# File 'lib/rubino/ui/printer_base.rb', line 23

def stream(chunk)
  text = chunk[:text].to_s
  $stdout.print text
  $stdout.flush
end

#stream_endObject



29
30
31
# File 'lib/rubino/ui/printer_base.rb', line 29

def stream_end
  $stdout.puts
end

#success(message) ⇒ Object



18
# File 'lib/rubino/ui/printer_base.rb', line 18

def success(message) = puts_colored(color_for(:success), "#{message}")

#tool_finished(name, result: nil) ⇒ Object



37
38
39
40
# File 'lib/rubino/ui/printer_base.rb', line 37

def tool_finished(name, result: nil)
  suffix = result ? " (#{result.truncated_preview})" : ""
  puts_colored(color_for(:tool), "#{name} done#{suffix}")
end

#tool_started(name, arguments: nil, at: nil) ⇒ Object



33
34
35
# File 'lib/rubino/ui/printer_base.rb', line 33

def tool_started(name, arguments: nil, at: nil)
  puts_colored(color_for(:tool), "  → Running tool: #{name}")
end

#warning(message) ⇒ Object



19
# File 'lib/rubino/ui/printer_base.rb', line 19

def warning(message) = puts_colored(color_for(:warning), "#{message}")