tui

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 18 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 tui is the interactive dashboard's rendering layer: the row cells, the gauge, the state map, and eventually the whole page.

Package tui is ccdad's terminal dashboard.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handles

func Handles(b key.Binding) bool

Handles reports whether the dashboard does something with a binding, on any of its screens.

It exists because a keybar that offers a key the model ignores is a string painted on a terminal that nothing else in this repository reads, and the test that catches it lives in the package that registers the command. It runs the binding's own keys through the same switch Update runs rather than re-listing them: a predicate built from a second list would go on passing for a dashboard that handled nothing.

It asks about every screen because the help view advertises keys that live on one of them -- enter belongs to a picker, and three of them belong to the daemon screen and are offered nowhere else.

func Render

func Render(o Options) (string, error)

Render is the one-shot, non-TTY page: load, draw at the design target with no height ladder, and write it.

A failed load here is fatal rather than a notice, and that is not a second rule: AfterLoad keeps the PREVIOUS snapshot, and a one-shot render has none. There is nothing to keep and nothing to label.

func Run

func Run(o Options) error

Run drives the dashboard until the user quits.

THE OPTION LIST IS EMPTY, AND THAT IS THE POINT. The two that are missing are WithoutSignalHandler and WithoutSignals, and leaving them out is a shutdown property rather than a default nobody thought about. With the library's own handler in place, a SIGTERM arriving in raw mode is turned into an ordinary quit: the loop returns, the terminal is put back to echo, canonical input and signal generation, and this returns nil. With the handler removed, the same SIGTERM kills the process outright with status 15 and leaves the terminal in raw mode -- the shell the user goes back to has no echo, no line editing and no Ctrl-C.

Ctrl-C is an ordinary key while nothing is released: the terminal is in raw mode, so it arrives as a keystroke rather than a signal, there is no scoped trap to fight, and signals are not being ignored. During the add key's released span both signals are dropped, which is documented where that key is written.

A panic inside the model is caught by the program's own recover, the terminal is restored, and this returns the killed-program error. The dashboard still dies, which is correct: a renderer that panicked has nothing useful left to show.

AN INTERRUPT IS NOT A FAILURE, and this is where that is decided. The library routes SIGTERM to an ordinary quit and SIGINT to an interrupt, and the two take the same shutdown path and leave the terminal in the same state -- the only difference is that one comes back as an error. Passing it on would make `kill -INT` print a message and exit non-zero where `kill -TERM` is silent and exits 0, for two ways of asking the same program to stop. It is worded the way the login's own interrupted exit is worded: the user's decision, not a fault.

Options.Out is not passed through, and the reason is not that the library cannot take a writer -- it can. It is that Out is where the ONE-SHOT render writes, downstream of a colour decision package cli has already made, and a program makes that decision for itself by probing the terminal it was given. Handing it a writer that has already answered would be two answers to one question.

Types

type App

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

App is the dashboard as a running program: the page, the injected world, and which of the five screens is showing.

The page itself is Model, which is pure and stays pure. Everything with a clock, a terminal or a signal disposition is here.

func (App) Init

func (a App) Init() tea.Cmd

Init loads once and starts both clocks.

The startup read goes through a message rather than straight to the seam, because Init hands back a command and not a model -- and the flag that says a read is in flight lives on the model.

func (App) Update

func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update is the whole event loop. Every arm that schedules ends by returning the next tick, which is what makes "at most one outstanding" a property of the code rather than of the timing.

func (App) View

func (a App) View() tea.View

View is two lines, and that split is the whole reason the page is a pure string: everything above this point can be asserted with a string comparison, and nothing below it can be.

AltScreen is a declarative field on the returned view. There is no WithAltScreen option to pass to the program, and inline is the default.

type Column

type Column int

Column identifies one field of the two shipping tables. ColIdx through ColAuto are SetStatus's eight columns; ColTier and ColLeft are the two SetList carries instead of ColUsed, ColWindow, ColState and ColAuto.

const (
	ColIdx Column = iota
	ColAccount
	ColType
	ColUsed
	ColWindow
	ColResets
	ColState
	ColAuto
	ColTier
	ColLeft
)

type ColumnSet

