class ProgressBar::Console

Attributes

errfd[R]
outfd[R]

Public Class Methods

new(*a, outfd: nil, errfd: nil, **options) click to toggle source
Calls superclass method ProgressBar::Base::new
# File lib/progress-bar.rb, line 66
def initialize *a, outfd: nil, errfd: nil, **options
        @outfd = outfd || STDERR
        @errfd = errfd || @outfd
        super *a, **options
end

Public Instance Methods

change_progress()
Alias for: change_text
change_text() click to toggle source
# File lib/progress-bar.rb, line 90
def change_text
        l = [[100.0*i/max, 0].max, 100].min.to_i
        dd, td = done_dur, total_dur
        b = ?= * l
        b[-1] = ?>  unless 0 == l or 100 == l
        @outfd.printf "\r\e[J%s / %s [%-*s] %s", format_time(dd), format_time(td), 100, b, text
end
Also aliased as: change_progress
error(text) click to toggle source
# File lib/progress-bar.rb, line 99
def error text
        @errfd.printf "\r\e[J%s\n", text
        @errfd.flush
end
finish() click to toggle source
# File lib/progress-bar.rb, line 104
def finish
        @outfd.puts
        @outfd.flush
end
format_time(t) click to toggle source
# File lib/progress-bar.rb, line 82
def format_time t
        if t.finite?
                sprintf "%02d:%02d:%02d", t/3600, t/60 % 3600, t % 60
        else
                "--:--:--"
        end
end
possible?() click to toggle source
# File lib/progress-bar.rb, line 72
def possible?
        @outfd.tty?
end
start() click to toggle source
Calls superclass method ProgressBar::Base#start
# File lib/progress-bar.rb, line 76
def start
        super
        change_text
        self
end