Module: Interact::Progress::Dots

Defined in:
lib/interact/progress.rb

Constant Summary collapse

DOT_COUNT =
3
DOT_TICK =
0.15

Class Method Summary collapse

Class Method Details

.start!Object



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
47
# File 'lib/interact/progress.rb', line 12

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



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

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