ui

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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()
	Accent color.Color = catppuccin.Mocha.Mauve()
	Dim    color.Color = catppuccin.Mocha.Overlay0()
	Label  color.Color = catppuccin.Mocha.Subtext0()
	Value  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

func AccentBoldStyle() lipgloss.Style

AccentBoldStyle returns a bold accent-colored style.

func BeaconDetailURL added in v0.6.0

func BeaconDetailURL(apiURL, hash string) string

BeaconDetailURL is the hash-keyed variant used only by the beacon listing card (`truestamp beacon {latest,list,get,by-hash}`), 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

func BeaconVerifyURL(apiURL, id string) string

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

func CompactTable() *table.Table

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

func FailureBanner(text string) string

FailureBanner renders a bold red failure message.

func FaintStyle

func FaintStyle() lipgloss.Style

FaintStyle returns a faint/dim style.

func HeaderBox

func HeaderBox(title, subtitle string) string

HeaderBox renders a bordered title box with an optional subtitle.

func HuhTheme

func HuhTheme() huh.Theme

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

func LabelStyle() lipgloss.Style

LabelStyle returns the style for key-value labels.

func LabelValueStyleFunc added in v0.3.0

func LabelValueStyleFunc() func(row, col int) lipgloss.Style

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 SectionHeader

func SectionHeader(name string) string

SectionHeader renders a styled group header with a separator line.

func SubjectDetailURL added in v0.6.0

func SubjectDetailURL(apiURL, typeName, id string) string

SubjectDetailURL returns the subject detail page URL for a download or create card. `typeName` must be one of the six canonical wire values; `id` is the ULID (item) or UUIDv7 (every other type). Returns "" for unknown types or dev-host API URLs.

func SubjectVerifyURL added in v0.6.0

func SubjectVerifyURL(apiURL, typeName, id string) string

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

func SuccessBanner(text string) string

SuccessBanner renders a bold green success message.

func TruncateToSecond added in v0.6.0

func TruncateToSecond(ts string) string

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 — beacon 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

func ValueStyle() lipgloss.Style

ValueStyle returns the style for key-value values.

Types

type PickFileOptions added in v0.3.0

type PickFileOptions struct {
	Title        string
	AllowedTypes []string
}

PickFileOptions configures an interactive file-picker form. Both fields are optional; Title defaults to "Select file" and AllowedTypes to "any file type".

Jump to

Keyboard shortcuts

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