diff --git a/lib/pry.rb b/lib/pry.rb index 10b1a675..f5cccff6 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -19,9 +19,9 @@ class Pry end # The default print - DEFAULT_PRINT = proc do |output, value| + DEFAULT_PRINT = proc do |output, value, _pry_| Pry::Pager.with_pager(output) do |pager| - pager.print "=> " + pager.print _pry_.config.output_prefix Pry::ColorPrinter.pp(value, pager, Pry::Terminal.width! - 1) end end diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 5db6a3fa..bd6abacc 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -347,7 +347,7 @@ class Pry if last_result_is_exception? exception_handler.call(output, result, self) elsif should_print? - print.call(output, result) + print.call(output, result, self) else # nothin' end diff --git a/spec/pry_output_spec.rb b/spec/pry_output_spec.rb index 5fe2d22f..c3707e45 100644 --- a/spec/pry_output_spec.rb +++ b/spec/pry_output_spec.rb @@ -35,8 +35,9 @@ describe Pry do end it "should include the =>" do + pry = Pry.new accumulator = StringIO.new - Pry.config.print.call(accumulator, [1]) + pry.config.print.call(accumulator, [1], pry) accumulator.string.should == "=> \[1\]\n" end @@ -49,6 +50,16 @@ describe Pry do end end + describe "output_prefix" do + it "should be able to change output_prefix" do + pry = Pry.new + accumulator = StringIO.new + pry.config.output_prefix = "-> " + pry.config.print.call(accumulator, [1], pry) + accumulator.string.should == "-> \[1\]\n" + end + end + describe "color" do before do Pry.color = true @@ -59,19 +70,21 @@ describe Pry do end it "should colorize strings as though they were ruby" do + pry = Pry.new accumulator = StringIO.new colorized = CodeRay.scan("[1]", :ruby).term - Pry.config.print.call(accumulator, [1]) + pry.config.print.call(accumulator, [1], pry) accumulator.string.should == "=> #{colorized}\n" end it "should not colorize strings that already include color" do + pry = Pry.new f = Object.new def f.inspect "\e[1;31mFoo\e[0m" end accumulator = StringIO.new - Pry.config.print.call(accumulator, f) + pry.config.print.call(accumulator, f, pry) # We add an extra \e[0m to prevent color leak accumulator.string.should == "=> \e[1;31mFoo\e[0m\e[0m\n" end