Skip to content

Progress and terminal examples

Run the cells in order after installation. Code comes from the original notebook. Saved outputs are previews. Output paths are relative to the working directory.

Preamble

from pathlib import Path
import hedgehogs as hdg

Iterable progress

values = []
for index in hdg.Progress(range(20), desc="Evaluating"):
    values.append(index**2)

Manual progress

with hdg.Progress(total=10, desc="Iterations") as progress:
    for iteration in range(10):
        error = 1 / (iteration + 1)
        progress.set_metrics(error=f"{error:.4f}")
        progress.update()

Status messages

hdg.echo("Reading data", tone="info")
hdg.echo("Fallback selected", tone="warning")
hdg.echo("Evaluation complete", tone="success")
hdg.rule("Summary")

Redirected output

output_root = Path.cwd() / "output" / "cli"
output_root.mkdir(parents=True, exist_ok=True)
with (output_root / "status.log").open("w") as stream:
    hdg.echo("Evaluation complete", tone="success", file=stream)
    hdg.rule("Summary", file=stream)
print((output_root / "status.log").read_text())