type ColumnSet int

ColumnSet is which of the two shipping tables the page is showing. [L] swaps between them; the heading changes with the polarity, so USED and LEFT never share a heading. Plan is the first thing in this package that needs the distinction, so it is declared here rather than left undeclared until something else does.

const (
	SetStatus ColumnSet = iota // IDX ACCOUNT TYPE USED WINDOW RESETS IN STATE AUTO
	SetList                    // IDX ACCOUNT TYPE TIER LEFT RESETS IN
)

type KeyMap

type KeyMap struct {
	Add, Switch, Daemon, Strategy, Quit, List key.Binding
	Up, Down, Refresh, Help, Esc, Enter       key.Binding
	Start, Stop, Restart                      key.Binding
}

KeyMap is every binding the dashboard answers to. Add through List are the six the keybar advertises; Up through Enter are movement and dismissal, shown only in the long help; Start through Restart belong to the daemon screen and are not offered anywhere else.

func DefaultKeys

func DefaultKeys() KeyMap

DefaultKeys is the one KeyMap this program has.

func (KeyMap) FullHelp

func (k KeyMap) FullHelp() [][]key.Binding

FullHelp groups every binding for the long help view: the keybar's six, then movement and dismissal, then the daemon screen's three.

func (KeyMap) ShortHelp

func (k KeyMap) ShortHelp() []key.Binding

ShortHelp returns the keybar's six, in the order a, s, d, c, q, l. help truncates from the right, so this order is a safety property and not a preference: losing l costs nothing, because the table already is the list, and losing q strands a user in a full-screen program with no advertised way out. Being fifth of six rather than sixth is what buys q the room it has -- it is not a guarantee q survives every width. Measured against the rendered bar (see keybar's own tests): q is entirely absent below width 45, and present at 45 and every width above it.

type Layout

type Layout struct {
	Columns     []Column
	AccountWide int
	Collapsed   bool // USED is the bare percentage, not the gauge

	Wordmark, Tagline, Figures bool
	Notice                     bool // the "note: ..." line; see Plan's notice parameter
	Runway                     bool // the "Runway: ..." line; see Plan's runway parameter
	Border, Blanks             bool
	Title, Header              bool // Header is the Active/Strategy/Mode line

	// VisibleRows is an UPPER BOUND on how many account rows to render, not a
	// count of rows that are actually shown: at the scrolling rung the last
	// of them is spent on "+K more (j/k)" rather than an account row, and
	// below that rung it is clamped to the real row count so a renderer
	// slicing Rows[Top:Top+VisibleRows] never reads past the end.
	VisibleRows int

	TooNarrow, TooShort bool
}

Layout is the answer to "what fits", computed once per frame from the terminal size and the row count, and read by nothing but the renderer: it carries no styling and touches no string.

func Plan

func Plan(set ColumnSet, width, height, rows int, notice, runway bool) Layout

Plan reads nothing and calls nothing: it is a pure function of the six arguments, so the same (set, width, height, rows, notice, runway) always answers the same way and a test can walk every boundary without a terminal.

notice is whether Snapshot.Notices is non-empty. Plan has no other way to find out: it takes no Snapshot, so a caller with a notice to show has to say so directly. A page with a notice needs one more row than the same page without one — the notice line itself — and that row is spent or reclaimed by the height ladder exactly like any other block.

runway is whether there is a runway line to draw — the measured-burn summary, which exists only once enough readings have been recorded to give a rate, and is therefore absent on every machine for the first hours after it starts recording. It arrives as a bool for the reason notice does, and it costs the same one row. It is deliberately NOT folded into fixedRows below: that constant is the sum of every UNCONDITIONAL row, and raising it would shift every threshold on the height ladder for pages that draw no runway line at all.

The defect this guards against was reproduced before this existed: with ACCOUNT computed as "whatever's left" independently at every width, going from 100 columns to 105 columns took ACCOUNT from 24 down to 12, because 105 crossed the threshold that puts WINDOW back on the page and WINDOW's cost came out of the one flex column. Widening a terminal must never narrow an address. The fix implemented below is to hold ACCOUNT at its comfort width while columns are added back one at a time, and to only let it grow once every optional column for the current table is already on the page — so crossing a column threshold can never claim width ACCOUNT already had.

