[terminal-stylist] Terminal Stylist Analysis: Console Output Patterns in pkg/ #46584
Closed
Replies: 1 comment
|
This discussion was automatically closed because it expired on 2026-07-20T09:25:51.384Z.
|
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.
Summary
Scanned 1,106 non-test Go files under
pkg/. The codebase has a strong console abstraction:pkg/consolecentralizes styling, TTY-aware rendering, tables, prompts, and spinners;pkg/stylescentralizes adaptive colors/themes. Most CLI output uses these correctly. Only 3 rawfmt.Print*call sites exist in non-test production code, and all simply emit already-rendered console output. Manual ANSI is rare and confined to internal console/parser helpers.Key Metrics
fmt.Print*call sitesConsole Package Analysis
pkg/consoleprovides:FormatSuccessMessage,FormatInfoMessage,FormatWarningMessage,FormatError, section/table/list formattingRenderStruct,RenderTableNewForm,NewInputForm,NewSelectForm,NewConfirmForm,IsCancelledGood patterns:
pkg/console/console.go:44-60gates ANSI on TTY and degrades stdout colors via environment-aware color handling.pkg/console/prompt_form.go:12-36standardizeshuhtheme/accessibility.pkg/console/input.go,confirm.go,list.goguard interactive flows with TTY detection.Lipgloss Usage
Mostly good and centralized.
Good examples:
pkg/styles/theme.go:103-107probes terminal background safely, with Windows guardrails.pkg/styles/huh_theme.go:13-80useslipgloss.LightDarkfor adaptive form theming.pkg/cli/compile_schedule_calendar.go:198-217applies styles only when terminal output is detected.pkg/cli/gateway_logs_timeline_render.go:475-494wraps styling in TTY checks for stream output.pkg/logger/logger.go:51-58,128-141uses palette-based styles rather than hardcoded ANSI.Minor concern:
pkg/console/spinner.go:87,176,195,198,202uses carriage-return/clear-line ANSI indirectly via constants. This is acceptable for spinner control, but it is one of the few manual terminal-control paths.Huh Usage
Usage is consistent and correct.
pkg/cli/interactive.go,add_interactive_*.go,run_interactive.gopkg/console/prompt_form.gopkg/console/input.gopkg/console/confirm.goandpkg/console/list.goGood examples:
pkg/console/prompt_form.go:13-29ensures all forms sharestyles.HuhThemeand accessibility mode.pkg/console/input.go:33usesEchoModePasswordcorrectly.pkg/console/spinner.go:117-122explicitly avoids stealing input from subsequenthuhforms.Files with Issues
pkg/console/list.go:76—fmt.Scanfanti-patternUses
fmt.Scanf("%d", &choice)in the non-TTY fallback, while the function otherwise accepts a reader abstraction. This bypasses dependency injection and may read from the wrong input source in scripted/non-interactive contexts.Suggested fix: Use the injected reader (matching the
confirm.gopattern) instead offmt.Scanf.Recommendations
pkg/console/list.go:76— replacefmt.Scanfwith an injected reader to matchconfirm.go.pkg/console— the current abstraction is well-structured.fmt.Printpattern — usingfmt.Printonly to emit already-rendered console output is fine in:pkg/cli/logs_report.go:554pkg/cli/status_command.go:288pkg/cli/view_command.go:168pkg/stylesusing adaptive colors — current code already avoids hardcoded terminal colors.References: §29681321005
All reactions