metrics

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 4 Imported by: 0

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

func Badge(ok, warn, down int) string

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

func Bar(value, max float64, width int) string

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

func BarStyled(value, max float64, width int, color int) string

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

func Ratio(done, total int) string

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

func Spark(values []float64, width int) string

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.

func SparkStyled

func SparkStyled(values []float64, width int, color int) string

SparkStyled is Spark with an explicit ANSI color index.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL