Class: Crimson::Repl
- Inherits:
-
Object
- Object
- Crimson::Repl
- Defined in:
- lib/crimson/repl.rb
Overview
Interactive REPL with readline support, slash commands, and session management.
Instance Method Summary collapse
-
#initialize(agent) ⇒ Repl
constructor
A new instance of Repl.
-
#start ⇒ void
Start the REPL event loop.
Constructor Details
#initialize(agent) ⇒ Repl
Returns a new instance of Repl.
10 11 12 13 14 15 16 |
# File 'lib/crimson/repl.rb', line 10 def initialize(agent) @agent = agent @pastel = Pastel.new @output_handler = OutputHandler.new @output_handler.attach(agent) setup_readline end |
Instance Method Details
#start ⇒ void
This method returns an undefined value.
Start the REPL event loop.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/crimson/repl.rb', line 20 def start puts @pastel.bold("Crimson v#{VERSION}") puts @pastel.dim("Type /help for commands, /exit to quit") puts loop do input = Reline.readline("> ", true) break if input.nil? input = input.strip break if input == "/exit" || input == "/quit" next if input.empty? if input.start_with?("/") handle_command(input) else @agent.prompt(input) end rescue => e puts @pastel.red("Error: #{e.}") end puts @pastel.dim("Goodbye!") end |