Skip to content

Terminal output API

Examples assume import hedgehogs as hdg.

API index

API Purpose Returns
hdg.Progress(...) Create manual or iterable progress Progress
progress.update(...) Advance completed work None
progress.set_metrics(...) Update reported metrics None
progress.set_description(...) Change the progress label None
progress.finish() Complete output None
progress.to_text() Render current progress as text str
progress.to_html() Render current progress as HTML str
hdg.echo(...) Write a status message None
hdg.rule(...) Write a separator None
hdg.info() Print package and Matplotlib versions str

Progress

Report progress for manually advanced work or an iterable.

hdg.Progress(iterable=None, total=None, desc="", width=40, mininterval=0.1, smoothing=0.3)

Invalid constructor values raise ValueError; update() after finish() raises RuntimeError.

mininterval limits refresh frequency. finish() always renders the final state.

Parameter Type Default Constraint or meaning
iterable iterable or None None Source consumed by iteration
total int or None Inferred Non-negative; required for sized progress when length cannot be inferred
desc str "" Prefix label
width int 40 Positive terminal bar width
mininterval float 0.1 Non-negative minimum refresh interval in seconds
smoothing float 0.3 Rate smoothing from 0 to 1

Terminal output

echo

Write a status message with optional colour and emphasis.

hdg.echo(message, *, tone=None, color=None, bold=False, file=None) -> None

Explicit color overrides tone. Invalid colours or tones raise ValueError. Redirected output stays plain; NO_COLOR and TERM=dumb disable terminal colour.

Parameter Default Meaning
message Required Text to write
tone None info, success, warning, error, or muted
color None Explicit Matplotlib colour; overrides tone
bold False Emphasise the message
file None Destination stream; None selects notebook output or standard output
Tone Intended use
info Neutral activity or context
success Successful completion
warning Recoverable concern or fallback
error Failed operation
muted Secondary information
hdg.echo("Evaluation complete", tone="success")

rule

Write a horizontal separator with an optional title.

hdg.rule(title="", *, width=None, file=None) -> None
Parameter Default Meaning
title "" Centred title; an empty string produces a line alone
width None Terminal width; automatic detection falls back to 80 columns
file None Destination stream; None selects standard output
hdg.rule("Summary")

Progress updates

progress.update(n=1)
progress.set_description(desc)
progress.set_metrics(**metrics)
progress.finish()
progress.to_text()
progress.to_html()

update() advances the counter. set_description() changes the label, and set_metrics() records metrics for the next refresh. These methods return None. Text and HTML renderers return strings. A context manager calls finish() on exit, including after an exception.

progress = hdg.Progress(total=2, desc="Evaluating")
progress.set_metrics(loss=0.12)
progress.update()
progress.set_description("Saving results")
progress.update()
progress.finish()
text = progress.to_text()
html = progress.to_html()

Package information

hdg.info()
info() prints the Hedgehogs and Matplotlib versions and returns the same text as a string.