Skip to content

5. Spinners and counters ​

march with a spinner, then a spinner alone, then a counter

A spinner is a character that changes at every drawing of the bar: it shows that the program is alive. You choose it with spinner_string, the key of one of the 40 spinners of forbear:

f90
call bar%initialize(prefix_string='march ', bracket_left_string='[', bracket_right_string='] ', &
                    filled_char_string='#', empty_char_string='.',                              &
                    spinner_string='⠋', spinner_color_fg='red',                                 &
                    width=40, max_value=real(steps, R8P))

While running:

$ march
march [####################....................] ⠴

The spinner moves one frame at every drawing of the bar: it is not driven by a clock of its own, so it stands still while the program spends a long time between two updates (Fortran has no portable threads to animate it meanwhile). A string that is not the key of a spinner stops the program, with a message that names it.

Without the bar ​

With width=0 the bar has no body: what remains is the prefix, the spinner, the percentage. A spinner alone:

f90
call bar%initialize(prefix_string='march ', spinner_string='⠋', spinner_color_fg='red', &
                    width=0, max_value=real(steps, R8P))
$ march
march [########################################] ⠋
march ⠴

A percentage alone, a counter:

f90
call bar%initialize(prefix_string='march ', add_progress_percent=.true., &
                    width=0, max_value=real(steps, R8P))
$ march
march [########################################] ⠋
march ⠋
march   50%

Each output shows the line of the previous bars above it: this program runs three bars, one after another, with the same bar object. Calling initialize again resets the bar: every setting not passed returns to its default.

What you learned

Spinners next to the bar and alone; a bare percentage; one object for several bars in a row. Reference: Spinners.

Next: 6. Talking while the bar runs.

Released under the GPL v3, BSD 2-Clause, BSD 3-Clause or MIT License.