sparkline

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BufferSize is the number of readings to keep in the ring buffer
	BufferSize = 8
)

Variables

This section is empty.

Functions

func Save

func Save(sessionID, metric string, b *Buffer)

Save persists a buffer to disk

Types

type Buffer

type Buffer struct {
	Values [BufferSize]int `json:"values"`
	Pos    int             `json:"pos"`
	Count  int             `json:"count"`
}

Buffer is a fixed-size ring buffer of percentage values (0-100) that persists to disk across process invocations.

func Load

func Load(sessionID, metric string) *Buffer

Load reads a buffer from disk (or returns a cached in-memory copy). Returns a new empty buffer if the file doesn't exist.

func PushAndSave

func PushAndSave(sessionID, metric string, pct int) *Buffer

PushAndSave is a convenience that loads, pushes, saves, and returns the buffer

func (*Buffer) Latest

func (b *Buffer) Latest() int

Latest returns the most recently pushed value, or 0 if empty

func (*Buffer) Push

func (b *Buffer) Push(pct int)

Push appends a new percentage value to the ring buffer

func (*Buffer) Render

func (b *Buffer) Render() string

Render returns the sparkline string (e.g. "▁▃▅▇█▅▃▂"). Always renders BufferSize bars; empty slots show as the lowest bar.

Jump to

Keyboard shortcuts

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