Class: Alula::ProgressBar
- Inherits:
-
PowerBar
- Object
- PowerBar
- Alula::ProgressBar
- Defined in:
- lib/alula/progressbar.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
-
#showing ⇒ Object
Returns the value of attribute showing.
Instance Method Summary collapse
- #file_transfer_mode ⇒ Object
- #finish(fill = true) ⇒ Object
-
#initialize(message, total, opts = {}) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #render(opts = {}) ⇒ Object
- #set(value) ⇒ Object
- #step ⇒ Object
- #vanish ⇒ Object
Constructor Details
#initialize(message, total, opts = {}) ⇒ ProgressBar
Returns a new instance of ProgressBar.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/alula/progressbar.rb', line 8 def initialize(, total, opts = {}) super(opts) @message = "%20s" % @done = 0 @total = total @showing = true self.settings.tty.finite.template.main = '${<msg>}: ${<percent>% } ${[<bar>] }${ ETA: <eta>}' self.settings.tty.finite.template. = 'o' self.settings.tty.finite.template.padchar = ' ' end |
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/alula/progressbar.rb', line 6 def @message end |
#showing ⇒ Object
Returns the value of attribute showing.
5 6 7 |
# File 'lib/alula/progressbar.rb', line 5 def showing @showing end |
Instance Method Details
#file_transfer_mode ⇒ Object
22 23 24 |
# File 'lib/alula/progressbar.rb', line 22 def file_transfer_mode self.settings.tty.finite.template.main = '${<msg>}: ${<percent>% } ${[<bar>] }${<rate>/s }${<done>}${ ETA: <eta>}' end |
#finish(fill = true) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/alula/progressbar.rb', line 42 def finish(fill = true) # self.close(true) render( { :done => fill && !state.total.is_a?(Symbol) ? state.total : state.done, :tty => { :finite => { :show_eta => false }, :infinite => { :show_eta => false }, }, :notty => { :finite => { :show_eta => false }, :infinite => { :show_eta => false }, }, }) # scope.output.call(scope.template.close) unless scope.template.close.nil? state.closed = true end |
#render(opts = {}) ⇒ Object
26 27 28 |
# File 'lib/alula/progressbar.rb', line 26 def render(opts = {}) super({msg: @message, done: @done, total: @total}.merge(opts)) end |
#set(value) ⇒ Object
34 35 36 |
# File 'lib/alula/progressbar.rb', line 34 def set(value) @done = value end |
#step ⇒ Object
30 31 32 |
# File 'lib/alula/progressbar.rb', line 30 def step @done += 1 end |
#vanish ⇒ Object
38 39 40 |
# File 'lib/alula/progressbar.rb', line 38 def vanish self.wipe end |