Class: Derrick::CLI::ProgressDisplay

Inherits:
Object
  • Object
show all
Defined in:
lib/derrick/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(progress, output) ⇒ ProgressDisplay

Returns a new instance of ProgressDisplay.



10
11
12
13
14
# File 'lib/derrick/cli.rb', line 10

def initialize(progress, output)
  @progress = progress
  @output = output
  @last_output_size = 0
end

Instance Method Details

#clearObject



23
24
25
# File 'lib/derrick/cli.rb', line 23

def clear
  @output.print "\b" * @last_output_size
end

#renderObject



16
17
18
19
20
21
# File 'lib/derrick/cli.rb', line 16

def render
  clear
  message = "collected: #{@progress.collected}/#{@progress.total} fetched: #{@progress.fetched}/#{@progress.total}"
  @last_output_size = message.size
  @output.print message
end

#startObject



27
28
29
30
31
32
33
34
# File 'lib/derrick/cli.rb', line 27

def start
  @thread = Thread.new do
    loop do
      render
      sleep 1
    end
  end
end

#stopObject



36
37
38
39
# File 'lib/derrick/cli.rb', line 36

def stop
  @thread.kill
  clear
end