type Model

type Model struct {
	Snap   view.Snapshot
	Set    ColumnSet
	Width  int
	Height int
	Cursor int // index into Snap.Rows
	Top    int // first visible row, for the scrolling rung of the height ladder
	Gauge  progress.Model
	Help   help.Model
	Keys   KeyMap
}

Model is the whole page as data. Body is pure: no Program, no clock, no filesystem. Every field it will ever carry is declared here, so the event loop that arrives later adds methods to this type and no fields.

func (Model) AfterLoad

func (m Model) AfterLoad(snap view.Snapshot, err error) Model

AfterLoad folds one Load result into the page.

A failed load KEEPS the previous snapshot and adds one notice. The two alternatives are both worse and both silent: emptying the table hides accounts that are still there and reads as "you have none", and leaving the previous numbers unlabelled presents a reading from before the failure as the current one. The notice is the label, and it is what makes keeping the numbers honest rather than stale.

A load that succeeds replaces the snapshot whole, which is what takes the notice away again — there is no separate clearing step to forget.

func (Model) Body

func (m Model) Body() string

Body is the whole page as one string.

It reads nothing: the layout comes from Plan, which is a pure function of four numbers, and every cell comes from a Snapshot somebody else built. That is what makes the fixtures below comparable as whole strings.

type Options

type Options struct {
	// Load is one complete read of the documents the dashboard renders. It
	// takes the clock rather than reading it, so a caller can pin time.
	//
	// A failed Load is not fatal and must not empty the table — see
	// Model.AfterLoad, which is the rule that says what happens instead.
	Load func(now time.Time) (view.Snapshot, error)
	// Exec runs one ccdad command through a FRESH cobra root. Every key that
	// changes anything goes through here rather than calling an internal, so
	// the scoped-session refusal, the wording and the exit contract all stay
	// in one authority.
	Exec view.Exec
	// Now is the clock. It is a function value because nothing in this package
	// may call time.Now itself.
	Now func() time.Time
	// Out is where the one-shot render writes.
	Out io.Writer
	// StderrTTY is whether stderr is a terminal, probed by package cli beside
	// the two probes that already exist there. It gates the add key: the login
	// writes every line of its prose to stderr, and bubbletea hands a released
	// child os.Stderr rather than the Program's own output, so under a
	// redirect the prompt would vanish while the dashboard sat blank.
	StderrTTY bool
	// CredentialHome is THIS process's own resolution of the Claude Code
	// credential home, for the [D] screen to compare against the one the
	// daemon published. A daemon started from a shell that resolved a
	// different one manages that directory for the rest of its life and every
	// other file on the machine looks normal; comparing the two is the only
	// way anyone finds out.
	//
	// Empty is a legitimate value -- a caller that could not resolve one --
	// and it omits the warning rather than guessing.
	CredentialHome string
	// SamePath reports whether two spellings name one directory.
	//
	// It is injected rather than called, and that is not ceremony. ccdad
	// manufactures the two spellings of that path itself: daemon.ChildEnv pins
	// an absolute, symlink-resolved one into every daemon it spawns, while a
	// shell's own spelling comes back untouched, so a trailing slash or a
	// symlink is enough to make two names for one directory. Answering it
	// honestly therefore means asking the FILESYSTEM, which is exactly what
	// nothing in this package may do. `doctor` asks the same question and
	// reaches internal/credhome for the answer; package cli hands that same
	// function down here.
	//
	// nil means the caller cannot compare paths, which omits the warning for
	// the same reason an empty CredentialHome does.
	SamePath func(a, b string) bool
}

Options is everything package cli injects. Nothing in package tui reads the environment, the clock or the filesystem except through one of these — which is what makes the whole page a pure function of data somebody else read, and therefore what makes every visual assertion in this package a string comparison rather than a pty.

The fields are declared here in full, once, even though the two-shot render below uses only three of them: the event loop that arrives later adds METHODS to Model and reads the rest of these, and a field added to a struct three files already read is a merge conflict in the one place this package cannot afford one.

Jump to

Keyboard shortcuts

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