Class: TTY::ProgressBar::BarFormatter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/progressbar/formatter/bar.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Used by Pipeline to format bar

Instance Method Summary collapse

Instance Method Details

#call(value) ⇒ Object

Format :bar token

Parameters:

  • value (String)

    the value being formatted



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tty/progressbar/formatter/bar.rb', line 19

def call(value)
  without_bar = value.gsub(/:bar/, "")
  available_space = [0, ProgressBar.max_columns -
                        ProgressBar.display_columns(without_bar) -
                        @progress.inset].max
  width = [@progress.width.to_i, available_space].min

  # When we don't know the total progress, use either user
  # defined width or rely on terminal width detection
  if @progress.indeterminate?
    width = available_space if width.zero?

    format_indeterminate(value, width)
  else
    format_determinate(value, width)
  end
end