Documentation
¶
Overview ¶
Package ui provides shared styling for the Truestamp CLI using lipgloss v2. Colors are sourced from the Catppuccin palette (Latte for light terminals, Mocha for dark). The same palette is used for both static lipgloss output and interactive huh components via HuhTheme().
IMPORTANT: Color initialization is deferred to Init() to avoid terminal queries at package init time. Querying the terminal (for dark/light background detection) in a background process group causes SIGTTIN, which hangs shell completion via source <(truestamp completion zsh).
Index ¶
- Variables
- func AccentBoldStyle() lipgloss.Style
- func BeaconDetailURL(apiURL, hash string) string
- func BeaconVerifyURL(apiURL, id string) string
- func CompactTable() *table.Table
- func FailureBanner(text string) string
- func FaintStyle() lipgloss.Style
- func Fprint(w io.Writer, a ...any) (int, error)
- func Fprintf(w io.Writer, format string, a ...any) (int, error)
- func Fprintln(w io.Writer, a ...any) (int, error)
- func HeaderBox(title, subtitle string) string
- func HeaderRowStyleFunc() func(row, col int) lipgloss.Style
- func HintStyle() lipgloss.Style
- func HuhTheme() huh.Theme
- func Init(noColor bool)
- func LabelStyle() lipgloss.Style
- func LabelValueStyleFunc() func(row, col int) lipgloss.Style
- func PickFile(opts PickFileOptions) (string, error)
- func ProfileWriter(w io.Writer) io.Writer
- func SectionHeader(name string) string
- func SubjectDetailURL(apiURL, typeName, id string) string
- func SubjectVerifyURL(apiURL, typeName, id string) string
- func SuccessBanner(text string) string
- func TeamCreateURL(apiURL string) string
- func TeamDetailURL(apiURL, teamID string) string
- func TruncateToSecond(ts string) string
- func ValueStyle() lipgloss.Style
- type PickFileOptions
Constants ¶
This section is empty.
Variables ¶
var ( Green color.Color = catppuccin.Mocha.Green() Red color.Color = catppuccin.Mocha.Red() Yellow color.Color = catppuccin.Mocha.Yellow() Blue color.Color = catppuccin.Mocha.Blue() Cyan color.Color = catppuccin.Mocha.Sky() Accent color.Color = catppuccin.Mocha.Mauve() Dim color.Color = catppuccin.Mocha.Overlay0() Hint color.Color = catppuccin.Mocha.Subtext1() Label color.Color = catppuccin.Mocha.Subtext0() Value color.Color = catppuccin.Mocha.Text() Banner color.Color = catppuccin.Mocha.Text() )
Color variables. Defaults to dark (Mocha) palette. Updated by Init() if the terminal has a light background.
Functions ¶
func AccentBoldStyle ¶
AccentBoldStyle returns a bold accent-colored style.
func BeaconDetailURL ¶ added in v0.6.0
BeaconDetailURL is the hash-keyed variant used only by the beacon listing card (`truestamp beacons {latest,list,get}`), where the hash is already in hand from the API response. Distinct from SubjectDetailURL's beacon row (which points at the underlying block's page when only the id is available).
func BeaconVerifyURL ¶ added in v0.6.0
BeaconVerifyURL is a typed alias for readability at the beacon-card call site. Equivalent to SubjectVerifyURL(apiURL, "beacon", id).
func CompactTable ¶ added in v0.6.0
CompactTable returns a lipgloss table with a hidden border AND no top/bottom/left/right border rows. `.Border(HiddenBorder())` on its own still emits invisible top and bottom rows of whitespace, which stacks with section separators in the card / verify-report output and wastes a blank line above and below every table. Using this helper ensures the table content is flush to whatever comes before and after it, letting callers use explicit `""` elements in a `strings.Join` (or a bare newline) for inter-section spacing when they want it. Every post-action card / verify-report table in the CLI routes through this.
func FailureBanner ¶
FailureBanner renders a bold red failure message.
func FaintStyle ¶
FaintStyle returns a faint/dim style. It is for decoration that the reader is not expected to act on. Anything meant to be READ — a hint, a cursor to paste, an empty-state line — uses HintStyle instead.
func Fprintln ¶ added in v0.14.0
Fprintln writes to w through a colour profile writer, so styled text is downsampled or stripped to match what the destination can actually render, and --no-color / NO_COLOR are honored. Use it instead of fmt.Fprintln anywhere the arguments may contain Style.Render output.
func HeaderRowStyleFunc ¶ added in v0.14.0
HeaderRowStyleFunc styles a table whose first row is column labels: bold label colour on row 0, value colour below, the same padding on every cell. Shared by every listing that prints a header row.
func HintStyle ¶ added in v0.15.0
HintStyle returns the style for trailing guidance: the "More:" / "Back:" cursor lines, the "Hint:" tips, and empty-state text.
It is deliberately NOT FaintStyle. That style compounds two dimming effects — an already-low-contrast foreground (Overlay0) plus the ANSI faint attribute (SGR 2), which terminals render by reducing brightness again. Measured against each flavour's base, Overlay0 is 3.36:1 on Mocha and 2.30:1 on Latte: below the WCAG AA 4.5:1 floor on dark and failing outright on light, before the faint attribute is applied at all. Subtext1 is 9.26:1 and 5.53:1, so it clears AA in both themes while still reading as subordinate to Value.
A hint the reader cannot see is not a subtle hint, it is a missing one, and the "More: --after <cursor>" line exists to be copied.
func HuhTheme ¶
HuhTheme returns the Catppuccin theme for huh interactive components. Uses the same Latte/Mocha palette as the static color definitions above.
func Init ¶
func Init(noColor bool)
Init configures the global color profile and detects the terminal's background color. Call once from root command before any output. If noColor is true, all ANSI sequences are stripped. The NO_COLOR env var is handled automatically by lipgloss.
func LabelStyle ¶
LabelStyle returns the style for key-value labels.
func LabelValueStyleFunc ¶ added in v0.3.0
LabelValueStyleFunc returns a lipgloss table StyleFunc that renders the first column as a right-aligned label and subsequent columns as the value. It matches the two-column "key: value" layout used by the create and download summary tables.
func PickFile ¶ added in v0.3.0
func PickFile(opts PickFileOptions) (string, error)
PickFile launches a single-page interactive file picker themed with the CLI's palette and returns the selected path. Returns an error if the user aborts, the form fails, or no file is selected.
func ProfileWriter ¶ added in v0.14.0
ProfileWriter wraps w so ANSI is stripped or downsampled to suit the destination. Detection runs on every call, so a caller writing many lines to one destination (the hash listing) takes the writer once rather than paying for it per line.
func SectionHeader ¶
SectionHeader renders a styled group header with a separator line.
func SubjectDetailURL ¶ added in v0.6.0
SubjectDetailURL returns the subject detail page URL for a download or items create card. `typeName` must be one of the six canonical wire values; `id` is the ULID (item) or UUIDv7 (every other type). Returns "" for an unknown type or an empty apiURL. Dev hosts are NOT filtered: see the package comment above for why that filter was removed.
func SubjectVerifyURL ¶ added in v0.6.0
SubjectVerifyURL returns the typed sub-path verify URL (`{host}/verify/<type>/<id>`). Accepts any of the six canonical types; server-side also accepts bare `entropy` as a convenience form but this CLI sticks to strict subtypes end-to-end.
func SuccessBanner ¶
SuccessBanner renders a bold green success message.
func TeamCreateURL ¶ added in v0.8.0
TeamCreateURL returns the public-web teams URL. The CLI now creates teams itself (truestamp teams create), so this is used as the "manage teams & plans" pointer in the plan-limit-reached hint rather than as the only creation path.
func TeamDetailURL ¶ added in v0.8.0
TeamDetailURL returns the public-web team detail page URL, `{host}/teams/<id>`. Used by `truestamp teams get`. (The empty-state hint of `truestamp teams list` uses TeamCreateURL instead.)
func TruncateToSecond ¶ added in v0.6.0
TruncateToSecond parses an RFC 3339 / ISO 8601 timestamp and re-emits it at second precision (drops fractional seconds). Returns the input string unchanged if it cannot be parsed, so it is safe to chain with already-truncated values. Used by every display site that shows a timestamp to a human, beacons list rows, beacon cards, the verify report's Timeline / Subject / Commitments sections. The `convert` subcommands deliberately bypass this helper because they exist precisely to extract high-precision timestamps from IDs.
func ValueStyle ¶
ValueStyle returns the style for key-value values.
Types ¶
type PickFileOptions ¶ added in v0.3.0
PickFileOptions configures an interactive file-picker form. Both fields are optional; Title defaults to "Select file" and AllowedTypes to "any file type".