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.



8
9
10
11
12
# File 'lib/derrick/cli.rb', line 8

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

Instance Method Details

#clearObject



21
22
23
# File 'lib/derrick/cli.rb', line 21

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

#renderObject



14
15
16
17
18
19
# File 'lib/derrick/cli.rb', line 14

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

#startObject



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

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

#stopObject



34
35
36
37
# File 'lib/derrick/cli.rb', line 34

def stop
  @thread.kill
  clear
end