Documentation
¶
Overview ¶
Package ui holds the shared look of every DECSR screen: theme tokens, the theme switch and small pure components that render width-aware strings.
Index ¶
- Constants
- Variables
- func Apply(mode string, detect func() (dark bool, ok bool))
- func Card(o CardOpts) string
- func Chip(text string) string
- func Header(left, right string, width int) string
- func HintBar(hints []Hint, width int) string
- func InputBox(view, placeholder string, width int, focused bool, chips string) string
- func IsDark() bool
- func JoinColumns(width int, cols ...Column) string
- func ListRow(o RowOpts) string
- func Overlay(title string, body []string, hints []Hint, width int) string
- func PaneLabel(text string, focused bool, width int) string
- func PlaceAt(base, overlay string, x, y, w, h int) string
- func PlaceOverlay(base, overlay string, w, h int) string
- func RightAlign(left, right string, width int) string
- func Status(kind string) (glyph, word string, color lipgloss.TerminalColor)
- func TerminalDark() (dark bool, ok bool)
- func Truncate(s string, w int) string
- func TruncateMiddle(s string, w int) string
- func VDivider(height int) string
- func ValidTheme(mode string) bool
- type CardOpts
- type Column
- type Hint
- type RowOpts
Constants ¶
const ( ThemeAuto = "auto" ThemeDark = "dark" ThemeLight = "light" )
Theme modes of ui.theme.
const Gutter = 1
Gutter is the padding on each side of the divider between two columns.
Variables ¶
var ( Text = lipgloss.AdaptiveColor{Dark: "#d5e0f7", Light: "#1f2937"} // titles, body Muted = lipgloss.AdaptiveColor{Dark: "#7d8db3", Light: "#6b7280"} // labels, metadata, hints Border = lipgloss.AdaptiveColor{Dark: "#2f4270", Light: "#d0d7e2"} // dividers, card borders Accent = lipgloss.AdaptiveColor{Dark: "#7c9cff", Light: "#3b5bdb"} // brand, focus, running OK = lipgloss.AdaptiveColor{Dark: "#6ff2b4", Light: "#2f9e44"} // done, + lines Warn = lipgloss.AdaptiveColor{Dark: "#ffd166", Light: "#b7791f"} // waiting, needs you, budget Fail = lipgloss.AdaptiveColor{Dark: "#ff5c7a", Light: "#d6336c"} // failed, - lines Sel = lipgloss.AdaptiveColor{Dark: "#1c2b4d", Light: "#e7ecfb"} // background of the selected row or card // Brand colours of runner glyphs. Claude = lipgloss.AdaptiveColor{Dark: "#D97757", Light: "#c15f3c"} DeepSeek = lipgloss.AdaptiveColor{Dark: "#4D6BFE", Light: "#3b54d9"} // Diff tints: the background of added and removed lines. DiffAdd = lipgloss.AdaptiveColor{Dark: lerpHex("#0b1426", "#6ff2b4", 0.16), Light: lerpHex("#ffffff", "#2f9e44", 0.16)} DiffDel = lipgloss.AdaptiveColor{Dark: lerpHex("#0b1426", "#ff5c7a", 0.18), Light: lerpHex("#ffffff", "#d6336c", 0.18)} )
Theme tokens. Each is an adaptive colour, so one switch (Apply) flips every style built from them.
Functions ¶
func Apply ¶
Apply selects the theme once at startup, before the Bubble Tea program starts and before the first render. "dark" and "light" force it. "auto", "" and any invalid value ask detect (nil uses TerminalDark) and fall back to dark when it reports not-ok.
detect runs synchronously on the caller's goroutine and Apply starts no goroutine, so nothing can still be reading the terminal after Apply returns. A custom detector must therefore return promptly on its own.
func Card ¶
Card is a rounded box: the title in bold with Meta dim at the right on the first line, then Body. The border is Accent when selected, Fail when failed and Border otherwise; a selected card is filled with Sel. Width includes the border; below 5 cells the card is empty.
func Header ¶
Header is the top line of a screen: the brand glyph in Accent, left in Text and right in Muted at the right edge. The left side is truncated first.
func HintBar ¶
HintBar renders "key label · key label" in at most width cells: the key in Text, the label in Muted. Trailing hints are dropped until the bar fits.
func InputBox ¶
InputBox wraps the view of a text input in a rounded box of width cells. An empty view shows the placeholder dim. The border is Accent when focused. chips, when set, is a dim row under the input.
func JoinColumns ¶
JoinColumns places columns side by side, separated by a single "│" in Border, and never exceeds width. Column.Width includes the gutter: one space on each side of the divider, so text never touches it (a body should be built Gutter cells narrower per inner side). A column that does not fit is narrowed or dropped. Every row has the same width.
func ListRow ¶
ListRow is one row of a list, exactly Width cells wide. A selected row gets the Sel background across the whole width and a "▌" cursor in Accent.
func Overlay ¶
Overlay draws a titled box of width cells around body lines: a rounded Accent border with the title in its top edge and, when hints are given, a hint bar as the last row. Lines are cut to fit.
func PlaceAt ¶
PlaceAt draws overlay over base with its top-left corner at (x, y) in a w x h screen.
func PlaceOverlay ¶
PlaceOverlay draws overlay (multi-line) centred over base in a w x h screen, leaving the first and last line of base alone when it fits between them. The rows it covers are blanked on both sides.
func RightAlign ¶
RightAlign puts right at the right edge of a line of width cells. The left side is truncated first; when right alone is too wide it is cut and left is dropped. A result never exceeds width.
func Status ¶
func Status(kind string) (glyph, word string, color lipgloss.TerminalColor)
Status gives the glyph, word and colour of a status kind: todo, ready, blocked, running, done, failed, waiting, limited, unassigned or stalled. An unknown kind is a dim dot with the kind as its word. Status is always shown as glyph and word, never by colour alone.
func TerminalDark ¶
TerminalDark is the default detector. It asks the terminal for its background colour, but only when that is safe and reliable: stdin and stdout are terminals, $TERM is not "dumb", and the program is not inside tmux or screen (they cannot answer for the outer terminal). Otherwise it reports not-ok, which means dark.
The query is termenv's: it runs on the calling goroutine, reads the answer with select-based waits bounded by the library, and restores the terminal mode before returning, so no goroutine or pending read outlives the call.
func TruncateMiddle ¶
TruncateMiddle cuts s to at most w cells by dropping its middle, which keeps both ends of a path: "internal/…/model.go".
func ValidTheme ¶
ValidTheme reports whether mode is a value ui.theme accepts ("" counts as auto).