cliui

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cliui is OpenPanda's terminal presentation layer: one colour vocabulary, one spinner, one live status line, shared by every CLI surface.

It exists because the colour handling used to be copy-pasted — five separate `"\x1b[" + code + "m" + s + "\x1b[0m"` sites, each with its own TTY check and none of them honouring NO_COLOR. A palette is built once from the terminal's actual capabilities and passed down; a disabled palette returns its input untouched, so callers never branch on "are we on a TTY" again.

Nothing here knows about locales: every human-readable word arrives from the caller (already translated through internal/i18n).

Index

Constants

View Source
const FrameInterval = 80 * time.Millisecond

FrameInterval is one spinner step. Fast enough to read as motion, slow enough that a remote session over ssh is not repainting constantly.

Variables

View Source
var ASCIIWheel = []string{"-", "\\", "|", "/"}

ASCIIWheel is the fallback spinner. Four frames, so it visibly ticks rather than pretending to be smooth.

View Source
var Braille = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}

Braille is the default spinner: ten frames of U+280x dots, one glyph wide, which reads as smooth rotation at ~80ms per frame.

Functions

func DisplayWidth

func DisplayWidth(s string) int

DisplayWidth sums the column count of s. Escape sequences are NOT accounted for — pass unstyled text (the status line measures before it paints).

func Frames

func Frames(p Palette) []string

Frames picks the spinner set for a palette.

func HumanCount

func HumanCount(n int64) string

HumanCount abbreviates a token/byte count: 1234 → "1.2k", 1234567 → "1.2M". Exact below 1000, because "3 tokens" reads better than "0.0k".

func HumanDuration

func HumanDuration(d time.Duration) string

HumanDuration renders an elapsed time the way a progress line wants it: sub-second work in milliseconds, seconds with one decimal until it stops being interesting, then m/s. Never wider than 7 columns.

func RuneWidth

func RuneWidth(r rune) int

RuneWidth approximates the terminal column count of r: East Asian and emoji ranges render double-wide, control and combining marks zero. A compact table — full wcwidth tables are overkill for a line editor.

func Truncate

func Truncate(s string, max int, unicode bool) string

Truncate clips s to at most max columns, marking the cut. It measures in columns rather than runes so a CJK status line cannot overflow into a second physical row — which would break the \r-based repaint of the status line.

func TruncateTail

func TruncateTail(s string, max int, unicode bool) string

TruncateTail is Truncate from the other end: it keeps the LAST max columns and marks the cut at the front. A live preview of text still arriving wants the newest words on screen, not the oldest.

Types

type Palette

type Palette struct {
	// contains filtered or unexported fields
}

Palette carries the terminal's presentation capabilities: whether colour may be emitted, whether 24-bit colour is available (the brand green degrades to plain green without it), and whether non-ASCII glyphs render at all — a bare Linux VT has the encoding but not the font.

The zero Palette is the safe one: no colour, no unicode. That makes it the right default for pipes, CI logs and tests.

func New

func New(tty, unicode bool) Palette

New builds a palette for a stream. tty says whether that stream is a terminal; unicode whether non-ASCII glyphs are expected to render. Both are facts the caller already knows (cmd/panda has stdoutIsTTY and termSupportsUnicode); the environment overrides below are ours to apply.

func Plain

func Plain() Palette

Plain is the no-styling palette: every method returns its argument. Used for piped output, --json paths and tests.

func (Palette) Accent

func (p Palette) Accent(s string) string

Accent is the OpenPanda wordmark green — the one place a 24-bit terminal gets the exact brand colour and everything else gets plain green.

func (Palette) Blue

func (p Palette) Blue(s string) string

func (Palette) Bold

func (p Palette) Bold(s string) string

The base vocabulary. Semantic names live below; these stay for the handful of places that genuinely mean "this word is yellow".

func (Palette) Command

func (p Palette) Command(s string) string

Command tints a literal the user can type back (a subcommand, a slash command, a flag) so scanning help output lands on the actionable words.

func (Palette) Cyan

func (p Palette) Cyan(s string) string

func (Palette) Danger

func (p Palette) Danger(s string) string

func (Palette) Dim

func (p Palette) Dim(s string) string

func (Palette) Enabled

func (p Palette) Enabled() bool

Enabled reports whether this palette emits colour.

func (Palette) Glyph

func (p Palette) Glyph(uni, ascii string) string

Glyph picks between a unicode glyph and its ASCII stand-in.

func (Palette) Green

func (p Palette) Green(s string) string

func (Palette) Heading

func (p Palette) Heading(s string) string

Heading is a section title: bold, and accent-coloured when colour is on.

func (Palette) Info

func (p Palette) Info(s string) string

func (Palette) Italic

func (p Palette) Italic(s string) string

func (Palette) Magenta

func (p Palette) Magenta(s string) string

func (Palette) MarkArrow

func (p Palette) MarkArrow() string

func (Palette) MarkBullet

func (p Palette) MarkBullet() string

func (Palette) MarkFail

func (p Palette) MarkFail() string

func (Palette) MarkOK

func (p Palette) MarkOK() string

