Documentation
¶
Overview ¶
Package ui provides terminal UI helpers for the ToolHive CLI.
Package ui provides shared styling helpers for the ToolHive CLI.
Index ¶
- Constants
- Variables
- func PadLeftToWidth(s string, w int) string
- func PadToWidth(s string, w int) string
- func RenderClientStatusTable(clientStatuses []client.ClientAppStatus) error
- func RenderCommandUsage(cmd *cobra.Command)
- func RenderDim(s string) string
- func RenderGroupChip(group string) string
- func RenderHelp(cmd *cobra.Command)
- func RenderKey(key string) string
- func RenderLogLine(line string) string
- func RenderPort(port string) string
- func RenderRegisteredClientsTable(registeredClients []RegisteredClient, hasGroups bool) error
- func RenderSection(title string) string
- func RenderServerTypeBadge(isRemote bool) string
- func RenderStars(n int) string
- func RenderStatusDot(status rt.WorkloadStatus) string
- func RenderStatusPill(status rt.WorkloadStatus) string
- func RenderText(s string) string
- func RenderTierBadge(tier string) string
- func RunClientSetup(clients []client.ClientAppStatus, availableGroups []*groups.Group) ([]client.ClientAppStatus, []string, bool, error)
- func VisibleLen(s string) int
- type RegisteredClient
- type Spinner
- type TUILogHandler
Constants ¶
const PillWidth = 13 // "● unhealthy" + 2 padding = longest
PillWidth is the fixed visible width of a status pill (for column alignment).
Variables ¶
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
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
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
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 RenderGroupChip ¶ added in v0.26.0
RenderGroupChip returns a bordered group name tag.
func RenderHelp ¶ added in v0.26.0
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 RenderLogLine ¶ added in v0.26.0
RenderLogLine colorizes a log line based on detected severity level.
func RenderPort ¶ added in v0.26.0
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
RenderSection renders a section heading (e.g. "Permissions").
func RenderServerTypeBadge ¶ added in v0.26.0
RenderServerTypeBadge returns a styled badge for container vs remote server type.
func RenderStars ¶ added in v0.26.0
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
RenderText returns a text-colored string.
func RenderTierBadge ¶ added in v0.26.0
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
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
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
NewSpinner creates a new Spinner with the given message.
func (*Spinner) Checkpoint ¶ added in v0.26.0
Checkpoint commits the current step as done (prints ✓ doneMsg) and keeps the spinner running. Safe to call from any goroutine.
func (*Spinner) Start ¶ added in v0.26.0
func (s *Spinner) Start()
Start launches the spinner goroutine. Call Stop or Fail to end it.
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
Enabled reports whether the handler handles records at the given level.
func (*TUILogHandler) Handle ¶ added in v0.26.0
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.