Class: ProgressBar::Console
- Inherits:
-
Base
- Object
- Base
- ProgressBar::Console
show all
- Defined in:
- lib/progress-bar.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#i, #max, #startts, #text
Instance Method Summary
collapse
Methods inherited from Base
#done_dur, #done_rel, #increment!, #total_dur
Constructor Details
#initialize(*a, outfd: nil, errfd: nil, **options) ⇒ Console
Returns a new instance of Console.
66
67
68
69
70
|
# 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
|
Instance Attribute Details
#errfd ⇒ Object
Returns the value of attribute errfd.
64
65
66
|
# File 'lib/progress-bar.rb', line 64
def errfd
@errfd
end
|
#outfd ⇒ Object
Returns the value of attribute outfd.
64
65
66
|
# File 'lib/progress-bar.rb', line 64
def outfd
@outfd
end
|
Instance Method Details
#change_text ⇒ Object
Also known as:
change_progress
90
91
92
93
94
95
96
|
# 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
|
#error(text) ⇒ Object
99
100
101
102
|
# File 'lib/progress-bar.rb', line 99
def error text
@errfd.printf "\r\e[J%s\n", text
@errfd.flush
end
|
#finish ⇒ Object
104
105
106
107
|
# File 'lib/progress-bar.rb', line 104
def finish
@outfd.puts
@outfd.flush
end
|
82
83
84
85
86
87
88
|
# 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? ⇒ Boolean
72
73
74
|
# File 'lib/progress-bar.rb', line 72
def possible?
@outfd.tty?
end
|
#start ⇒ Object
76
77
78
79
80
|
# File 'lib/progress-bar.rb', line 76
def start
super
change_text
self
end
|