Class: Tqdm::StatusPrinter

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

Overview

Prints a status line, handling the deletion of previously printed lines with carriage returns as necessary. Instantiated by a TqdmDecorator.

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ StatusPrinter

Initialize a new StatusPrinter.

Parameters:

  • file (File, IO)

    the status will be printed to this via #write and #flush



35
36
37
38
# File 'lib/tqdm.rb', line 35

def initialize(file)
  @file = file
  @last_printed_len = 0
end

Instance Method Details

Prints a line of text to @file, after deleting the previously printed line

Parameters:

  • line (String)

    a line of text to be printed

Returns:

  • (Integer)

    the number of bytes written



44
45
46
47
48
# File 'lib/tqdm.rb', line 44

def print_status(line)
  @file.write("\r" + line + ' ' * [@last_printed_len - line.size, 0].max)
  @file.flush
  @last_printed_len = line.size
end