class Console::Event::Progress
def self.register(terminal)
def self.register(terminal) terminal[:progress_bar] ||= terminal.style(:blue, :white) end
def bar(value = self.value, width = 70)
def bar(value = self.value, width = 70) blocks = width * value full_blocks = blocks.floor partial_block = ((blocks - full_blocks) * BLOCK.size).floor if partial_block.zero? BLOCK.last * full_blocks else "#{BLOCK.last * full_blocks}#{BLOCK[partial_block]}" end.ljust(width) end
def format(output, terminal, verbose)
def format(output, terminal, verbose) output.puts "#{terminal[:progress_bar]}#{self.bar}#{terminal.reset} #{sprintf('%6.2f', self.value * 100)}%" end
def initialize(current, total)
def initialize(current, total) @current = current @total = total end
def to_h
def to_h {current: @current, total: @total} end
def value
def value @current.to_f / @total.to_f end