diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 167b2e57..9aa8c6b4 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -137,7 +137,8 @@ class Pry end alias current_context current_binding # support previous API - # Push a binding for the given object onto the stack. + # Push a binding for the given object onto the stack. If this instance is + # currently stopped, mark it as usable again. def push_binding(object) @stopped = false binding_stack << Pry.binding_for(object) @@ -304,7 +305,7 @@ class Pry complete_expr = Pry::Code.complete_expression?(@eval_string) rescue SyntaxError => e output.puts "SyntaxError: #{e.message.sub(/.*syntax error, */m, '')}" - @eval_string = "" + reset_line end if complete_expr @@ -332,10 +333,20 @@ class Pry throw(:breakout) if current_binding.nil? end - # @deprecated - Please use Pry::REPL.start(:pry => pry, :target => target) instead. - def repl(target=binding_stack.last) - @@repl_warning ||= (warn "(deprecation) Pry#repl has been replaced by Pry::REPL.start(:pry => pry)"; true) - Pry::REPL.start(:pry => self, :target => target) + # @deprecated Use `Pry::REPL.new(pry, :target => target).start` instead. + def repl(target = nil) + @@repl_warning ||= (warn Pry::Helpers::CommandHelpers.unindent(<<-S); true) + DEPRECATION: Pry#repl is deprecated. Instead, use + + Pry::REPL.new(pry, :target => target).start + + where pry is the Pry instance you called #repl on and target is the + optional target parameter of #repl. + + Call stack: + #{caller.join("\n" + (' ' * 8))} + S + Pry::REPL.new(self, :target => target).start end def evaluate_ruby(code) @@ -551,7 +562,7 @@ class Pry Pry.critical_section do # If input buffer is empty then use normal prompt - if @eval_string.empty? + if eval_string.empty? generate_prompt(Array(prompt).first, c) # Otherwise use the wait prompt (indicating multi-line expression) diff --git a/lib/pry/repl.rb b/lib/pry/repl.rb index 402c20bb..3102eded 100644 --- a/lib/pry/repl.rb +++ b/lib/pry/repl.rb @@ -8,15 +8,16 @@ class Pry def_delegators :pry, :input, :output, :input_stack def self.start(options) - new(options).start + new(Pry.new(options)).start end - def initialize(options) - @pry = options[:pry] || Pry.new(options) - if options[:pry] && options[:target] + def initialize(pry, options = {}) + @pry = pry + @indent = Pry::Indent.new + + if options[:target] @pry.push_binding options[:target] end - @indent = Pry::Indent.new end def start diff --git a/spec/helpers/repl_tester.rb b/spec/helpers/repl_tester.rb index b8bef381..8c15afb4 100644 --- a/spec/helpers/repl_tester.rb +++ b/spec/helpers/repl_tester.rb @@ -23,7 +23,7 @@ class ReplTester def initialize @pry = Pry.new - @repl = Pry::REPL.new(:pry => @pry) + @repl = Pry::REPL.new(@pry) @fiber = Fiber.new do @repl.start diff --git a/spec/input_stack_spec.rb b/spec/input_stack_spec.rb index 196ec791..852f0dd4 100644 --- a/spec/input_stack_spec.rb +++ b/spec/input_stack_spec.rb @@ -30,9 +30,10 @@ describe "Pry#input_stack" do it 'input objects should be popped off stack as they are used up' do stack = [StringIO.new(":cloister\n"), StringIO.new(":baron\n")] - repl = Pry::REPL.new :input => StringIO.new(":alex\n"), - :output => @str_output, - :input_stack => stack + pry = Pry.new :input => StringIO.new(":alex\n"), + :output => @str_output, + :input_stack => stack + repl = Pry::REPL.new pry stack.size.should == 2 repl.send(:retrieve_line).should == ":alex\n" stack.size.should == 2 diff --git a/spec/pry_repl_spec.rb b/spec/pry_repl_spec.rb index c7837980..cd8f7c34 100644 --- a/spec/pry_repl_spec.rb +++ b/spec/pry_repl_spec.rb @@ -15,7 +15,7 @@ describe "The REPL" do it "shouldn't break if we start a nested session" do ReplTester.start do |t| - t.in 'Pry::REPL.start(:pry => _pry_, :target => 10)' + t.in 'Pry::REPL.new(_pry_, :target => 10).start' t.out '' t.prompt /10.*> $/