Documentation
¶
Overview ¶
Package ui renders treewright's interactive terminal pieces.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCancelled = errors.New("cancelled")
ErrCancelled reports that the user dismissed the picker, or that there was no terminal to prompt on. Callers treat it as "do nothing", not as a failure.
Functions ¶
func ColorEnabled ¶
ColorEnabled reports whether ANSI color is appropriate for w.
Three conditions must hold, and each rules out a way color goes wrong: NO_COLOR must be unset or empty (the no-color.org convention, which any value honors), TERM must not be "dumb", and w must be a terminal — so redirected or piped output never carries escape sequences into a file or a parser.
func Pick ¶
Pick shows a numbered menu on w and returns the zero-based index the user chose, or ErrCancelled.
Keys are read from /dev/tty rather than stdin so the picker still works when stdin has been redirected. With no controlling terminal there is nobody to prompt, so it cancels instead of hanging.
Types ¶
type Color ¶
type Color uint8
Color is a display attribute for one piece of text.
The attributes treewright uses. Plain is the zero value, so a Cell that names no color renders as the terminal's own foreground rather than as a chosen one.
type Table ¶
Table lays out rows in columns sized to their contents.
Sizing from content is the point: a fixed column width silently misaligns every subsequent column as soon as one value is longer than the guess, and worktree slugs have no bounded length.
func (*Table) Lines ¶
Lines renders the table as a header line plus one line per row.
Returning lines rather than writing them lets the same table feed both plain output and the interactive picker, which needs each row as a separate label.
Padding is computed from cell text only, never from the styled string: escape sequences occupy no columns, so measuring them would break alignment exactly when color is on.