diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb index 3154a858..06063d97 100644 --- a/lib/pry/commands.rb +++ b/lib/pry/commands.rb @@ -27,14 +27,27 @@ class Pry command ".", "All text following a '.' is forwarded to the shell." do end - command "hist", "Show Readline history" do |start_line, end_line| - if !start_line + command "hist", "Show and replay Readline history" do |*args| + require 'slop' + if args.empty? text = add_line_numbers(Readline::HISTORY.to_a.join("\n"), 0) stagger_output(text) next end - actions = Readline::HISTORY.to_a[start_line.to_i..end_line.to_i].join("\n") + "\n_pry_.input=Readline\n" + opts = Slop.parse(args) do + banner "Usage: hist [-rSTART..END]" + on :r, :replay, 'The line (or range of lines) to replay.', true, :as => Range do |r| + options[:r].argument_value = r.to_i if r.is_a?(String) + end + on :h, :help, 'Show this message.', :tail => true do + output.puts help + end + end + + next if opts.h? + + actions = Array(Readline::HISTORY.to_a[opts[:r]]).join("\n") + "\n" Pry.active_instance.input = StringIO.new(actions) end diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index a41d2bb1..31381b1c 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -193,10 +193,7 @@ class Pry loop do val = retrieve_line(eval_string, target) process_line(val, eval_string, target) - if valid_expression?(eval_string) - redo if null_input?(val) - break - end + break if valid_expression?(eval_string) && !null_input?(val) end @suppress_output = true if eval_string =~ /;\Z/ @@ -276,10 +273,22 @@ class Pry # as it has a second parameter. input.readline(current_prompt, true) else - if input.method(:readline).arity == 1 - input.readline(current_prompt) - else - input.readline + begin + if input.method(:readline).arity == 1 + input.readline(current_prompt) + else + input.readline + end + rescue Exception => ex + self.input = Readline + "" + + # FIX ME!!! + # failing test is due to null_input?() being true for a + # command that doesn't return a value. This causes a EOFError + # exception for a 'rep' (as in test) as it makes the read loop + # redo and so it tries to read from a non-existent string + # binding.pry end end end diff --git a/test/test.rb b/test/test.rb index e1711607..187f8456 100644 --- a/test/test.rb +++ b/test/test.rb @@ -380,7 +380,7 @@ describe Pry do end end str_output = StringIO.new - Pry.new(:input => StringIO.new("hello"), :output => str_output, :commands => Command68).rep + Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => Command68).rep str_output.string.should =~ /:kept_hello/ Object.remove_const(:Command68) @@ -393,7 +393,7 @@ describe Pry do end end str_output = StringIO.new - Pry.new(:input => StringIO.new("hello"), :output => str_output, :commands => Command68).rep + Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => Command68).rep (str_output.string =~ /:kept_hello/).should == nil Object.remove_const(:Command68)