[Rubygems-developers] Pretty Listings for RubyGems
Gavin Sinclair
gsinclair at soyabean.com.au
Sun Mar 21 03:06:32 EST 2004
On Sunday, March 21, 2004, 2:34:21 AM, Gavin wrote:
>>> I certainly like that output better. What do you think?
>> Works for me.
> Thanks. The difference is: you have a patch; I don't! (I wish Ruby
> had a string-wrapping method implemented...)
> Anyway, I'll get on with it.
OK, here's the patch:
Index: bin/gem
===================================================================
RCS file: /var/cvs/rubygems/rubygems/bin/gem,v
retrieving revision 1.37
diff -u -r1.37 gem
--- bin/gem 20 Mar 2004 12:53:51 -0000 1.37
+++ bin/gem 20 Mar 2004 16:21:07 -0000
@@ -47,6 +47,36 @@
require 'rubygems'
+#
+# These implementations are not idiot-proof or intended for general use. They are to support
+# the pretty-printing of lists of gems.
+#
+class String # :nodoc:
+ # Wrap string to +n+ characters, inserting newlines and ensuring words are not broken.
+ # Stolen from 'ri'.
+ def wrap(n)
+ result = []
+ pattern = Regexp.new("^(.{0,#{n}})[ \n]")
+ work = self.dup
+ while work.length > n
+ if work =~ pattern
+ result << $1
+ work.slice!(0, $&.length)
+ else
+ result << work.slice!(0, n)
+ end
+ end
+ result << work if work.length.nonzero?
+ result.join("\n")
+ end
+
+ # Indent string by +n+ spaces.
+ def indent(n)
+ gsub(/^/, " " * n)
+ end
+end
+
+
def get_remote_installer(options)
Gem::RemoteInstaller.new(options[:http_proxy])
end
@@ -71,15 +101,23 @@
end
end
+# +gems+ is actually an Array: [name, gemspec, name, gemspec, ...]
def display_gems(gems)
gems.sort {|a,b|
a[0].downcase <=> b[0].downcase
}.each do |gem|
- puts "#{gem[0]} - #{gem[1].summary}"
- puts
+ puts
+ display_gem(gem)
end
end
+# +gem+ is actually an Array: [name, gemspec]
+def display_gem(gem)
+ name, spec = gem
+ puts name
+ puts spec.summary.wrap(68).indent(4)
+end
+
spec_file = options[:build]
install_file = options[:install]
gem_to_uninstall = options[:uninstall]
@@ -187,3 +225,4 @@
Gem::Validator.new.alien
end
More information about the Rubygems-developers
mailing list