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

Defined Under Namespace

Classes: State

Instance Attribute Summary

Attributes inherited from Processor

#interface

Instance Method Summary collapse

Methods inherited from Processor

#without_exceptions

Constructor Details

#initialize(interface = LocalInterface.new) ⇒ ControlCommandProcessor

Returns a new instance of ControlCommandProcessor.



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

def initialize(interface = LocalInterface.new)
  super(interface)
  @context_was_dead = false # Assume we haven't started.
end

Instance Method Details

#process_commands(verbose = false) ⇒ Object



11
12
13
14
15
16
17
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 11

def process_commands(verbose = false)
  control_cmds = Command.commands.select do |cmd|
    cmd.allow_in_control
  end
  state = State.new(@interface, control_cmds)
  commands = control_cmds.map { |cmd| cmd.new(state) }

  if @context_was_dead
    puts 'The program finished.'
    @context_was_dead = false
  end

  while (input = @interface.read_command(prompt(nil)))
    puts("+#{input}") if verbose

    cmd = commands.find { |c| c.match(input) }
    return errmsg('Unknown command') unless cmd

    cmd.execute
  end
rescue IOError, SystemCallError
rescue
  without_exceptions do
    puts "INTERNAL ERROR!!! #{$ERROR_INFO}"
    puts $ERROR_INFO.backtrace.map { |l| "\t#{l}" }.join("\n")
  end
ensure
  @interface.close
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