buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject svn commit: r643673 - /incubator/buildr/trunk/lib/buildr/core/progressbar.rb
Date Wed, 02 Apr 2008 01:13:53 GMT
Author: assaf
Date: Tue Apr  1 18:13:50 2008
New Revision: 643673

URL: http://svn.apache.org/viewvc?rev=643673&view=rev
Log:
BUILDR-57 fixed to work on JRuby

Modified:
    incubator/buildr/trunk/lib/buildr/core/progressbar.rb

Modified: incubator/buildr/trunk/lib/buildr/core/progressbar.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/progressbar.rb?rev=643673&r1=643672&r2=643673&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/progressbar.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/progressbar.rb Tue Apr  1 18:13:50 2008
@@ -22,15 +22,17 @@
       new(args).start &block
     end
 
+    def width
+      @width ||= $terminal.output_cols || 80
+    end
+
   end
 
   def initialize(args = {})
     @title = args[:title] || ''
     @total = args[:total] || 0
     @mark = args[:mark] || '.'
-    @format = args[:format] ||
-      @total == 0 ? ['%s %8s %s', :title, :count, :elapsed] : ['%s: %s |--| %8s/%s %s', :title,
:percentage, :count, :total, :time]
-    @width = $terminal.output_cols - 1
+    @format = args[:format] || default_format
     @output = args[:output] || $stderr unless args[:hidden] || !$stdout.isatty
     clear
   end
@@ -64,7 +66,7 @@
   end
 
   def title
-    @title.size > @width / 5 ? (@title[0, @width / 5 - 2] + '..') : @title 
+    @title.size > ProgressBar.width / 5 ? (@title[0, ProgressBar.width / 5 - 2] + '..')
: @title 
   end
 
   def count
@@ -125,7 +127,7 @@
 
   def clear
     return unless @output
-    @output.print "\r", " " * @width, "\r"
+    @output.print "\r", " " * (ProgressBar.width - 1), "\r"
     @output.flush
   end
     
@@ -133,7 +135,7 @@
     return unless @output
     format, *args = @format
     line = format % args.map { |arg| send(arg) }
-    @output.print line.sub('|--|') { progress(@width - line.size + 4) }
+    @output.print line.sub('|--|') { progress(ProgressBar.width - line.size + 3) }
     @output.print @finished ? "\n" : "\r"
     @output.flush
     @previous = @count
@@ -145,6 +147,10 @@
     return human(@count) != human(@previous) if @total == 0
     return true if (@count - @previous) >= @total / 100
     return Time.now - @last_time > 1
+  end
+
+  def default_format
+    @total == 0 ? ['%s %8s %s', :title, :count, :elapsed] : ['%s: %s |--| %8s/%s %s', :title,
:percentage, :count, :total, :time]
   end
 
 end



Mime
View raw message