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:
parent
33d4cb26db
commit
2b5e3b396c
3 changed files with 35 additions and 13 deletions
|
@ -27,14 +27,27 @@ class Pry
|
||||||
command ".<shell command>", "All text following a '.' is forwarded to the shell." do
|
command ".<shell command>", "All text following a '.' is forwarded to the shell." do
|
||||||
end
|
end
|
||||||
|
|
||||||
command "hist", "Show Readline history" do |start_line, end_line|
|
command "hist", "Show and replay Readline history" do |*args|
|
||||||
if !start_line
|
require 'slop'
|
||||||
|
if args.empty?
|
||||||
text = add_line_numbers(Readline::HISTORY.to_a.join("\n"), 0)
|
text = add_line_numbers(Readline::HISTORY.to_a.join("\n"), 0)
|
||||||
stagger_output(text)
|
stagger_output(text)
|
||||||
next
|
next
|
||||||
end
|
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)
|
Pry.active_instance.input = StringIO.new(actions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -193,10 +193,7 @@ class Pry
|
||||||
loop do
|
loop do
|
||||||
val = retrieve_line(eval_string, target)
|
val = retrieve_line(eval_string, target)
|
||||||
process_line(val, eval_string, target)
|
process_line(val, eval_string, target)
|
||||||
if valid_expression?(eval_string)
|
break if valid_expression?(eval_string) && !null_input?(val)
|
||||||
redo if null_input?(val)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@suppress_output = true if eval_string =~ /;\Z/
|
@suppress_output = true if eval_string =~ /;\Z/
|
||||||
|
@ -276,10 +273,22 @@ class Pry
|
||||||
# as it has a second parameter.
|
# as it has a second parameter.
|
||||||
input.readline(current_prompt, true)
|
input.readline(current_prompt, true)
|
||||||
else
|
else
|
||||||
if input.method(:readline).arity == 1
|
begin
|
||||||
input.readline(current_prompt)
|
if input.method(:readline).arity == 1
|
||||||
else
|
input.readline(current_prompt)
|
||||||
input.readline
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -380,7 +380,7 @@ describe Pry do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
str_output = StringIO.new
|
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/
|
str_output.string.should =~ /:kept_hello/
|
||||||
|
|
||||||
Object.remove_const(:Command68)
|
Object.remove_const(:Command68)
|
||||||
|
@ -393,7 +393,7 @@ describe Pry do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
str_output = StringIO.new
|
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
|
(str_output.string =~ /:kept_hello/).should == nil
|
||||||
|
|
||||||
Object.remove_const(:Command68)
|
Object.remove_const(:Command68)
|
||||||
|
|
Loading…
Reference in a new issue