mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Merge remote-tracking branch 'golive/master'
Conflicts: lib/pry/default_commands/input.rb
This commit is contained in:
commit
10b223855e
3 changed files with 59 additions and 6 deletions
|
@ -173,6 +173,23 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
# Take `num_lines` from `start_line`, forward or backwards
|
||||
#
|
||||
# @param [Fixnum] start_line
|
||||
# @param [Fixnum] num_lines
|
||||
# @return [Code]
|
||||
def take_lines(start_line, num_lines)
|
||||
if start_line >= 0
|
||||
start_idx = @lines.index { |l| l.last >= start_line } || @lines.length
|
||||
else
|
||||
start_idx = @lines.length + start_line
|
||||
end
|
||||
|
||||
alter do
|
||||
@lines = @lines.slice(start_idx, num_lines)
|
||||
end
|
||||
end
|
||||
|
||||
# Remove all lines except for the `lines` up to and excluding `line_num`.
|
||||
#
|
||||
# @param [Fixnum] line_num
|
||||
|
|
|
@ -32,21 +32,25 @@ class Pry
|
|||
def process
|
||||
@history = Pry::Code(Pry.history.to_a)
|
||||
|
||||
if opts.present?(:show)
|
||||
@history = @history.between(opts[:show])
|
||||
end
|
||||
|
||||
if opts.present?(:grep)
|
||||
@history = @history.grep(opts[:grep])
|
||||
end
|
||||
|
||||
@history = case
|
||||
when opts.present?(:head)
|
||||
@history.between(1, opts[:head] || 10)
|
||||
@history.take_lines(1, opts[:head] || 10)
|
||||
when opts.present?(:tail)
|
||||
@history.between(-(opts[:tail] || 10), -1)
|
||||
@history.take_lines(-(opts[:tail] || 10), opts[:tail] || 10)
|
||||
when opts.present?(:show)
|
||||
@history.between(opts[:show])
|
||||
else
|
||||
@history
|
||||
end
|
||||
|
||||
if opts.present?(:grep)
|
||||
@history = @history.grep(opts[:grep])
|
||||
end
|
||||
|
||||
if opts.present?(:'exclude-pry')
|
||||
@history = @history.select { |l, ln| !command_set.valid_command?(l) }
|
||||
end
|
||||
|
|
|
@ -347,6 +347,38 @@ describe "Pry::DefaultCommands::Input" do
|
|||
str_output.string.should =~ /x\n\d+:.*y\n\d+:.*z/
|
||||
end
|
||||
|
||||
it 'should apply --tail after --grep' do
|
||||
@hist.push "print 1"
|
||||
@hist.push "print 2"
|
||||
@hist.push "puts 3"
|
||||
@hist.push "print 4"
|
||||
@hist.push "puts 5"
|
||||
|
||||
str_output = StringIO.new
|
||||
redirect_pry_io(InputTester.new("hist --tail 2 --grep print", "exit-all"), str_output) do
|
||||
pry
|
||||
end
|
||||
|
||||
str_output.string.each_line.count.should == 2
|
||||
str_output.string.should =~ /\d:.*?print 2\n\d:.*?print 4/
|
||||
end
|
||||
|
||||
it 'should apply --head after --grep' do
|
||||
@hist.push "puts 1"
|
||||
@hist.push "print 2"
|
||||
@hist.push "puts 3"
|
||||
@hist.push "print 4"
|
||||
@hist.push "print 5"
|
||||
|
||||
str_output = StringIO.new
|
||||
redirect_pry_io(InputTester.new("hist --head 2 --grep print", "exit-all"), str_output) do
|
||||
pry
|
||||
end
|
||||
|
||||
str_output.string.each_line.count.should == 2
|
||||
str_output.string.should =~ /\d:.*?print 2\n\d:.*?print 4/
|
||||
end
|
||||
|
||||
# strangeness in this test is due to bug in Readline::HISTORY not
|
||||
# always registering first line of input
|
||||
it 'should return first N lines in history with --head switch' do
|
||||
|
|
Loading…
Reference in a new issue