class Tqdm::Printer

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

@private

Attributes

file[R]
format[R]
total[R]

Public Class Methods

new(options) click to toggle source

Initialize a new Printer.

@param options [Hash] the options for the instantiating Tqdm::Decorator

@see Tqdm::Decorator#initialize

# File lib/tqdm/printer.rb, line 20
def initialize(options)
  @total = options[:total]
  @format = Printer::DefaultFormat.new(options)
  @file = options[:file] || $stderr
  @last_printed_length = 0
end

Public Instance Methods

finish(iteration, elapsed_time, reprint) click to toggle source

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

@param iteration [Integer] number of iterations, out of the total, that are completed @param elapsed_time [Float] number of seconds passed since start @param reprint [Boolean] do we need to reprint the line one last time?

# 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() click to toggle source

Disappear without a trace.

# File lib/tqdm/printer.rb, line 60
def null_finish
  file.write("\r" + ' ' * @last_printed_length + "\r")
end
padded_line(iteration, elapsed_time) click to toggle source

Pads a status line so that it is long enough to overwrite the previously written line

@param iteration [Integer] number of iterations, out of the total, that are completed @param elapsed_time [Float] number of seconds passed since start @return [String] the padded line

# 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) click to toggle source

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

@param iteration [Integer] number of iterations, out of the total, that are completed @param elapsed_time [Float] number of seconds passed since start

# File lib/tqdm/printer.rb, line 43
def status(iteration, elapsed_time)
  file.write("\r" + padded_line(iteration, elapsed_time))
  file.flush
end