components

package
v0.213.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 4 Imported by: 0

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

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

func Bytes(n int64) string

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 Clock

func Clock(tsMicros int64) string

Clock renders an event microsecond timestamp as HH:MM:SS (local-safe UTC).

func Count

func Count(n int64) string

Count renders a plain integer count compactly (1.2k, 88k, 4k) for high-cardinality counters; small values stay exact.

func Gauge

func Gauge(value, max float64, width int, ascii bool) string

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 OrDash

func OrDash(s string) string

OrDash returns "-" for an empty string (never a blank cell).

func ShortAddr

func ShortAddr(s string, head, tail int) string

ShortAddr abbreviates a long handle (an opaque t<sha256> tenant) to head…tail so the header stays compact while still being recognisable.

func Sparkline

func Sparkline(vals []float64, width int, ascii bool) string

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).

func TrimDot

func TrimDot(s string) string

TrimDot drops a trailing FQDN dot for display.

func Uptime

func Uptime(epochMs int64) string

Uptime renders a duration since an epoch-ms instant as a compact "3d2h" / "5m" form.

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.

Jump to

Keyboard shortcuts

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