Class: RubynCode::CLI::InputHandler

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(command_registry: nil) ⇒ InputHandler

Returns a new instance of InputHandler.

Parameters:



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

Returns:

  • (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