Class: Alula::Progress

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Progress

Returns a new instance of Progress.



5
6
7
8
9
10
11
12
# File 'lib/alula/progress.rb', line 5

def initialize(options)
  @pbars = {}
  @interval = 1.0
  @options = options
  @display = false
  
  @@lock = Mutex.new
end

Instance Method Details

#create(identifier, opts) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/alula/progress.rb', line 14

def create(identifier, opts)
  if @pbars[identifier]
    @pbars[identifier].finish
  end
  
  @@lock.synchronize do
    @pbars[identifier] = ProgressBar.new(opts[:title], opts[:total] == 0 ? 0.1 : opts[:total])
    if @options[:debug]
      @pbars[identifier].settings.force_mode = :notty
    end
  end
end

#displayObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/alula/progress.rb', line 62

def display
  @display = true
  _display(true)
  unless @options[:debug]
    @update_thread = Thread.new {
      loop {
        sleep(@interval)
        _display
      }
    }
  end
end

#finish(identifier) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/alula/progress.rb', line 52

def finish(identifier)
  if @pbars[identifier]
    @pbars[identifier].finish
    _display
    @@lock.synchronize do
      @pbars.delete(identifier)
    end
  end
end

#hideObject



75
76
77
78
79
80
# File 'lib/alula/progress.rb', line 75

def hide
  @display = false
  if @update_thread
    Thread.kill(@update_thread)
  end
end

#set(identifier, value) ⇒ Object



34
35
36
37
38
# File 'lib/alula/progress.rb', line 34

def set(identifier, value)
  if @pbars[identifier]
    @pbars[identifier].set(value)
  end
end

#set_file_transfer(identifier) ⇒ Object



46
47
48
49
50
# File 'lib/alula/progress.rb', line 46

def set_file_transfer(identifier)
  if @pbars[identifier]
    @pbars[identifier].file_transfer_mode
  end
end

#step(identifier) ⇒ Object



27
28
29
30
31
32
# File 'lib/alula/progress.rb', line 27

def step(identifier)
  if @pbars[identifier]
    @pbars[identifier].step
    _display
  end
end

#title(identifier, title) ⇒ Object



40
41
42
43
44
# File 'lib/alula/progress.rb', line 40

def title(identifier, title)
  if @pbars[identifier]
    @pbars[identifier].message = title
  end
end