Class: Byebug::ControlCommandProcessor

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

Defined Under Namespace

Classes: State

Instance Attribute Summary

Attributes inherited from Processor

#interface

Instance Method Summary collapse

Constructor Details

#initialize(interface) ⇒ ControlCommandProcessor

Returns a new instance of ControlCommandProcessor.



269
270
271
272
# File 'lib/byebug/processor.rb', line 269

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

Instance Method Details

#process_commands(verbose = false) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/byebug/processor.rb', line 274

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
    print "The program finished.\n"
    @context_was_dead = false
  end

  while input = @interface.read_command(prompt(nil))
    print "+#{input}" if verbose
    catch(:debug_error) do
      if cmd = commands.find{|c| c.match(input) }
        cmd.execute
      else
        errmsg "Unknown command\n"
      end
    end
  end
rescue IOError, Errno::EPIPE
rescue Exception
  print "INTERNAL ERROR!!! #{$!}\n" rescue nil
  print $!.backtrace.map{|l| "\t#{l}"}.join("\n") rescue nil
ensure
  @interface.close
end

#prompt(context) ⇒ Object

Prompt shown before reading a command.



307
308
309
# File 'lib/byebug/processor.rb', line 307

def prompt(context)
  return '(byebug:ctrl) '
end