Progressbar is a text-based progressbar library.
pbar = Progressbar.new( "Demo", 100 ) 100.times { pbar.inc } pbar.finish
# File lib/ansi/progressbar.rb, line 22 def initialize(title, total, out=STDERR) @title = title @total = total @out = out @bar_length = 80 @bar_mark = "|" @total_overflow = true @current = 0 @previous = 0 @is_finished = false @start_time = Time.now @format = "%-14s %3d%% %s %s" @format_arguments = [:title, :percentage, :bar, :stat] @styles = {} # yield self if block_given? # show_progress end
# File lib/ansi/progressbar.rb, line 54 def bar_mark=(mark) @bar_mark = String(mark)[0..0] end
# File lib/ansi/progressbar.rb, line 138 def clear @out.print(" " * get_width + eol) end
# File lib/ansi/progressbar.rb, line 93 def finish @current = @total @is_finished = true show_progress end
# File lib/ansi/progressbar.rb, line 103 def halt @is_finished = true show_progress end
# File lib/ansi/progressbar.rb, line 130 def inc(step = 1) @current += step @current = @total if @current > @total show_progress @previous = @current end
# File lib/ansi/progressbar.rb, line 142 def inspect "(ProgressBar: #{@current}/#{@total})" end
# File lib/ansi/progressbar.rb, line 124 def reset @current = 0 @is_finished = false end
# File lib/ansi/progressbar.rb, line 108 def set(count) if count < 0 raise "invalid count less than zero: #{count}" elsif count > @total if @total_overflow @total = count + 1 else raise "invalid count greater than total: #{count}" end end @current = count show_progress @previous = @current end
# File lib/ansi/progressbar.rb, line 79 def standard_mode @format = "%-14s %3d%% %s %s" @format_arguments = [:title, :percentage, :bar, :stat] end
Set ANSI styling options.
# File lib/ansi/progressbar.rb, line 74 def style(options) @styles = options end
# File lib/ansi/progressbar.rb, line 50 def title=(str) @title = str end
# File lib/ansi/progressbar.rb, line 60 def total_overflow=(boolv) @total_overflow = boolv ? true : false end
# File lib/ansi/progressbar.rb, line 85 def transfer_mode @format = "%-14s %3d%% %s %s" @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer] end
Generated with the Darkfish Rdoc Generator 2.