Method: CLI::UI::Progress#tick

Defined in:
lib/cli/ui/progress.rb

#tick(percent: nil, set_percent: nil) ⇒ Object

Set the progress of the bar. Typically used in a Progress.progress block

Options

One of the follow can be used, but not both together

  • :percent - Increment progress by a specific percent amount

  • :set_percent - Set progress to a specific percent

Note: The :percent and +:set_percent must be between 0.00 and 1.0

: (?percent: Numeric?, ?set_percent: Numeric?) -> void

Raises:

  • (ArgumentError)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/cli/ui/progress.rb', line 83

def tick(percent: nil, set_percent: nil)
  raise ArgumentError, 'percent and set_percent cannot both be specified' if percent && set_percent

  @percent_done += percent || 0.01
  @percent_done = set_percent if set_percent
  @percent_done = [@percent_done, 1.0].min # Make sure we can't go above 1.0

  # Update terminal progress reporter with current percentage
  @reporter&.set_progress((@percent_done * 100).floor)

  print(self)

  printed_lines = @title ? 2 : 1
  print(CLI::UI::ANSI.previous_lines(printed_lines) + "\n")
end