Class: ANSI::ProgressBar

### Home Classes Methods

### In Files

- lib/ansi/progressbar.rb

### Parent

Object

### Methods

- ::new
- #bar_mark=
- #barmark=
- #clear
- #file_transfer_mode
- #finish
- #flush
- #halt
- #inc
- #inspect
- #mark=
- #reset
- #set
- #standard_mode
- #style
- #title=
- #total_overflow=
- #transfer_mode

### Files

- COPYING.rdoc
- DEMO.rdoc
- HISTORY.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- ANSI
- ANSI::BBCode
- ANSI::Chain
- ANSI::Code
- ANSI::Columns
- ANSI::Constants
- ANSI::Diff
- ANSI::HexDump
- ANSI::Logger
- ANSI::Mixin
- ANSI::ProgressBar
- ANSI::String
- ANSI::Table
- ANSI::Terminal
- Object
- String

No matching classes.

# ANSI::ProgressBar

# Progressbar

Progressbar is a text-based progressbar library.

    pbar = Progressbar.new( "Demo", 100 )
    100.times { pbar.inc }
    pbar.finish

### Attributes

format[RW]
format_arguments[RW]
styles[RW]

### Public Class Methods

new(title, total, out=STDERR) click to toggle source

    # 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

### Public Instance Methods

bar_mark=(mark) click to toggle source

    # File lib/ansi/progressbar.rb, line 54
    def bar_mark=(mark)
      @bar_mark = String(mark)[0..0]
    end

Also aliased as: barmark=, mark=
barmark=(mark) click to toggle source
Alias for: bar_mark=
clear() click to toggle source

    # File lib/ansi/progressbar.rb, line 138
    def clear
      @out.print(" " * get_width + eol)
    end

file_transfer_mode() click to toggle source

For backward compatability

Alias for: transfer_mode
finish() click to toggle source

    # File lib/ansi/progressbar.rb, line 93
    def finish
      @current = @total
      @is_finished = true
      show_progress
    end

flush() click to toggle source

    # File lib/ansi/progressbar.rb, line 99
    def flush
      @out.flush
    end

halt() click to toggle source

    # File lib/ansi/progressbar.rb, line 103
    def halt
      @is_finished = true
      show_progress
    end

inc(step = 1) click to toggle source

    # File lib/ansi/progressbar.rb, line 130
    def inc(step = 1)
      @current += step
      @current = @total if @current > @total
      show_progress
      @previous = @current
    end

inspect() click to toggle source

    # File lib/ansi/progressbar.rb, line 142
    def inspect
      "(ProgressBar: #{@current}/#{@total})"
    end

mark=(mark) click to toggle source
Alias for: bar_mark=
reset() click to toggle source

    # File lib/ansi/progressbar.rb, line 124
    def reset
      @current = 0
      @is_finished = false
    end

set(count) click to toggle source

    # 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

standard_mode() click to toggle source

    # File lib/ansi/progressbar.rb, line 79
    def standard_mode
      @format = "%-14s %3d%% %s %s"
      @format_arguments = [:title, :percentage, :bar, :stat]
    end

style(options) click to toggle source

Set ANSI styling options.

    # File lib/ansi/progressbar.rb, line 74
    def style(options)
      @styles = options
    end

title=(str) click to toggle source

    # File lib/ansi/progressbar.rb, line 50
    def title=(str)
      @title = str
    end

total_overflow=(boolv) click to toggle source

    # File lib/ansi/progressbar.rb, line 60
    def total_overflow=(boolv)
      @total_overflow = boolv ? true : false
    end

transfer_mode() click to toggle source

    # 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

Also aliased as: file_transfer_mode

[Validate]

Generated with the Darkfish Rdoc Generator 2.