Class: RDialogy::Gauge

Inherits:
Base
  • Object
show all
Defined in:
lib/rdialogy/gauge.rb

Class Method Summary collapse

Class Method Details

.commandObject



33
34
35
# File 'lib/rdialogy/gauge.rb', line 33

def self.command
  'gauge'
end

.run(options = {}) ⇒ Object

a new prompt on the progress bar.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rdialogy/gauge.rb', line 19

def self.run(options={})
  begin
    fifo = "/tmp/dialog_gauge.#{$$}"
    system "mkfifo #{fifo}"
    system "( #{dialog_string options} < #{fifo} ) &"
    @@fifo = File.open fifo, 'w'
    yield self
  ensure
    @@fifo.close
    @@fifo = nil
    system "rm #{fifo}"
  end
end

.set_prompt(percentage, new_prompt) ⇒ Object

sends the percentage to the running gauge and sets a new prompt



47
48
49
50
51
52
53
54
# File 'lib/rdialogy/gauge.rb', line 47

def self.set_prompt(percentage, new_prompt)
  raise "Can't update gauge as it is not running." if @@fifo.nil?
  @@fifo.puts "XXX"
  @@fifo.puts percentage.to_i
  @@fifo.puts new_prompt
  @@fifo.puts "XXX"
  @@fifo.flush
end

.update(percentage) ⇒ Object

sends the new percentage to the running gauge



39
40
41
42
43
# File 'lib/rdialogy/gauge.rb', line 39

def self.update(percentage)
  raise "Can't update gauge as it is not running." if @@fifo.nil?
  @@fifo.puts percentage.to_i
  @@fifo.flush
end