GranularBar

GranularBar renders sub-character progress using block glyphs.

Useful when the bar is narrow and whole-character steps would look like the bar is stuck. markers sets the glyph ramp used for the partial cell. In the demo, the bar’s leading edge steps through the partial glyphs instead of jumping a whole character at a time.

class progressbar.widgets.GranularBar(markers=' ▏▎▍▌▋▊▉█', left='|', right='|', **kwargs)[source]

Bases: AutoWidthWidgetBase

A progressbar with sub-character granularity via multiple markers.

Examples of markers:
  • Smooth: ` ▏▎▍▌▋▊▉█` (default)

  • Bar: ` ▁▂▃▄▅▆▇█`

  • Snake: ` ▖▌▛█`

  • Fade in: ` ░▒▓█`

  • Dots: ` ⡀⡄⡆⡇⣇⣧⣷⣿`

  • Growing circles: ` .oO`

The markers can be accessed through GranularMarkers. GranularMarkers.dots for example

Create a GranularBar with its marker ramp and borders.

Parameters:
  • markers – String of characters to use as granular progress markers. The first character should represent 0% and the last 100%. Ex: ` .oO`.

  • left – String or callable object to use as a left border.

  • right – String or callable object to use as a right border.

  • **kwargs – Forwarded to AutoWidthWidgetBase.__init__.

Example

GranularBar
"""``GranularBar`` renders sub-character progress using block glyphs.

Useful when the bar is narrow and whole-character steps would look like
the bar is stuck.
"""

import time

import progressbar

STEPS = 24


def main() -> None:
    widgets = [
        progressbar.Percentage(),
        ' ',
        progressbar.GranularBar(),
        ' ',
        progressbar.ETA(),
    ]
    with progressbar.ProgressBar(max_value=STEPS, widgets=widgets) as bar:
        for step in range(STEPS):
            bar.update(step + 1)
            time.sleep(0.005)


if __name__ == '__main__':
    main()

See also

  • Bar: the whole-character fill this refines.