Skip to content

Formatting

Jeff Felchner edited this page Mar 4, 2023 · 11 revisions

The format of the progress bar is extremely easy to customize. You can do it one of two ways:

  1. When you create the progress bar and pass the :format option
  2. By setting the RUBY_PROGRESS_BAR_FORMAT environment variable

Note 1: Explicitly passing :format will override the environment variable.

Note 2: Most of this information is also exposed via to_h which is a bit more script-friendly if you need only a single piece or two of information.

All values have an absolute length with the exception of the bar flags which will occupy any leftover space.

You can use as many bar flags as you'd like, but if you do weird things, weird things will happen; so be wary.

The flags you can use in the format string are as follows:

Basic

Flag Description Example
%t Title Progress
%% A literal percent sign % %

Timers

Flag Description Example
%a Elapsed (absolute) time 12:01:59
%e Estimated time (will fall back to ETA: ??:??:?? when it exceeds 99:00:00) ETA: 21:12:39
%E Estimated time (will fall back to ETA: > 4 Days when it exceeds 99:00:00) ETA: 21:12:39
%l Estimated wall clock completion time 16:58:32
%f Force estimated time to be displayed even if it exceeds 99:00:00 ETA: 91:12:39

Percentage

Flag Description Example
%p Percentage complete represented as a whole number 82
%P Percentage complete represented as a decimal number 82.33
%j Like %p but right-justified to 3 places
%J Like %P but right-justified to 6 places

Progress/Items/Total

Flag Description Example
%c Number of items currently completed 12
%C Total number of items to be completed 100
%u Like %C but falls back to ?? if total is unknown) ??

Bar

Flag Description Example
%B The full progress bar including 'incomplete' space ==========
%b Progress bar only ==========
%W The full progress bar With integrated percentage including 'incomplete' space ==== 75 ====
%w Bar With Integrated Percentage ==== 75 ====
%i Display the incomplete space of the bar (by default this string will only contain whitespace) N/A

Rate of Change

Flag Description Example
%r Rate of Progress as a whole number 13
%R Rate of Progress as a decimal number 13.67