output

package
v0.1.0-beta.14 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package output provides terminal output formatting for gridctl with amber color theme.

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorAmber = lipgloss.Color("#f59e0b") // Primary brand color
	ColorWhite = lipgloss.Color("#fafaf9") // text-text-primary
	ColorMuted = lipgloss.Color("#78716c") // text-text-muted
	ColorGreen = lipgloss.Color("#10b981") // status-running
	ColorRed   = lipgloss.Color("#f43f5e") // status-error
	ColorGray  = lipgloss.Color("#a8a29e") // text-text-secondary
)

Amber color theme based on Gridctl web UI design system. Primary amber (#f59e0b) for key elements.

Functions

func ColorEnabled

func ColorEnabled(w io.Writer) bool

ColorEnabled reports whether styled output should be emitted on w. Color is disabled when SetNoColor(true) was called, NO_COLOR is set and non-empty (https://no-color.org/), TERM is "dumb", or w is not a terminal.

func EncodeJSON

func EncodeJSON(w io.Writer, v any) error

EncodeJSON writes v to w as two-space-indented JSON. It is the shared encoder for every command's machine-readable output so schemas render consistently and never carry ANSI escapes.

func IsTerminal

func IsTerminal(w io.Writer) bool

IsTerminal reports whether w is an interactive terminal. Callers use it to gate interactive chrome (spinners, prompts) that must never run against pipes or CI logs.

func NewTableWriter

func NewTableWriter(w io.Writer, plain bool) table.Writer

NewTableWriter returns a go-pretty table writer bound to w using the shared gridctl style. Plain rendering is used when forced by a --plain flag or when w is not a terminal, so piped output never contains box runes. Commands that render tables outside a Printer share this chokepoint instead of hand-rolling styles.

func SetDefaultLevel

func SetDefaultLevel(l slog.Level)

SetDefaultLevel sets the minimum level for subsequently created Printers. charmbracelet/log levels share slog's numeric values, so the conversion is direct.

func SetNoColor

func SetNoColor(disabled bool)

SetNoColor disables (or re-enables) all styled output for the process, regardless of TTY detection. Wired to the global --no-color flag.

func Suggest

func Suggest(input string, candidates []string) string

Suggest returns the candidate closest to input within a Levenshtein distance of suggestMaxDistance, or "" when nothing is close enough. Matching is case-insensitive; ties resolve to the earliest candidate.

Types

type ContainerSummary

type ContainerSummary struct {
	ID        string
	Name      string
	Type      string // mcp-server, agent, resource
	Image     string
	State     string // running, exited, etc.
	Message   string // status message
	PinStatus string // pinned, drift, approved, unpinned, or empty to omit column
}

ContainerSummary contains data for the container status table.

type GatewaySummary

type GatewaySummary struct {
	Name     string
	Port     int
	PID      int
	Status   string // running, stopped
	Started  string // human-readable duration
	CodeMode string // "on" or empty
}

GatewaySummary contains data for the gateway status table.

type MCPServerRollup

type MCPServerRollup struct {
	Name      string
	Type      string // transport label: local-process, container, ssh, external, openapi
	Replicas  string // "N/M" for sets with replicas > 1, "—" for single-replica servers
	State     string // "healthy", "degraded (replica-N restarting, next in 4s)", "unhealthy"
	Autoscale string // "min/current/max (target=N)" for autoscaled servers, empty for static
}

MCPServerRollup is one row of the rolled-up MCP-servers table shown by `gridctl status`. A server with a single replica uses "—" in the Replicas column to match the UX spec.

type Printer

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

Printer handles terminal output with amber-themed styling.

func New

func New() *Printer

New creates a Printer writing to stdout with amber theme.

func NewWithWriter

func NewWithWriter(w io.Writer) *Printer

NewWithWriter creates a Printer with a custom writer.

func (*Printer) Banner

func (p *Printer) Banner(ver string)

Banner prints the ASCII logo with version information.

func (*Printer) Containers

func (p *Printer) Containers(containers []ContainerSummary)

Containers prints the container status table with amber styling.

func (*Printer) Debug

func (p *Printer) Debug(msg string, keyvals ...any)

Debug logs a debug message with optional key-value pairs.

func (*Printer) Error

func (p *Printer) Error(msg string, keyvals ...any)

Error logs an error message with optional key-value pairs.

func (*Printer) Gateways

func (p *Printer) Gateways(gateways []GatewaySummary)

Gateways prints the gateway status table with amber styling.

func (*Printer) Hint

func (p *Printer) Hint(format string, args ...any)

Hint prints a short next-step suggestion. Hints are conversational chrome: they are suppressed when the writer is not a terminal so scripts, pipes, and JSON consumers never see them.

func (*Printer) Info

func (p *Printer) Info(msg string, keyvals ...any)

Info logs an info message with optional key-value pairs.

func (*Printer) MCPServers

func (p *Printer) MCPServers(rows []MCPServerRollup)

MCPServers prints the rolled-up MCP-server status table. The AUTOSCALE column is shown only when at least one row has autoscale configured, so static-only stacks see an unchanged table.

func (*Printer) Print

func (p *Printer) Print(format string, args ...any)

Print writes a message directly to output without formatting.

func (*Printer) Println

func (p *Printer) Println(args ...any)

Println writes a message with newline directly to output.

func (*Printer) Replicas

func (p *Printer) Replicas(rows []ReplicaDetail)

Replicas prints the per-replica detail table used by `gridctl status --replicas`. The AUTOSCALE column only appears when at least one row populates it.

func (*Printer) Section

func (p *Printer) Section(title string)

Section prints a section header.

func (*Printer) SetDebug

func (p *Printer) SetDebug(enabled bool)

SetDebug enables debug-level logging.

func (*Printer) SetLevel

func (p *Printer) SetLevel(l slog.Level)

SetLevel sets the printer's minimum log level from an slog level.

func (*Printer) SetPlain

func (p *Printer) SetPlain(plain bool)

SetPlain forces grep-friendly table rendering (no box-drawing) even when the writer is a terminal. Wired to per-command --plain flags.

func (*Printer) Summary

func (p *Printer) Summary(workloads []WorkloadSummary)

Summary prints the final status table with amber styling.

func (*Printer) Warn

func (p *Printer) Warn(msg string, keyvals ...any)

Warn logs a warning message with optional key-value pairs.

type ReplicaDetail

type ReplicaDetail struct {
	Server    string
	Replica   int
	Handle    string // PID for local-process, container id prefix for container-backed
	State     string
	Uptime    string
	InFlight  int64
	Autoscale string // "min/current/max (target=N)" — repeated per replica row for server-level info, empty for static servers
}

ReplicaDetail is one row of the expanded `gridctl status --replicas` view.

type Reporter

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

Reporter prints apply-phase progress. The base behavior is a static "<name>..." line on start and a "<name>... done" line on completion; when animate is enabled a spinner redraws the line in place instead. A nil *Reporter is a no-op so quiet mode can skip construction.

func NewReporter

func NewReporter(w io.Writer) *Reporter

NewReporter creates a phase reporter writing to w. Animation runs only when w is an interactive terminal, the CI environment variable is unset, styling is not globally disabled (NO_COLOR, TERM=dumb, --no-color), and ACCESSIBLE is not requested; everything else gets static lines.

func (*Reporter) EndPhase

func (r *Reporter) EndPhase(ok bool)

EndPhase completes the running phase, printing its terminal status line. Safe to call when no phase is active.

func (*Reporter) StartPhase

func (r *Reporter) StartPhase(name string, spin bool)

StartPhase begins a named phase. Any phase still running is finished successfully first, so call sites never have to pair Start/End manually across seams.

Pass spin=false for phases whose window carries foreign output (the docker pull/build slog stream): the phase then renders as static lines even on a TTY, so redraw frames never interleave with real output.

type WorkloadSummary

type WorkloadSummary struct {
	Name      string
	Type      string // mcp-server, agent, resource
	Transport string // http, stdio, sse, external, local, ssh
	State     string // running, failed, pending
}

WorkloadSummary contains data for the summary table.

Jump to

Keyboard shortcuts

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