From dd84c4c0c3a8bef9e4029dbe20b2393f2e3abfb7 Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 30 May 2011 03:42:36 +1200 Subject: [PATCH] added hist --show option + tests --- lib/pry/default_commands/input.rb | 8 ++++++++ test/test_default_commands.rb | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/pry/default_commands/input.rb b/lib/pry/default_commands/input.rb index 89ad3042..b4896cdf 100644 --- a/lib/pry/default_commands/input.rb +++ b/lib/pry/default_commands/input.rb @@ -62,6 +62,14 @@ class Pry end end + opt.on :s, :show, 'Show the history corresponding to the history line (or range of lines).', true, :as => Range do |range| + unless opt.grep? + start_line = range.is_a?(Range) ? range.first : range + lines = text.with_line_numbers Array(history[range]).join("\n"), start_line + stagger_output lines + end + end + opt.on :e, :exclude, 'Exclude pry commands from the history.' do unless opt.grep? history.map!.with_index do |element, index| diff --git a/test/test_default_commands.rb b/test/test_default_commands.rb index 5a32265a..7530b6f9 100644 --- a/test/test_default_commands.rb +++ b/test/test_default_commands.rb @@ -98,6 +98,23 @@ describe "Pry::Commands" do str_output.string.each_line.count.should == 4 str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/ end + + # strangeness in this test is due to bug in Readline::HISTORY not + # always registering first line of input + it 'should show lines between lines A and B with the --show switch' do + push_first_hist_line.call(@hist, "0") + ("a".."z").each do |v| + @hist.push v + end + + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), str_output) do + pry + end + + str_output.string.each_line.count.should == 4 + str_output.string.should =~ /b\n\d+:.*c\n\d+:.*d/ + end end describe "show-method" do