Documentation
¶
Overview ¶
Package style provides centralized terminal styling for the gcx CLI. All styling is gated on TTY detection — piped and agent-mode output remains plain text for backward compatibility.
Index ¶
- Variables
- func ColorCell(text string, dim, isErr bool) string
- func ColorMutedText(text string) string
- func ColorPercent(text string, pct float64, dim, isErr bool) string
- func Gradient(text string, from, to lipgloss.Color) string
- func HelpFunc(defaultHelp func(*cobra.Command, []string)) func(*cobra.Command, []string)
- func IsStylingEnabled() bool
- func RenderLogo() string
- func SetEnabled(enabled bool)
- type TableBuilder
Constants ¶
This section is empty.
Variables ¶
var ( // Semantic colors. ColorPrimary = lipgloss.Color("#6E9FFF") ColorMuted = lipgloss.Color("#7D8085") ColorBorder = lipgloss.Color("#44474E") // Gradient endpoints (used by the ASCII logo). GradientBrandTo = lipgloss.Color("#EAB839") // Amber GradientAccentFrom = lipgloss.Color("#F2495C") // Coral // Grafana chart palette (classic series colors). ChartPalette = []lipgloss.Color{ lipgloss.Color("#7EB26D"), lipgloss.Color("#EAB839"), lipgloss.Color("#6ED0E0"), lipgloss.Color("#EF843C"), lipgloss.Color("#E24D42"), lipgloss.Color("#1F78C1"), lipgloss.Color("#BA43A9"), lipgloss.Color("#705DA0"), lipgloss.Color("#508642"), lipgloss.Color("#CCA300"), } )
Grafana Neon Dark — color palette derived from Grafana's official dark theme.
Functions ¶
func ColorCell ¶ added in v0.2.13
ColorCell applies row-level error/dim treatment to a non-percent cell:
isErr → red dim → muted gray else → unchanged
Error treatment overrides dim. Returns text unchanged when styling is disabled.
func ColorMutedText ¶ added in v0.2.13
ColorMutedText renders text in muted gray. Used for elements like the detached-subtrees divider that should always be dim when styling is on. Returns text unchanged when styling is disabled.
func ColorPercent ¶ added in v0.2.13
ColorPercent applies duration-share color thresholds to a % cell:
isErr → bold red (overrides everything) dim → muted gray pct >= 50 → bold red pct >= 10 → yellow otherwise → unchanged
Returns text unchanged when styling is disabled.
func Gradient ¶
Gradient renders text with a linear color gradient between from and to. When styling is disabled, returns the text unchanged.
func HelpFunc ¶
HelpFunc returns a custom Cobra help function that renders Long descriptions and Examples through glamour markdown rendering when styling is enabled. Falls back to Cobra's default help when styling is disabled.
func IsStylingEnabled ¶
func IsStylingEnabled() bool
IsStylingEnabled reports whether the terminal supports styled output. Returns false when stdout is piped, agent mode is active, the user passed --no-color, or stdout is not a real TTY.
func RenderLogo ¶
func RenderLogo() string
RenderLogo writes the gcx ASCII logo with a gradient color effect. When styling is disabled, returns an empty string.
func SetEnabled ¶
func SetEnabled(enabled bool)
SetEnabled controls whether styling is active. Pass false to force plain output (used by --no-color). The default is determined by TTY detection.
Types ¶
type TableBuilder ¶
type TableBuilder struct {
// contains filtered or unexported fields
}
TableBuilder constructs styled tables that degrade gracefully to plain tabwriter output when styling is disabled (piped, agent mode, --no-color).
func NewTable ¶
func NewTable(headers ...string) *TableBuilder
NewTable creates a new table with the given column headers.
func (*TableBuilder) ColumnWidths ¶ added in v0.2.13
func (tb *TableBuilder) ColumnWidths(widths []int) *TableBuilder
ColumnWidths sets per-column fixed widths for the styled renderer. A value of 0 means auto-size; a positive value locks that column and prevents lipgloss from shrinking it when the table is wider than the terminal. The slice may be shorter than the column count; trailing columns default to 0.
func (*TableBuilder) Render ¶
func (tb *TableBuilder) Render(w io.Writer) error
Render writes the table to w. When styling is enabled, it uses lipgloss/table with the Grafana Neon Dark palette. Otherwise, it falls back to text/tabwriter with the exact same formatting as the legacy code (minwidth=0, tabwidth=4, padding=2).
func (*TableBuilder) Row ¶
func (tb *TableBuilder) Row(vals ...string) *TableBuilder
Row appends a data row. The number of values should match the header count.