Class: BusyIndicator
- Inherits:
-
Object
- Object
- BusyIndicator
- 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
-
#width ⇒ Object
writeonly
Sets the attribute width.
Instance Method Summary collapse
-
#initialize(start = true, width = nil) ⇒ BusyIndicator
constructor
Defines a busy_indicator of a width of ‘width’ characters.
-
#run ⇒ Object
Starts the text-animation, returns the thread.
-
#stop(comment) ⇒ Object
Stops the text-animation, terminates the thread.
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.
26 27 28 29 |
# File 'lib/busy_indicator/busy_indicator.rb', line 26 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
23 24 25 |
# File 'lib/busy_indicator/busy_indicator.rb', line 23 def width=(value) @width = value end |
Instance Method Details
#run ⇒ Object
Starts the text-animation, returns the thread.
32 33 34 |
# File 'lib/busy_indicator/busy_indicator.rb', line 32 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.
38 39 40 41 42 43 |
# File 'lib/busy_indicator/busy_indicator.rb', line 38 def stop(comment) @thr.terminate @thr.join print ("\b" * @width) print ("%+#{@width}s\n" %comment) end |