Class: BusyIndicator

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

Overview

The BusyIndicator will show an “Animation” for the time of its execution. The main program will continue to run in its own thread and should stop the BusyIndicator, once that a process of longer duration has terminated.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start = true, width = nil) ⇒ BusyIndicator

Defines a busy_indicator of a width of ‘width’ characters. If ‘start’ is true, the text-animation is run immediately.



32
33
34
35
# File 'lib/busy_indicator/busy_indicator.rb', line 32

def initialize(start = true, width = nil)
	@width = width && width >= 3 ? width : 3
	@thr = busy_indicator(@width) if start
end

Instance Attribute Details

#width=(value) ⇒ Object (writeonly)

Sets the attribute width

Parameters:

  • value

    the value to set the attribute width to.



29
30
31
# File 'lib/busy_indicator/busy_indicator.rb', line 29

def width=(value)
  @width = value
end

Instance Method Details

#runObject

Starts the text-animation, returns the thread.



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

def run() 
	@thr = busy_indicator(@width)
end

#stop(comment) ⇒ Object

Stops the text-animation, terminates the thread. If comment is not null, it will be displayed in the end.



44
45
46
47
48
49
# File 'lib/busy_indicator/busy_indicator.rb', line 44

def stop(comment)
	@thr.terminate
	@thr.join
	print ("\b" * @width)
	print ("%+#{@width}s\n" %comment)
end