lib/progressbar.rb in progressbar-0.9.0 vs lib/progressbar.rb in progressbar-0.9.1
- old
+ new
@@ -31,16 +31,17 @@
end
attr_reader :title
attr_reader :current
attr_reader :total
attr_accessor :start_time
+ attr_writer :bar_mark
private
def fmt_bar
bar_width = do_percentage * @terminal_width / 100
- sprintf("|%s%s|",
- @bar_mark * bar_width,
+ sprintf("|%s%s|",
+ @bar_mark * bar_width,
" " * (@terminal_width - bar_width))
end
def fmt_percentage
do_percentage
@@ -49,13 +50,13 @@
def fmt_stat
if @finished_p then elapsed else eta end
end
def fmt_stat_for_file_transfer
- if @finished_p then
+ if @finished_p then
sprintf("%s %s %s", bytes, transfer_rate, elapsed)
- else
+ else
sprintf("%s %s %s", bytes, transfer_rate, eta)
end
end
def fmt_title
@@ -104,11 +105,11 @@
def elapsed
elapsed = Time.now - @start_time
sprintf("Time: %s", format_time(elapsed))
end
-
+
def eol
if @finished_p then "\n" else "\r" end
end
def do_percentage
@@ -135,18 +136,18 @@
default_width
end
end
def show
- arguments = @format_arguments.map {|method|
+ arguments = @format_arguments.map {|method|
method = sprintf("fmt_%s", method)
send(method)
}
line = sprintf(@format, *arguments)
width = get_width
- if line.length == width - 1
+ if line.length == width - 1
@out.print(line + eol)
@out.flush
elsif line.length >= width
@terminal_width = [@terminal_width - (line.length - width + 1), 0].max
if @terminal_width == 0 then @out.print(line + eol) else show end
@@ -165,11 +166,11 @@
cur_percentage = (@current * 100 / @total).to_i
prev_percentage = (@previous * 100 / @total).to_i
end
# Use "!=" instead of ">" to support negative changes
- if cur_percentage != prev_percentage ||
+ if cur_percentage != prev_percentage ||
Time.now - @previous_time >= 1 || @finished_p
show
end
end
@@ -231,6 +232,5 @@
class ReversedProgressBar < ProgressBar
def do_percentage
100 - super
end
end
-