Class: CC::Analyzer::Formatters::Spinner

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/analyzer/formatters/spinner.rb

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Spinner

Returns a new instance of Spinner.



5
6
7
# File 'lib/cc/analyzer/formatters/spinner.rb', line 5

def initialize(text)
  @spinner = TTY::Spinner.new(text)
end

Instance Method Details

#startObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/cc/analyzer/formatters/spinner.rb', line 9

def start
  return unless $stdout.tty? && !CLI.debug?
  @thread = Thread.new do
    loop do
      @spinning = true
      spinner.spin
      sleep 0.075
    end
  end
end

#stop(text = "Done!") ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/cc/analyzer/formatters/spinner.rb', line 20

def stop(text = "Done!")
  if @spinning
    spinner.stop(text)
    print("\n")
    @thread.kill
  end
  @spinning = false
end