class PryByebug::Processor

def run(initial = true, &block)

Wrap a Pry REPL to catch navigational commands and act on them.
def run(initial = true, &block)
  return_value = nil
  command = catch(:breakout_nav) do  # Throws from PryByebug::Commands
    return_value = yield
    {}    # Nothing thrown == no navigational command
  end
  times = (command[:times] || 1).to_i   # Command argument
  times = 1 if times <= 0
  if [:step, :next, :finish].include? command[:action]
    @pry = command[:pry]   # Pry instance to resume after stepping
    Byebug.start unless Byebug.started?
    if initial
      # Movement when on the initial binding.pry line will have a frame
      # inside Byebug. If we step normally, it'll stop inside this
      # Processor. So jump out and stop at the above frame, then step/next
      # from our callback.
      @delayed[command[:action]] = times
      Byebug.current_context.step_out(2)
    elsif :next == command[:action]
      Byebug.current_context.step_over(times, 0)
    elsif :step == command[:action]
      Byebug.current_context.step_into(times)
    elsif :finish == command[:action]
      Byebug.current_context.step_out(0)
    end
  else
    stop
  end
  return_value
end