Class: Byebug::ControlCommandProcessor

Inherits:
Processor
  • Object
show all
Defined in:
lib/byebug/processors/control_command_processor.rb

Overview

Processes commands in ‘control’ mode, when there’s no program running

Instance Attribute Summary collapse

Attributes inherited from Processor

#interface

Instance Method Summary collapse

Methods inherited from Processor

load_commands, load_settings, #without_exceptions

Constructor Details

#initialize(interface = LocalInterface.new) ⇒ ControlCommandProcessor

Returns a new instance of ControlCommandProcessor.



10
11
12
# File 'lib/byebug/processors/control_command_processor.rb', line 10

def initialize(interface = LocalInterface.new)
  super(interface)
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



8
9
10
# File 'lib/byebug/processors/control_command_processor.rb', line 8

def state
  @state
end

Instance Method Details

#commandsObject



14
15
16
# File 'lib/byebug/processors/control_command_processor.rb', line 14

def commands
  Command.commands.select(&:allow_in_control).map { |cmd| cmd.new(state) }
end

#process_commandsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/byebug/processors/control_command_processor.rb', line 18

def process_commands
  @state = ControlState.new(interface)

  while (input = @interface.read_command(prompt(nil)))
    cmd = commands.find { |c| c.match(input) }
    unless cmd
      errmsg('Unknown command')
      next
    end

    cmd.execute
  end

  @interface.close
rescue IOError, SystemCallError
  @interface.close
rescue
  without_exceptions do
    puts "INTERNAL ERROR!!! #{$ERROR_INFO}"
    puts $ERROR_INFO.backtrace.map { |l| "\t#{l}" }.join("\n")
  end
end

#prompt(_context) ⇒ Object

Prompt shown before reading a command.



44
45
46
# File 'lib/byebug/processors/control_command_processor.rb', line 44

def prompt(_context)
  '(byebug:ctrl) '
end