Class: Tqdm::Printer
- Inherits:
-
Object
- Object
- Tqdm::Printer
- Extended by:
- Forwardable
- Defined in:
- lib/tqdm/printer.rb,
lib/tqdm/printer/default_format.rb
Overview
Prints a status line, handling the deletion of previously printed lines with carriage
returns as necessary. Instantiated by a Decorator
.
Defined Under Namespace
Classes: DefaultFormat
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#finish(iteration, elapsed_time, reprint) ⇒ Object
Prints a line of text to @file, after deleting the previously printed line.
-
#initialize(options) ⇒ Printer
constructor
Initialize a new Printer.
-
#null_finish ⇒ Object
Disappear without a trace.
-
#padded_line(iteration, elapsed_time) ⇒ String
Pads a status line so that it is long enough to overwrite the previously written line.
-
#status(iteration, elapsed_time) ⇒ Object
Prints a line of text to @file, after deleting the previously printed line.
Constructor Details
#initialize(options) ⇒ Printer
Initialize a new Printer.
20 21 22 23 24 25 |
# File 'lib/tqdm/printer.rb', line 20 def initialize() @total = [:total] @format = Printer::DefaultFormat.new() @file = [:file] || $stderr @last_printed_length = 0 end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
13 14 15 |
# File 'lib/tqdm/printer.rb', line 13 def file @file end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
13 14 15 |
# File 'lib/tqdm/printer.rb', line 13 def format @format end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
13 14 15 |
# File 'lib/tqdm/printer.rb', line 13 def total @total end |
Instance Method Details
#finish(iteration, elapsed_time, reprint) ⇒ Object
Prints a line of text to @file, after deleting the previously printed line
53 54 55 56 57 |
# File 'lib/tqdm/printer.rb', line 53 def finish(iteration, elapsed_time, reprint) file.write("\r" + padded_line(iteration, elapsed_time)) if reprint file.write("\n") file.flush end |
#null_finish ⇒ Object
Disappear without a trace.
60 61 62 |
# File 'lib/tqdm/printer.rb', line 60 def null_finish file.write("\r" + ' ' * @last_printed_length + "\r") end |
#padded_line(iteration, elapsed_time) ⇒ String
Pads a status line so that it is long enough to overwrite the previously written line
32 33 34 35 36 37 |
# File 'lib/tqdm/printer.rb', line 32 def padded_line(iteration, elapsed_time) meter_line = line(iteration, elapsed_time) pad_size = [@last_printed_length - meter_line.size, 0].max @last_printed_length = meter_line.size meter_line + ' ' * pad_size end |
#status(iteration, elapsed_time) ⇒ Object
Prints a line of text to @file, after deleting the previously printed line
43 44 45 46 |
# File 'lib/tqdm/printer.rb', line 43 def status(iteration, elapsed_time) file.write("\r" + padded_line(iteration, elapsed_time)) file.flush end |