madbot_cli.progress
Show what a command is doing while it runs.
In a terminal, one line says the step under way and is written again in place
while madbot works in the background (madbot reads the data: 2/4, 35 s).
Elsewhere (a file, a CI log), each step is one line, a wait writes a new line
only when what it says changes, and no control character is written.
Attributes
| Name | Description |
|---|---|
CLEAR_LINE | Takes the cursor back to the start of the line and erases it, in a terminal. |
Classes
| Name | Description |
|---|---|
Progress | The step under way, and the lines a command writes around it. |
CLEAR_LINEattributemodule attribute#
CLEAR_LINE = '\r\x1b[2K'Takes the cursor back to the start of the line and erases it, in a terminal.
Progressclass#
class Progress(stream: TextIO, *, steps: bool = True, live: bool | None = None, clock: Callable[[], float] = time.monotonic, columns: Callable[[], int] | None = None)The step under way, and the lines a command writes around it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
stream | TextIO | required | Where to write. |
steps | bool | True | Say the steps; False (--quiet) writes only the lines that stay. |
live | bool | None | Write the step again in place; by default, when stream is a
terminal. |
clock | callable | time.monotonic | Gives the time in seconds, to say how long a step lasts. |
columns | callable | None | Gives the width of the terminal: a longer line would wrap, and only its last row would be erased. The terminal’s by default. |
clockattributeinstance attribute#
clock = clockcolumnsattributeinstance attribute#
columns = columns or lambda : shutil.get_terminal_size().columnsliveattributeinstance attribute#
live = livesaidattributeinstance attribute#
said = ''The last step written, out of a terminal: a wait writes it once.
shownattributeinstance attribute#
shown = ''The step written in place, to erase before another line.
startedattributeinstance attribute#
started = clock()stepsattributeinstance attribute#
steps = stepsstreamattributeinstance attribute#
stream = streamclearmethod#
def clear() -> NoneErase the step written in place, once the command is over.
linemethod#
def line(text: str) -> NoneWrite a line that stays, such as a change, above the step under way.
Parameters
| Name | Type | Description |
|---|---|---|
text | str | The line. |
stepmethod#
def step(text: str) -> NoneSay a new step has started.
Parameters
| Name | Type | Description |
|---|---|---|
text | str | What it does, such as reading what madbot holds. |
updatemethod#
def update(text: str, elapsed: float | None = None) -> NoneSay where the step under way stands, with the time it has taken.
Out of a terminal, the line is written only when text changes.

