Skip to content

Commit

Permalink
Remove output.write
Browse files Browse the repository at this point in the history
Many plugins only define a puts method on the output object. This change
removse the ability to customize the formatter used when outputting
variables in `ls`. We should reconsider the best way to do this.
  • Loading branch information
ConradIrwin committed Jan 14, 2013
1 parent 92a1b86 commit 1aacb10
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/pry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def self.output_with_default_format(output, value, options = {})
colorized = colorized.sub(/(\n*)\z/, "\e[0m\\1") if Pry.color

result = colorized.gsub(/%<(.*?)#{nonce}/, '#<\1')
result = "=> #{result}"if options[:hashrocket]
Helpers::BaseHelpers.stagger_output(result, output)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pry/commands/ls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def colorized_assignment_style(lhs, rhs, desired_width = 7)

def format_value(value)
accumulator = StringIO.new
Pry.print.call(accumulator, value)
Pry.output_with_default_format(accumulator, value, :hashrocket => false)
accumulator.string
end

Expand Down
1 change: 0 additions & 1 deletion lib/pry/pry_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ def show_result(result)
if last_result_is_exception?
exception_handler.call(output, result, self)
elsif should_print?
output.write(Pry.config.output_prefix)
print.call(output, result)
else
# nothin'
Expand Down
4 changes: 2 additions & 2 deletions spec/pry_defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def readline(*args)
end

it "should set the print default, and the default should be overridable" do
new_print = proc { |out, value| out.puts "LOL" }
new_print = proc { |out, value| out.puts "=> LOL" }
Pry.print = new_print

Pry.new.print.should == Pry.print
Expand All @@ -102,7 +102,7 @@ def readline(*args)
@str_output = StringIO.new
Pry.new(:input => InputTester.new("\"test\""), :output => @str_output,
:print => proc { |out, value| out.puts value.reverse }).rep
@str_output.string.should == "=> tset\n"
@str_output.string.should == "tset\n"

Pry.new.print.should == Pry.print
@str_output = StringIO.new
Expand Down
8 changes: 4 additions & 4 deletions spec/pry_output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
mock_pry("[1]").should =~ /^=> \[1\]/
end

it "should not include the =>" do
it "should include the =>" do
accumulator = StringIO.new
Pry.config.print.call(accumulator, [1])
accumulator.string.should == "\[1\]\n"
accumulator.string.should == "=> \[1\]\n"
end

it "should not be phased by un-inspectable things" do
Expand All @@ -57,7 +57,7 @@
it "should colorize strings as though they were ruby" do
accumulator = StringIO.new
Pry.config.print.call(accumulator, [1])
accumulator.string.should == "[\e[1;34m1\e[0m]\e[0m\n"
accumulator.string.should == "=> [\e[1;34m1\e[0m]\e[0m\n"
end

it "should not colorize strings that already include color" do
Expand All @@ -68,7 +68,7 @@ def f.inspect
accumulator = StringIO.new
Pry.config.print.call(accumulator, f)
# We add an extra \e[0m to prevent color leak
accumulator.string.should == "\e[1;31mFoo\e[0m\e[0m\n"
accumulator.string.should == "=> \e[1;31mFoo\e[0m\e[0m\n"
end
end

Expand Down

0 comments on commit 1aacb10

Please sign in to comment.