Class: Alula::ProgressBar

Inherits:
PowerBar
  • Object
show all
Defined in:
lib/alula/progressbar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(message, total, opts = {})
  super(opts)
  
  @message = "%20s" % message
  @done = 0
  @total = total
  
  @showing = true
  
  self.settings.tty.finite.template.main = '${<msg>}: ${<percent>% } ${[<bar>] }${ ETA: <eta>}'
  self.settings.tty.finite.template.barchar = 'o'
  self.settings.tty.finite.template.padchar = ' '
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/alula/progressbar.rb', line 6

def message
  @message
end

#showingObject

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_modeObject



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

#stepObject



30
31
32
# File 'lib/alula/progressbar.rb', line 30

def step
  @done += 1
end

#vanishObject



38
39
40
# File 'lib/alula/progressbar.rb', line 38

def vanish
  self.wipe
end