lib/progress_bar.rb in progress_bar-1.0.4 vs lib/progress_bar.rb in progress_bar-1.0.5
- old
+ new
@@ -96,13 +96,15 @@
send(:"#{meter}_width")
end
def render_bar
return '' if bar_width < 2
+ progress_width = (ratio * (bar_width - 2)).floor
+ remainder_width = bar_width - 2 - progress_width
"[" +
- "#" * (ratio * (bar_width - 2)).ceil +
- " " * ((1-ratio) * (bar_width - 2)).floor +
+ "#" * progress_width +
+ " " * remainder_width +
"]"
end
def render_counter
"[%#{max_width}i/%i]" % [count, max]
@@ -125,10 +127,10 @@
"[%#{max_width+3}.2f/s]" % rate
end
def terminal_width
# HighLine check takes a long time, so only update width every second.
- if @terminal_width.nil? || @last_width_adjustment.nil? ||
+ if @terminal_width.nil? || @last_width_adjustment.nil? ||
::Time.now - @last_width_adjustment > 1
@last_width_adjustment = ::Time.now
@terminal_width = @hl.output_cols.to_i
if @terminal_width < 1