diff options
author | Conrad Irwin <conrad.irwin@gmail.com> | 2012-11-07 23:58:18 -0800 |
---|---|---|
committer | Conrad Irwin <conrad.irwin@gmail.com> | 2012-11-08 00:02:25 -0800 |
commit | 5246700e2b074229c811cd0216c574bc8a46970e (patch) | |
tree | 12fafbfd6c15416ba69f4aa254548a968ea6d386 | |
parent | c0a33a0829f34b51afa4161afb9ce59989c3e87f (diff) | |
download | pry-5246700e2b074229c811cd0216c574bc8a46970e.tar.gz |
Move hashrocket out of Pry.config.print
This simplifies the contract of Pry.config.print which makes it easier to use
in other places that we want to output a value, like ls -l.
If desired you can stil remove the => by setting Pry.config.output_prefix = ''
in your ~/.pryrc
-rw-r--r-- | lib/pry.rb | 9 | ||||
-rw-r--r-- | lib/pry/commands/ls.rb | 10 | ||||
-rw-r--r-- | lib/pry/pry_class.rb | 1 | ||||
-rw-r--r-- | lib/pry/pry_instance.rb | 1 | ||||
-rw-r--r-- | test/test_pry_defaults.rb | 8 | ||||
-rw-r--r-- | test/test_pry_output.rb | 8 |
6 files changed, 17 insertions, 20 deletions
@@ -40,8 +40,7 @@ class Pry # avoid colour-leak from CodeRay and any of the users' previous output colorized = colorized.sub(/(\n*)\z/, "\e[0m\\1") if Pry.color - prefix = if false != options[:hashrocket] then '=> ' else '' end - result = prefix + colorized.gsub(/%<(.*?)#{nonce}/, '#<\1') + result = colorized.gsub(/%<(.*?)#{nonce}/, '#<\1') Helpers::BaseHelpers.stagger_output(result, output) end @@ -49,15 +48,15 @@ class Pry # pretty_print is too slow SIMPLE_PRINT = proc do |output, value| begin - output.puts "=> #{value.inspect}" + output.puts value.inspect rescue RescuableException - output.puts "=> unknown" + output.puts "unknown" end end # useful when playing with truly enormous objects CLIPPED_PRINT = proc do |output, value| - output.puts "=> #{Pry.view_clip(value)}" + output.puts Pry.view_clip(value) end # Will only show the first line of the backtrace diff --git a/lib/pry/commands/ls.rb b/lib/pry/commands/ls.rb index 2800d4f0..2d87017d 100644 --- a/lib/pry/commands/ls.rb +++ b/lib/pry/commands/ls.rb @@ -268,7 +268,7 @@ class Pry name_value_pairs.sort_by do |name, value| value.to_s.size end.reverse.map do |name, value| - colorized_assignment_style(name, format_value_without_hashrocket(value)) + colorized_assignment_style(name, format_value(value)) end end @@ -279,13 +279,9 @@ class Pry "%-#{pad}s = %s" % [color(:local_var, colorized_lhs), rhs] end - def format_value_without_hashrocket(value) + def format_value(value) accumulator = StringIO.new - if Pry::DEFAULT_PRINT.source_location == Pry.print.source_location - Pry.output_with_default_format(accumulator, value, :hashrocket => false) - else - Pry.print.call(accumulator, value) - end + Pry.print.call(accumulator, value) accumulator.string end diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index c1a4b7f0..2d2be5a2 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -272,6 +272,7 @@ class Pry config.auto_indent = Helpers::BaseHelpers.use_ansi_codes? config.correct_indent = true config.collision_warning = false + config.output_prefix = "=> " if defined?(Bond) && Readline::VERSION !~ /editline/i config.completer = Pry::BondCompleter diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 4dd33eee..9bc81f29 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -334,6 +334,7 @@ class Pry 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' diff --git a/test/test_pry_defaults.rb b/test/test_pry_defaults.rb index 503f65be..e79706fa 100644 --- a/test/test_pry_defaults.rb +++ b/test/test_pry_defaults.rb @@ -92,22 +92,22 @@ describe "test Pry defaults" do end it "should set the print default, and the default should be overridable" do - new_print = proc { |out, value| out.puts value } + new_print = proc { |out, value| out.puts "LOL" } Pry.print = new_print Pry.new.print.should == Pry.print Pry.new(:input => InputTester.new("\"test\""), :output => @str_output).rep - @str_output.string.should == "test\n" + @str_output.string.should == "=> LOL\n" @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 Pry.new(:input => InputTester.new("\"test\""), :output => @str_output).rep - @str_output.string.should == "test\n" + @str_output.string.should == "=> LOL\n" end describe "pry return values" do diff --git a/test/test_pry_output.rb b/test/test_pry_output.rb index 181ebc8d..f672352c 100644 --- a/test/test_pry_output.rb +++ b/test/test_pry_output.rb @@ -34,10 +34,10 @@ describe Pry do mock_pry("{:a => 1}").should =~ /^=> \{:a=>1\}/ end - it 'should have a milder-mannered companion without the hashrocket' do - s = StringIO.new - Pry.output_with_default_format s, '2', :hashrocket => false - s.string.should.not =~ /^=>/ + it "should not include the =>" do + accumulator = StringIO.new + Pry.config.print.call(accumulator, :a => 1) + accumulator.string.should == "{:a=>1}\n" end it "should not be phased by un-inspectable things" do |