Mark glyphs for finished lines: success, failure, and the neutral bullet that prefixes progress notes.

func (Palette) Muted

func (p Palette) Muted(s string) string

func (Palette) Red

func (p Palette) Red(s string) string

func (Palette) SGR

func (p Palette) SGR(code, s string) string

SGR wraps s in an arbitrary SGR parameter string ("1;33"). Prefer the named methods; this is the escape hatch for callers with a code already in hand.

func (Palette) Separator

func (p Palette) Separator() string

Separator is the mid-line divider used between status fields and in the banner's hint list.

func (Palette) Success

func (p Palette) Success(s string) string

Semantic layer. Call these from feature code so a later theme change is one edit here rather than a grep for "33".

func (Palette) Unicode

func (p Palette) Unicode() bool

Unicode reports whether non-ASCII glyphs are expected to render.

func (Palette) Warn

func (p Palette) Warn(s string) string

func (Palette) Yellow

func (p Palette) Yellow(s string) string

type PhaseRecord added in v0.0.7

type PhaseRecord struct {
	Name  string // stable id: "classify" | "route" | "exec" | "done"
	Label string // human label
	Start time.Time
	Dur   time.Duration // zero means still active
}

PhaseRecord is one finished (or in-flight) orbit step.

type Status

type Status struct {
	// contains filtered or unexported fields
}

Status is a live one-line progress indicator. Construct with NewStatus; all methods are safe to call from any goroutine, and every one of them is a no-op on a Status that is not running, so callers need no state of their own.

func NewStatus

func NewStatus(w io.Writer, p Palette, live bool) *Status

NewStatus builds a status line writing to w. live enables the animation and in-place repainting; pass false for anything that is not an interactive terminal.

func (*Status) Elapsed

func (s *Status) Elapsed() time.Duration

Elapsed is the run's duration — live while running, frozen after Stop.

func (*Status) Hint

func (s *Status) Hint(h string)

Hint sets a dimmed trailing hint, typically the interrupt key.

func (*Status) Log

func (s *Status) Log(line string)

Log prints one permanent line above the status line.

func (*Status) Note

func (s *Status) Note(n string)

Note sets the trailing detail on the status line ("running tool memory_get"). It is ephemeral — use Log for something the user should still see afterwards.

func (*Status) Phase added in v0.0.7

func (s *Status) Phase(name, label string)

Phase advances the orbit's phase chain. name is a stable id the caller can re-enter to correct an earlier optimistic guess; label is the user-facing text. If the phase is already current the call is a no-op so the caller never needs to track whether it already fired.

Completes any previously in-flight phase and prints a lightweight progress summary to .note ("classify → route → executing"), which keeps the full render chrome untouched (§D3 render is still handled by the front-end DecisionOrbit component; CLI here only gives at-a-glance parity).

func (*Status) PhaseHistory added in v0.0.7

func (s *Status) PhaseHistory() []PhaseRecord

PhaseHistory returns a shallow copy of the phase record list — for the closing summary line. Live durations are resolved at call time.

func (*Status) Preview

func (s *Status) Preview(text string)

Preview shows a live tail of text that is still arriving — the words the model has streamed since the last line break. Without it a long paragraph looks identical to a stalled request: the spinner turns and nothing else moves until a newline finally lands. Whatever does not fit is cut from the FRONT, so the newest words are the ones on screen. Passing "" clears it.

func (*Status) Running

func (s *Status) Running() bool

Running reports whether a run is in flight.

func (*Status) SetInterval

func (s *Status) SetInterval(d time.Duration) *Status

SetInterval overrides the frame interval (tests use a fast one).

func (*Status) SetTokenWord

func (s *Status) SetTokenWord(w string) *Status

SetTokenWord supplies the translated word for the token unit.

func (*Status) SetTokens

func (s *Status) SetTokens(n int64)

SetTokens updates the token counter shown on the line. Zero hides it.

func (*Status) SetWidth

func (s *Status) SetWidth(fn func() int) *Status

SetWidth supplies the terminal width, re-read on every paint so a resized window is honoured immediately. Without it the line is never truncated.

func (*Status) Start

func (s *Status) Start(verb string)

Start begins a run with verb as the current activity ("thinking", "routing"). Calling Start on an already-running status just changes the verb, so a caller that cannot tell whether a previous run ended is still correct.

func (*Status) Stats

func (s *Status) Stats() string

Stats renders the run's numbers for a closing line: "2.3s · 1.2k tokens". Empty when there is nothing to report.

func (*Status) Stop

func (s *Status) Stop() time.Duration

Stop ends the run, erases the status line and returns how long it took. It is idempotent, so `defer st.Stop()` alongside an explicit Stop is fine.

func (*Status) Suspend

func (s *Status) Suspend(f func())

Suspend runs f with the status line off the screen and repaints afterwards. This is how anything else prints during a run — streamed answer text, a completion notice from the task watcher — without fighting the spinner for the cursor.

func (*Status) Verb

func (s *Status) Verb(v string)

Verb changes the activity word mid-run. Silent when not animating: the verb is a live detail, and reprinting a line per change would be noise.

Jump to

Keyboard shortcuts

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