Documentation
¶
Overview ¶
Package metrics renders small inline summaries — status badges, ratios, progress bars, sparklines — sized to fit inside list rows, table cells, or inspector values without breaking outer SGR state. Every helper returns a fixed-width string of ANSI-colored text using foreground-only escapes (via pkg/ansi.CellColor) so embedding inside a table row keeps the selected-row background intact.
The package is rendering-only: callers own data, history, and any aggregation. For sparklines that need a moving window across refreshes, the caller maintains a fixed-size ring buffer and passes it in fresh each frame; metrics.Spark resamples to fit the requested width.
Defaults use a small, opinionated severity palette (green/yellow/red/blue) tuned for the common monitoring case. Callers that need different colors should use the *Styled variants which take an explicit ANSI color index, or assemble their own from pkg/ansi.CellColor.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Badge ¶
Badge renders an inline status-count summary like "12✓ 3⚠ 1✗", with each segment colored by severity. Zero buckets are omitted; an all-zero input renders as "". Visible width is variable (depends on which buckets are non-zero) — pad the cell yourself if you need a fixed column.
func Bar ¶
Bar renders a fixed-width progress bar. The fill ratio is value/max coerced to [0, 1]; width is the total visible cell width (must be > 0). Color is inferred from severity: green when full, yellow when partial, red when empty. For a non-severity bar (e.g. CPU usage that should always be blue), use BarStyled.
func BarStyled ¶
BarStyled is Bar with an explicit ANSI color index instead of severity inference. Useful for non-severity progress (CPU, memory, fill level) where the threshold doesn't carry "good/bad" meaning.
func Ratio ¶
Ratio renders "done/total" colored by completion: green when full, yellow when partial, red when zero, gray when total is zero. Use for replica counts, job-completion counters, or any "N of M" indicator where the threshold is "all-or-nothing." Visible width is the natural width of the formatted string.
func Spark ¶
Spark renders a fixed-width sparkline using 8-step block glyphs (▁▂▃▄▅▆▇█), normalized to the local series min/max. Resamples by averaging buckets when len(values) > width and by nearest-index sampling when len(values) < width. Returns "" when values is empty or width <= 0. Color is blue (informational); use SparkStyled for an explicit color.
Types ¶
This section is empty.