class BusyIndicator

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.

Attributes

width[W]

Public Class Methods

new(start = true, width = nil) click to toggle source

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

# 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

Public Instance Methods

run() click to toggle source

Starts the text-animation, returns the thread.

# File lib/busy_indicator/busy_indicator.rb, line 38
def run() 
        @thr = busy_indicator(@width)
end
stop(comment) click to toggle source

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

# 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

Private Instance Methods

busy_indicator(width) click to toggle source
# File lib/busy_indicator/busy_indicator.rb, line 51
def busy_indicator(width)
        tobj = Thread.new() do
                print "working ... "
                loop do 
                        # %w"OOO ooo ___ ooo".each do |s|
                        # %w"000 OOO UUU VVV YYY TTT 777 >>> === --- ooo".each do |s|
                        %w"0OU OUV UVY VYT YT7 T7> 7>= >=- =-o -o0 o0O".each do |s|
                                print "%+#{width}s" %s
                                sleep 0.1
                                print ("\b" * width)
                        end
                end
        end
end