flux.progress module
- class flux.progress.Bottombar(formatter=None, **kwargs)
Bases:
object
Maintain a status line at bottom of terminal using vt100 escape codes
The Bottombar class implements a very simple status line which stays positioned at the last line of vt100 capable terminals through the use of vt100 escape codes.
This class will only work properly on vt100 compatible terminals, which includes xterm, rxvt, and gnome-terminal and their derivatives on Linux, as well as iTerm and Terminal on OSX, and reportedly the new Windows Terminal on Windows.
Use of Bottombar requires that a
formatter
function be provided. Theformatter
will be called on each update as:formatter(bbar, width)
Where
bbar
is the bottombar object being formatted andwidth
is the current terminal width at the time of the update. The defaultformatter
will simply print all extraAs a convenience, the Bottombar constructor collects all extra keyword arguments and presents them as attributes on the Bottombar object for later access from within and outside the provided
formatter
, e.g:def formatter(bb, width): text = f"iteration={bb.i}" return text + time.ctime().rjust(width - len(text)) bb = Bottombar(formatter, i=0).start() for i in range(0, 128): bb.update(i=i) time.sleep(.05) bb.stop()
will print a statusbar with an iteration count left justified, and the current time right justified.
- elapsed
The elapsed time since
bb.start()
in floating point seconds. As a convenience,bb.elapsed
may be converted to adatetime.timedelta
object via thedt
attribute, e.g.bb.elapsed.dt
.- Type
float
- Parameters
formatter (function) -- Function which returns the status string
kwargs -- all extra keyword arguments are collected in the Bottombar instance and made available as attributes for convenience
- redraw()
Redraw bar without update
- start()
Start drawing a Bottombar
- stop()
Reset terminal and write final bottombar state with newline
- update(**kwargs)
Update keyword args and redraw a bottombar
- class flux.progress.ElapsedTime(x=0, /)
Bases:
float
An ElapsedTime object is a floating point elapsed time in seconds that comes with a convenient "dt" property that returns a datetime.timedelta object
- property dt
- class flux.progress.ProgressBar(total=100, style='vertbars', before='', after=' {percent:5.1f}%', autostop=False, **kwargs)
Bases:
Bottombar
Simple progress bar that stays on last line of terminal
The ProgressBar class uses the features of Bottombar to create a progress bar, plus optional other text, which stays on the last line of a terminal. A vt100 compatible terminal is required.
- Parameters
total (int) -- The total expected number of items/units for which the progressbar is monitoring progress, default=100.
style (str, optional) -- A string progress bar style from the list "line", "bar", "dots", "steps", "vertbars".
before (str, optional) -- A string to place before the progress bar.
after (str, optional) -- A string to place after the progress bar. default=" {percent:5.1f}%"
autostop (bool, optional) -- If True, ProgressBar instance will be automatically stopped when count == total. Otherwise, terminal reset will be deferred to an atexit handler.
kwargs (optional) -- Extra keyword args are saved and passed as args when formatting the
before
andafter
strings.
The
before
andafter
strings are formatted on each update to the progressbar and passed all extra keyword args, plus the currenttotal
,count
,percent
, andelapsed
time e.g.:before_str = before.format( total=total, count=count, percent=percent, elapsed=elapsed, **kwargs )
which means that these strings are most useful when they are format strings, e.g.:
ProgressBar(before="Running {total} jobs, {percent}% complete: ")
- bar_style = {'bar': '─█', 'dots': '⣀⣄⣤⣦⣶⣷⣿', 'line': '─━', 'steps': ' ▁▂▃▄▅▆▇█', 'vertbars': ' ▏▎▍▌▋▊▉█'}
- update(advance=1, **kwargs)
Update the state of a ProgressBar
Update the state of a ProgressBar and redraw if the progress bar is currently running. If
count == total
and autostop is set, the progress bar will be automatically stopped.When the progress bar is stopped, the terminal will be reset and the final state of the bar will be left on the last line of output.
- Parameters
advance (int, optional) -- Advance progress by
advance
amount.kwargs -- Update stored keyword arguments