Skip to content

Commit

Permalink
more fixes for issue #245 (enormous inspect output lagging REPL)
Browse files Browse the repository at this point in the history
1. Pry.view_clip no longer uses #inspect, it defaults to #<> syntax (but using Module#name for modules), exception for 'main' object
2. Pry.run_command passes in a blank prompt and blank hooks

Also updated tests
  • Loading branch information
banister committed Sep 7, 2011
1 parent 740e2d0 commit deeb62a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
7 changes: 4 additions & 3 deletions lib/pry/pry_class.rb
Expand Up @@ -101,9 +101,10 @@ def self.start(target=TOPLEVEL_BINDING, options={})
# @param max_size The maximum number of chars before clipping occurs.
# @return [String] The string representation of `obj`.
def self.view_clip(obj, max_length = 60)
if obj.kind_of?(Module) && obj.name && obj.name != "" && obj.name.to_s.length <= max_length
if obj.kind_of?(Module) && obj.name.to_s != "" && obj.name.to_s.length <= max_length
obj.name.to_s
elsif obj.inspect.length <= max_length
elsif TOPLEVEL_BINDING.eval('self') == obj
# special case for 'main' object :)
obj.inspect
else
"#<#{obj.class}:%#x>" % (obj.object_id << 1)
Expand Down Expand Up @@ -160,7 +161,7 @@ def self.run_command(command_string, options={})

output = options[:show_output] ? options[:output] : StringIO.new

Pry.new(:output => output, :input => StringIO.new(command_string), :commands => options[:commands]).rep(options[:context])
Pry.new(:output => output, :input => StringIO.new(command_string), :commands => options[:commands], :prompt => proc {""}, :hooks => {}).rep(options[:context])
end

def self.default_editor_for_platform
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/version.rb
@@ -1,3 +1,3 @@
class Pry
VERSION = "0.9.4pre2"
VERSION = "0.9.4pre5"
end
17 changes: 12 additions & 5 deletions test/test_pry.rb
Expand Up @@ -1126,21 +1126,28 @@ def readline(*args)

VC_MAX_LENGTH = 60

describe "given an object with an #inspect string shorter than the maximum specified" do
it "returns the #inspect string" do
describe "given an object with an #inspect string" do
it "returns the #<> format of the object (never use inspect)" do
o = Object.new
def o.inspect; "a" * VC_MAX_LENGTH; end

Pry.view_clip(o, VC_MAX_LENGTH).should =~ /Object:0x.*?/
end
end

describe "given the 'main' object" do
it "returns the #inspect of main (special case)" do
o = TOPLEVEL_BINDING.eval('self')
Pry.view_clip(o, VC_MAX_LENGTH).should == o.inspect
end
end

describe "given an object with an #inspect string as long as the maximum specified" do
it "returns the #inspect string" do
it "returns the #<> format of the object (never use inspect)" do
o = Object.new
def o.inspect; "a" * VC_MAX_LENGTH; end

Pry.view_clip(o, VC_MAX_LENGTH).should == o.inspect
Pry.view_clip(o, VC_MAX_LENGTH).should =~ /Object:0x.*?/
end
end

Expand All @@ -1151,7 +1158,7 @@ def o.inspect; "a" * VC_MAX_LENGTH; end
o = Object.new
def o.inspect; "a" * (VC_MAX_LENGTH + 1); end

Pry.view_clip(o, VC_MAX_LENGTH).should =~ /Object:0x\d+?/
Pry.view_clip(o, VC_MAX_LENGTH).should =~ /Object:0x.*?/
end
end

Expand Down

0 comments on commit deeb62a

Please sign in to comment.