Documentation
¶
Overview ¶
Package components holds the reusable Lip Gloss render helpers the views compose: the braille sparkline, the gauge, and small formatters. They are pure render functions (value-in, string-out) so they are trivially unit-testable and never touch the network or the Bubble Tea loop.
Index ¶
- func Braille(vals []float64, o BrailleOpts) string
- func Bytes(n int64) string
- func Clock(tsMicros int64) string
- func Count(n int64) string
- func Gauge(value, max float64, width int, ascii bool) string
- func GaugeGrad(value, max float64, width int, noColor bool, ...) string
- func OrDash(s string) string
- func ShortAddr(s string, head, tail int) string
- func Sparkline(vals []float64, width int, ascii bool) string
- func SparklineGradient(vals []float64, width int, noColor bool, lo, mid, hi lipgloss.TerminalColor) string
- func TrimDot(s string) string
- func Uptime(epochMs int64) string
- type BrailleOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Braille ¶
func Braille(vals []float64, o BrailleOpts) string
Braille renders vals as a hero graph filling Width×Height cells. The most-recent samples occupy the right edge; older samples scroll off the left. A flat/empty series renders a clean baseline (never a blank panel - the graph is always alive).
func Bytes ¶
Bytes renders a byte count in a compact human form (1.0K, 45.2M, 5.8G). It uses 1000-base units (matching the dev guide's display style) so "45.2M" reads naturally.
func Count ¶
Count renders a plain integer count compactly (1.2k, 88k, 4k) for high-cardinality counters; small values stay exact.
func Gauge ¶
Gauge renders a fixed-width fraction bar (filled ▓ / empty ░), like btop. value/max clamps to [0,1]; width is the bar interior. With ascii on it uses '#'/'-'.
func GaugeGrad ¶
func GaugeGrad(value, max float64, width int, noColor bool, lo, mid, hi, empty lipgloss.TerminalColor) string
GaugeGrad renders a fixed-width fraction bar whose FILLED portion is coloured by a three-stop value map of the fill fraction (low→lo, mid→mid, high→hi - the btop green→amber→red "load" look). The empty portion is dim. value/max clamps to [0,1]. With colour off it falls back to the plain ascii Gauge (meaning never depends on colour). Pure: deterministic per (value,max,width), so no flicker on re-render.
func ShortAddr ¶
ShortAddr abbreviates a long handle (an opaque t<sha256> tenant) to head…tail so the header stays compact while still being recognisable.
func Sparkline ¶
Sparkline renders the last `width` samples of vals as a peak-normalised bar string. When ascii is true (NO_COLOR or a non-UTF terminal) it uses the " .:-=+*#" ramp; a coloured terminal gets the braille ramp. An empty/zero series renders as flat low bars, never a blank - the panel always shows it is alive.
Conservative-emit: width is clamped to a sane range; a nil/short series left-pads with the lowest bar so the gauge keeps a fixed footprint (no layout jitter).
func SparklineGradient ¶
func SparklineGradient(vals []float64, width int, noColor bool, lo, mid, hi lipgloss.TerminalColor) string
SparklineGradient is Sparkline with a per-cell THREE-stop colour gradient (value- mapped: short bars → lo, mid bars → mid, tall bars → hi). With colour off it returns the plain ASCII sparkline. This gives the btop "value-mapped glow" without per-cell state - each cell's colour is a pure function of its height fraction, so the render is deterministic and re-renders identically every frame (no flicker).
Types ¶
type BrailleOpts ¶
type BrailleOpts struct {
Width int // total width in CELLS (incl. the Y-axis gutter) - the panel interior
Height int // total height in CELLS (incl. the time-axis row)
NoColor bool // ascii fallback + no gradient
// Gradient stops, low→high (a tall bar shifts toward Hi). Ignored when NoColor.
Lo, Mid, Hi lipgloss.TerminalColor
// AxisStyle / LabelStyle render the gutter rule and the axis labels (dim).
Axis, Label lipgloss.Style
// Unit is appended to the Y-axis peak label (e.g. "kbps").
Unit string
}
BrailleOpts configures a hero-graph render.