Class: Tqdm::StatusPrinter
- Inherits:
-
Object
- Object
- Tqdm::StatusPrinter
- 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
-
#initialize(file) ⇒ StatusPrinter
constructor
Initialize a new StatusPrinter.
-
#print_status(line) ⇒ Integer
Prints a line of text to @file, after deleting the previously printed line.
Constructor Details
#initialize(file) ⇒ StatusPrinter
Initialize a new StatusPrinter.
35 36 37 38 |
# File 'lib/tqdm.rb', line 35 def initialize(file) @file = file @last_printed_len = 0 end |
Instance Method Details
#print_status(line) ⇒ Integer
Prints a line of text to @file, after deleting the previously printed line
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 |