[terminal-stylist] Console Output Analysis: Terminal Styling Patterns #36875
Closed
Replies: 1 comment
-
|
This discussion has been marked as outdated by Terminal Stylist. A newer discussion is available at Discussion #37087. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
This report analyzes console output patterns across 879 Go source files in
pkg/. The codebase has a mature, well-structured terminal styling layer built on the Charmbracelet ecosystem (Lipgloss v2 + Huh v2), with very consistent adoption.Key Metrics
console.*formattersfmt.Print*to stdout (non-console)huh.NewForm(...)instancesWithTheme/WithAccessiblepkg/cliArchitecture Summary
The codebase follows a clean three-layer styling architecture:
pkg/styles/theme.go— Centralized color palette (Dracula-inspired adaptive colors viacompat.AdaptiveColor) and pre-configuredlipgloss.Stylevariables.pkg/console/console.go— Higher-level formatting helpers (FormatError,FormatSuccessMessage,FormatWarningMessage,RenderTable,RenderTitleBox, etc.) with TTY detection guard (applyStyle).pkg/cli/— Commands consumeconsole.*formatters exclusively in nearly all files.Strengths — What the codebase does well
✅ TTY-Aware Rendering
applyStyle()inpkg/console/console.gogates all Lipgloss styling behindtty.IsStdoutTerminal(). All render helpers (RenderTitleBox,RenderErrorBox,RenderInfoSection,RenderComposedSections) additionally checktty.IsStderrTerminal(), providing clean plain-text fallbacks for pipes and CI.✅ Adaptive Colors
All colors in
pkg/styles/theme.gousecompat.AdaptiveColorwith explicit light and dark hex variants. The Dracula palette is used for dark mode; high-contrast alternatives are provided for light terminals.lipgloss.HasDarkBackground()is called atinit()time.✅ Huh Form Consistency
All 16
huh.NewForm(...)calls inpkg/cli/use.WithTheme(styles.HuhTheme).WithAccessible(console.IsAccessibleMode()). The customHuhThemeinpkg/styles/huh_theme.gomaps the full palette to all huh field states (focused, blurred, select options, buttons, text inputs).✅ Centralized Table Rendering
console.RenderTable(TableConfig{...})wrapslipgloss/tablewith consistentstyleFunc, alternating row colors, total-row styling, and rounded borders. No ad-hoc manual table formatting was observed inpkg/cli/.✅ Consistent Message Types
Seven named formatter functions cover all message types:
FormatSuccessMessage,FormatInfoMessage,FormatWarningMessage,FormatCommandMessage,FormatProgressMessage,FormatPromptMessage,FormatVerboseMessage. These are widely used (1,435+ call sites forconsole.*inpkg/cli/).✅ Error Chain Formatting
FormatErrorChain(err)recursively unwraps%w-wrapped errors and indents each level, giving Rust-like readable error output.FormatError(CompilerError)renders file:line:column with source context and^pointer highlighting.Minor Observations
fmt.Print*calls (3 instances)Only 3 calls bypass
console.*formatters to write directly to stdout:These are intentional — they use
console.RenderStruct()for structured data or pass already-formatted output strings, so the usage is correct. No action needed.i️ Lipgloss used directly in
pkg/cli/compile_schedule_calendar.gointensityStyle()buildslipgloss.NewStyle()directly for calendar heat-map rendering. This is a justified specialization (intensity levels → color gradient) not covered by the genericpkg/stylespalette. The function acceptsisTerminal booland returns a plain style when not a TTY — correct pattern.i️ Logger uses Lipgloss directly
pkg/logger/logger.gobuilds acolorPaletteoflipgloss.Stylevalues for debug namespace coloring. This is appropriate for debug tooling and correctly usesstyles.Color*constants.i️ Huh used directly in
pkg/cli/(outsidepkg/console/)16
huh.NewForm(...)calls exist inpkg/cli/rather than being wrapped inpkg/console/. All applyWithThemeandWithAccessible. This is consistent and acceptable; the forms are command-specific and would be harder to generalize into console helpers.Recommendations
pkg/console/confirm.goConfirmActionvariant withRunWithContextsupport for cancellation in long-running interactive flowspkg/console/FormatCountMessage(n int, label string)usingstyles.Countto standardize"X items"output patternsWithTheme+WithAccessible— no remediation neededconsole.RenderStructor pre-formatted output — correctConclusion
The codebase demonstrates excellent adherence to Charmbracelet ecosystem best practices. The
pkg/styles→pkg/console→pkg/clilayering is clean, TTY detection is applied consistently, adaptive colors are used throughout, and all interactive forms share the same theme and accessibility configuration. No critical issues were identified.References:
Beta Was this translation helpful? Give feedback.
All reactions