Fix pry.config.output_prefix to work. Fix #1128

This commit is contained in:
yui-knk 2014-02-05 22:29:25 +09:00
parent 21aa8959c8
commit 4e9df5b901
3 changed files with 19 additions and 6 deletions

View File

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

View File

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

View File

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