class Byebug::CommandProcessor - byebug-9.0.6 Documentation

# class Byebug::CommandProcessor

Processes commands in regular mode.

You can override this class to create your own command processor that, for example, whitelists only certain commands to be executed.

@see PostMortemProcessor for a example

### Attributes

context[R]
prev_line[RW]

### Public Class Methods

new(context) click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 21
    def initialize(context)
      @context = context

      @proceed = false
      @prev_line = nil
    end

### Public Instance Methods

at_breakpoint(brkpt) click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 65
    def at_breakpoint(brkpt)
      number = Byebug.breakpoints.index(brkpt) + 1

      puts "Stopped by breakpoint #{number} at #{frame.file}:#{frame.line}"
    end

at_catchpoint(exception) click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 71
    def at_catchpoint(exception)
      puts "Catchpoint at #{context.location}: `#{exception}'"
    end

at_end() click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 81
    def at_end
      process_commands
    end

at_line() click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 55
    def at_line
      process_commands
    end

at_return(return_value) click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 75
    def at_return(return_value)
      puts "Return value is: #{safe_inspect(return_value)}"

      process_commands
    end

at_tracing() click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 59
    def at_tracing
      puts "Tracing: #{context.full_location}"

      run_auto_cmds(2)
    end

command_list() click to toggle source

Available commands

    # File lib/byebug/processors/command_processor.rb, line 51
    def command_list
      @command_list ||= CommandList.new(commands)
    end

interface() click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 28
    def interface
      @interface ||= Context.interface
    end

printer() click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 32
    def printer
      @printer ||= Printers::Plain.new
    end

proceed!() click to toggle source

Let the execution continue

    # File lib/byebug/processors/command_processor.rb, line 88
    def proceed!
      @proceed = true
    end

process_commands() click to toggle source

Handle byebug commands.

    # File lib/byebug/processors/command_processor.rb, line 95
    def process_commands
      before_repl

      repl
    ensure
      after_repl
    end

### Protected Instance Methods

after_repl() click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 120
    def after_repl
      interface.autosave
    end

before_repl() click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 112
    def before_repl
      @proceed = false
      @prev_line = nil

      run_auto_cmds(1)
      interface.autorestore
    end

prompt() click to toggle source

Prompt shown before reading a command.

    # File lib/byebug/processors/command_processor.rb, line 108
    def prompt
      '(byebug) '
    end

repl() click to toggle source

Main byebug's REPL

    # File lib/byebug/processors/command_processor.rb, line 127
    def repl
      until @proceed
        cmd = interface.read_command(prompt)
        return if cmd.nil?

        next if cmd == ''

        run_cmd(cmd)
      end
    end

### Private Instance Methods

auto_cmds_for(run_level) click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 140
    def auto_cmds_for(run_level)
      command_list.select { |cmd| cmd.always_run >= run_level }
    end

run_auto_cmds(run_level) click to toggle source

Run permanent commands.

    # File lib/byebug/processors/command_processor.rb, line 147
    def run_auto_cmds(run_level)
      safely do
        auto_cmds_for(run_level).each { |cmd| cmd.new(self).execute }
      end
    end

run_cmd(input) click to toggle source

Executes the received input

Instantiates a command matching the input and runs it. If a matching command is not found, it evaluates the unknown input.

    # File lib/byebug/processors/command_processor.rb, line 159
    def run_cmd(input)
      safely do
        command = command_list.match(input)
        return command.new(self, input).execute if command

        puts safe_inspect(multiple_thread_eval(input))
      end
    end

safely() { || ... } click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 168
    def safely
      yield
    rescue => e
      errmsg(e.message)
    end