[Rake-devel] truncated task descriptions
Alex Chaffee
alexch at gmail.com
Sun Apr 6 15:14:39 EDT 2008
> I understand the rationale behind the truncation of task
> descriptions in 'rake -T' but I find the 80 column limit a little too
> condensed for my personal tastes. I whipped up a rake task that
> displays tasks and allows me to specify my column limit with an
> environment variable.
Wouldn't it be better to default to the width of the current window?
After looking at Reference [1] I believe that the easiest way to
figure this out is to check if you're on a unix system, and if so,
call "stty size" and parse the result. Here's some code that
demonstrates how.
I haven't made a test yet since I haven't quite figured out how to
mock out RUBY_PLATFORM or %x for a unit test... And I haven't tested
it on many platforms but the code is defensive enough that it should
gracefully and silently fail back to "80" on Windows etc.
References:
[1] http://codeidol.com/other/rubyckbk/User-Interface/Determining-Terminal-Size/
[2] http://www.tua.ch/ruby/platform/platform.html
[3] http://rubyforge.org/frs/download.php/7486/platform_0_4.rb
[4] http://geminstaller.rubyforge.org/svn/trunk/spec/fixture/rubygems_dist/rubygems-1.1.0/lib/rubygems/platform.rb
Code (a patch against 0.8.1):
Index: lib/rake.rb
===================================================================
--- lib/rake.rb (revision 639)
+++ lib/rake.rb (working copy)
@@ -2010,14 +2010,24 @@
end
else
width = displayable_tasks.collect { |t|
t.name_with_args.length }.max || 10
- max_column = 80 - name.size - width - 7
+ max_column = cols - name.size - width - 7
displayable_tasks.each do |t|
printf "#{name} %-#{width}s # %s\n",
t.name_with_args, truncate(t.comment, max_column)
end
end
end
+
+ def cols
+ unix? ? (%x{stty size 2>/dev/null}.split.collect { |x| x.to_i }[1]) : 80
+ rescue
+ 80
+ end
+ def unix?
+ RUBY_PLATFORM =~
/(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux|)/i
+ end
+
def truncate(string, width)
if string.length <= width
string
--
Alex Chaffee - Pivotal Labs
alex at PivotalLabs.com
More information about the Rake-devel
mailing list