1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

hist now can replay range of history, refactored pry_instance.rb,

there is a tiny, obscure bug and 1 failing test that i'll fix soon
(not that impt).
This commit is contained in:
John Mair 2011-04-15 07:51:00 +12:00
parent 33d4cb26db
commit 2b5e3b396c
3 changed files with 35 additions and 13 deletions

View file

@ -27,14 +27,27 @@ class Pry
command ".<shell 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

View file

@ -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,11 +273,23 @@ class Pry
# as it has a second parameter.
input.readline(current_prompt, true)
else
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

View file

@ -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)