Class: Testprune::UI::Progress

Inherits:
Object
  • Object
show all
Defined in:
lib/testprune/ui/progress.rb

Overview

Live scan progress display. Shows a Braille spinner, running test counter, and elapsed time. All output goes to io (default $stderr) and is suppressed when not a TTY or when NO_COLOR is set.

Constant Summary collapse

FRAMES =
%w[         ].freeze

Instance Method Summary collapse

Constructor Details

#initialize(io: $stderr) ⇒ Progress

Returns a new instance of Progress.



13
14
15
16
17
18
19
# File 'lib/testprune/ui/progress.rb', line 13

def initialize(io: $stderr)
  @io       = io
  @counter  = 0
  @frame    = 0
  @thread   = nil
  @mu       = Mutex.new
end

Instance Method Details

#increment(count: 1) ⇒ Object



37
38
39
# File 'lib/testprune/ui/progress.rb', line 37

def increment(count: 1)
  @mu.synchronize { @counter += count }
end

#startObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/testprune/ui/progress.rb', line 26

def start
  return unless tty?
  @start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  @thread = Thread.new do
    loop do
      draw
      sleep 0.1
    end
  end
end

#stop(test_count:, elapsed:) ⇒ Object

Stops the spinner thread and clears the line. Returns stats hash.



42
43
44
45
46
47
48
# File 'lib/testprune/ui/progress.rb', line 42

def stop(test_count:, elapsed:)
  @thread&.kill
  @thread&.join(0.2)
  @thread = nil
  @io.print("\r\e[K") if tty?
  { test_count: test_count, elapsed: elapsed }
end

#tty?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/testprune/ui/progress.rb', line 21

def tty?
  return false if ENV['NO_COLOR']
  @io.respond_to?(:isatty) && @io.isatty
end