ui

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 7 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 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

View Source
const (
	ThemeAuto  = "auto"
	ThemeDark  = "dark"
	ThemeLight = "light"
)

Theme modes of ui.theme.

View Source
const Gutter = 1

Gutter is the padding on each side of the divider between two columns.

Variables

View Source
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

func Apply(mode string, detect func() (dark bool, ok bool))

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

func Card(o CardOpts) string

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 Chip

func Chip(text string) string

Chip is a small dim tag: "[text]".

func Header(left, right string, width int) string

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

func HintBar(hints []Hint, width int) string

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

func InputBox(view, placeholder string, width int, focused bool, chips string) string

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 IsDark

func IsDark() bool

IsDark reports the theme chosen by Apply; dark until Apply runs.

func JoinColumns

func JoinColumns(width int, cols ...Column) string

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

func ListRow(o RowOpts) string

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

func Overlay(title string, body []string, hints []Hint, width int) string

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 PaneLabel

func PaneLabel(text string, focused bool, width int) string

PaneLabel names a pane: dim, or normal weight bold when the pane has focus.

func PlaceAt

func PlaceAt(base, overlay string, x, y, w, h int) string

PlaceAt draws overlay over base with its top-left corner at (x, y) in a w x h screen.

func PlaceOverlay

func PlaceOverlay(base, overlay string, w, h int) string

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

func RightAlign(left, right string, width int) string

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

func TerminalDark() (dark bool, ok bool)

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 Truncate

func Truncate(s string, w int) string

Truncate cuts s to at most w cells, ending in "…" when it was cut.

func TruncateMiddle

func TruncateMiddle(s string, w int) string

TruncateMiddle cuts s to at most w cells by dropping its middle, which keeps both ends of a path: "internal/…/model.go".

func VDivider

func VDivider(height int) string

VDivider is a vertical line of height rows in Border.

func ValidTheme

func ValidTheme(mode string) bool

ValidTheme reports whether mode is a value ui.theme accepts ("" counts as auto).

Types

type CardOpts

type CardOpts struct {
	Title, Meta      string
	Body             []string
	Width            int
	Selected, Failed bool
}

CardOpts describes a Card.

type Column

type Column struct {
	Width int
	Body  string
}

Column is one column of JoinColumns: Body is cut or padded to Width.

type Hint

type Hint struct{ Key, Label string }

Hint is one "key label" pair of a HintBar.

type RowOpts

type RowOpts struct {
	Left, Right string
	Width       int
	Selected    bool
	Indent      int // spaces before Left
}

RowOpts describes a ListRow.

Jump to

Keyboard shortcuts

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