Module: Mothership::Progress::Dots

Defined in:
lib/mothership/progress.rb

Constant Summary collapse

DOT_COUNT =
3
DOT_TICK =
0.15

Class Method Summary collapse

Class Method Details

.start!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mothership/progress.rb', line 11

def start!
  @dots ||=
    Thread.new do
      before_sync = $stdout.sync

      $stdout.sync = true

      printed = false
      i = 1
      until @stop_dots
        if printed
          print "\b" * DOT_COUNT
        end

        print ("." * i).ljust(DOT_COUNT)
        printed = true

        if i == DOT_COUNT
          i = 0
        else
          i += 1
        end

        sleep DOT_TICK
      end

      if printed
        print "\b" * DOT_COUNT
        print " " * DOT_COUNT
        print "\b" * DOT_COUNT
      end

      $stdout.sync = before_sync
      @stop_dots = nil
    end
end

.stop!Object



48
49
50
51
52
53
54
# File 'lib/mothership/progress.rb', line 48

def stop!
  return unless @dots
  return if @stop_dots
  @stop_dots = true
  @dots.join
  @dots = nil
end