class ProgressBar

Ruby/ProgressBar - a text progress bar library

Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>

All rights reserved.
This is free software with ABSOLUTELY NO WARRANTY.

You can redistribute it and/or modify it under the terms of Ruby’s license.

Constants

DEFAULT_WIDTH
VERSION

Attributes

bar_mark[W]
current[R]
start_time[RW]
title[R]
total[R]

Public Class Methods

new(title, total, out = STDERR) click to toggle source
# File lib/progressbar.rb, line 15
def initialize (title, total, out = STDERR)
  @title = title
  @total = total
  @out = out
  @terminal_width = 80
  @bar_mark = "o"
  @current = 0
  @previous = 0
  @finished_p = false
  @start_time = Time.now
  @previous_time = @start_time
  @title_width = 14
  @format = "%-#{@title_width}s %3d%% %s %s"
  @format_arguments = [:title, :percentage, :bar, :stat]
  clear
  show
end

Public Instance Methods

clear() click to toggle source
# File lib/progressbar.rb, line 215
def clear
  @out.print "\r"
  @out.print(" " * (get_term_width - 1))
  @out.print "\r"
end
file_transfer_mode() click to toggle source
# File lib/progressbar.rb, line 231
def file_transfer_mode
  @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
end
finish() click to toggle source
# File lib/progressbar.rb, line 221
def finish
  @current = @total
  @finished_p = true
  show
end
finished?() click to toggle source
# File lib/progressbar.rb, line 227
def finished?
  @finished_p
end
format=(format) click to toggle source
# File lib/progressbar.rb, line 239
def format= (format)
  @format = format
end
format_arguments=(arguments) click to toggle source
# File lib/progressbar.rb, line 243
def format_arguments= (arguments)
  @format_arguments = arguments
end
halt() click to toggle source
# File lib/progressbar.rb, line 247
def halt
  @finished_p = true
  show
end
inc(step = 1) click to toggle source
# File lib/progressbar.rb, line 252
def inc (step = 1)
  @current += step
  @current = @total if @current > @total
  show_if_needed
  @previous = @current
end
inspect() click to toggle source
# File lib/progressbar.rb, line 268
def inspect
  "#<ProgressBar:#{@current}/#{@total}>"
end
long_running() click to toggle source
# File lib/progressbar.rb, line 235
def long_running
  @format_arguments = [:title, :percentage, :bar, :stat_for_long_run]
end
set(count) click to toggle source
# File lib/progressbar.rb, line 259
def set (count)
  if count < 0 || count > @total
    raise "invalid count: #{count} (total: #{@total})"
  end
  @current = count
  show_if_needed
  @previous = @current
end