ui

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package ui provides terminal UI helpers for the ToolHive CLI.

Package ui provides shared styling helpers for the ToolHive CLI.

Index

Constants

View Source
const PillWidth = 13 // "● unhealthy" + 2 padding = longest

PillWidth is the fixed visible width of a status pill (for column alignment).

Variables

View Source
var (
	ColorGreen  = lipgloss.Color("#9ece6a")
	ColorRed    = lipgloss.Color("#f7768e")
	ColorYellow = lipgloss.Color("#e0af68")
	ColorBlue   = lipgloss.Color("#7aa2f7")
	ColorPurple = lipgloss.Color("#bb9af7")
	ColorCyan   = lipgloss.Color("#7dcfff")
	ColorDim    = lipgloss.Color("#4a5070")
	ColorDim2   = lipgloss.Color("#6272a4")
	ColorText   = lipgloss.Color("#c0caf5")
	// ColorBg is the main TUI background — the same dark tone used by the statusbar.
	ColorBg = lipgloss.Color("#1e2030")
)

Tokyo Night palette

Functions

func PadLeftToWidth added in v0.26.0

func PadLeftToWidth(s string, w int) string

PadLeftToWidth right-aligns s within width w by prepending spaces. If s is already wider, it is returned unchanged.

func PadToWidth added in v0.26.0

func PadToWidth(s string, w int) string

PadToWidth pads s (which may contain ANSI escapes) so its visible width equals w. If s is already wider, it is returned unchanged.

func RenderClientStatusTable

func RenderClientStatusTable(clientStatuses []client.ClientAppStatus) error

RenderClientStatusTable renders the client status table to stdout.

func RenderCommandUsage added in v0.26.0

func RenderCommandUsage(cmd *cobra.Command)

RenderCommandUsage prints a styled usage hint for a command when the user omits required arguments. Falls back to cmd.Usage() on non-TTY output.

func RenderDim added in v0.26.0

func RenderDim(s string) string

RenderDim returns a dim-styled string.

func RenderGroupChip added in v0.26.0

func RenderGroupChip(group string) string

RenderGroupChip returns a bordered group name tag.

func RenderHelp added in v0.26.0

func RenderHelp(cmd *cobra.Command)

RenderHelp prints the styled help page. - Root command: 2-column command grid - Parent commands with subcommands: styled subcommand list - Non-TTY or leaf commands: falls back to cmd.Usage()

func RenderKey added in v0.26.0

func RenderKey(key string) string

RenderKey returns a dim-styled label for key-value displays.

func RenderLogLine added in v0.26.0

func RenderLogLine(line string) string

RenderLogLine colorizes a log line based on detected severity level.

func RenderPort added in v0.26.0

func RenderPort(port string) string

RenderPort returns a bold cyan port number string.

func RenderRegisteredClientsTable added in v0.2.8

func RenderRegisteredClientsTable(registeredClients []RegisteredClient, hasGroups bool) error

RenderRegisteredClientsTable renders the registered clients table to stdout.

func RenderSection added in v0.26.0

func RenderSection(title string) string

RenderSection renders a section heading (e.g. "Permissions").

func RenderServerTypeBadge added in v0.26.0

func RenderServerTypeBadge(isRemote bool) string

RenderServerTypeBadge returns a styled badge for container vs remote server type.

func RenderStars added in v0.26.0

func RenderStars(n int) string

RenderStars returns a yellow star count string.

func RenderStatusDot added in v0.26.0

func RenderStatusDot(status rt.WorkloadStatus) string

RenderStatusDot returns a colored bullet for the given WorkloadStatus.

func RenderStatusPill added in v0.26.0

func RenderStatusPill(status rt.WorkloadStatus) string

RenderStatusPill returns a badge with background color for the given status.

func RenderText added in v0.26.0

func RenderText(s string) string

RenderText returns a text-colored string.

func RenderTierBadge added in v0.26.0

func RenderTierBadge(tier string) string

RenderTierBadge returns a styled badge for the registry tier.

func RunClientSetup

func RunClientSetup(
	clients []client.ClientAppStatus,
	availableGroups []*groups.Group,
) ([]client.ClientAppStatus, []string, bool, error)

RunClientSetup runs the interactive client setup and returns the selected clients, groups, and whether the user confirmed.

func VisibleLen added in v0.26.0

func VisibleLen(s string) int

VisibleLen returns the number of visible characters in s, stripping ANSI escape sequences and counting multi-byte UTF-8 codepoints as one character.

Types

type RegisteredClient added in v0.2.8

type RegisteredClient struct {
	Name   string
	Groups []string
}

RegisteredClient represents a registered client with its associated groups

type Spinner added in v0.26.0

type Spinner struct {
	// contains filtered or unexported fields
}

Spinner is a simple TTY-only spinner that shows animated progress. All methods are no-ops when stdout is not a terminal.

func NewSpinner added in v0.26.0

func NewSpinner(msg string) *Spinner

NewSpinner creates a new Spinner with the given message.

func (*Spinner) Checkpoint added in v0.26.0

func (s *Spinner) Checkpoint(doneMsg string)

Checkpoint commits the current step as done (prints ✓ doneMsg) and keeps the spinner running. Safe to call from any goroutine.

func (*Spinner) Fail added in v0.26.0

func (s *Spinner) Fail(errMsg string)

Fail halts the spinner and prints a final error line.

func (*Spinner) Start added in v0.26.0

func (s *Spinner) Start()

Start launches the spinner goroutine. Call Stop or Fail to end it.

func (*Spinner) Stop added in v0.26.0

func (s *Spinner) Stop(successMsg string)

Stop halts the spinner and prints a final success line.

func (*Spinner) Update added in v0.26.0

func (s *Spinner) Update(msg string)

Update changes the spinner message while it is running.

type TUILogHandler added in v0.26.0

type TUILogHandler struct {
	// contains filtered or unexported fields
}

TUILogHandler is an end-of-pipeline slog.Handler that sends formatted WARN/ERROR records to a channel so the TUI can display them inside the dashboard instead of writing to stderr (which would corrupt the alt-screen rendering).

Because TUILogHandler is a terminal handler (it formats and dispatches records directly rather than delegating to an inner handler), it does not support WithAttrs/WithGroup chaining. Callers must not rely on slog.Logger.With to attach attributes through this handler; any attributes present on a record are inlined in Handle instead.

func NewTUILogHandler added in v0.26.0

func NewTUILogHandler(ch chan<- string, level slog.Level) *TUILogHandler

NewTUILogHandler creates a TUILogHandler that sends records to ch.

func (*TUILogHandler) Enabled added in v0.26.0

func (h *TUILogHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled reports whether the handler handles records at the given level.

func (*TUILogHandler) Handle added in v0.26.0

func (h *TUILogHandler) Handle(_ context.Context, r slog.Record) error

Handle formats and sends a log record to the channel.

func (*TUILogHandler) WithAttrs added in v0.26.0

func (h *TUILogHandler) WithAttrs(_ []slog.Attr) slog.Handler

WithAttrs returns the receiver unchanged. TUILogHandler is an end-of-pipeline handler; pre-bound attributes from slog.Logger.With are silently dropped. See the type doc comment for details.

func (*TUILogHandler) WithGroup added in v0.26.0

func (h *TUILogHandler) WithGroup(_ string) slog.Handler

WithGroup returns the receiver unchanged. TUILogHandler is an end-of-pipeline handler; group scoping from slog.Logger.WithGroup is silently ignored. See the type doc comment for details.

Jump to

Keyboard shortcuts

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