Class: RubynCode::CLI::InputHandler
- Inherits:
-
Object
- Object
- RubynCode::CLI::InputHandler
- Defined in:
- lib/rubyn_code/cli/input_handler.rb
Defined Under Namespace
Classes: Command
Constant Summary collapse
- SLASH_COMMANDS =
Legacy mapping for backward compatibility when no registry is provided. New code should use the command registry instead.
{ '/quit' => :quit, '/exit' => :quit, '/q' => :quit }.freeze
Instance Method Summary collapse
-
#initialize(command_registry: nil) ⇒ InputHandler
constructor
A new instance of InputHandler.
- #multiline?(line) ⇒ Boolean
- #parse(input) ⇒ Object
- #strip_continuation(line) ⇒ Object
Constructor Details
#initialize(command_registry: nil) ⇒ InputHandler
Returns a new instance of InputHandler.
17 18 19 |
# File 'lib/rubyn_code/cli/input_handler.rb', line 17 def initialize(command_registry: nil) @command_registry = command_registry end |
Instance Method Details
#multiline?(line) ⇒ Boolean
34 35 36 |
# File 'lib/rubyn_code/cli/input_handler.rb', line 34 def multiline?(line) line&.end_with?('\\') end |
#parse(input) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubyn_code/cli/input_handler.rb', line 21 def parse(input) return Command.new(action: :quit, args: []) if input.nil? stripped = input.strip return Command.new(action: :empty, args: []) if stripped.empty? if stripped.start_with?('/') parse_slash_command(stripped) else Command.new(action: :message, args: [process_file_references(stripped)]) end end |
#strip_continuation(line) ⇒ Object
38 39 40 |
# File 'lib/rubyn_code/cli/input_handler.rb', line 38 def strip_continuation(line) line.chomp('\\') end |