Consolidate cmdio capability detection into capabilities struct#4298
Consolidate cmdio capability detection into capabilities struct#4298
Conversation
Replace scattered interactive/prompt booleans in cmdIO with a single Capabilities struct that encapsulates all terminal capability detection (TTY status, color support, prompt support, Git Bash detection). Changes: - Add Capabilities struct with methods SupportsInteractive(), SupportsPrompt(), SupportsColor() - Move IsTTY to tty.go with FakeTTY test helper - Replace cmdio.IsTTY(w) with cmdio.SupportsColor(ctx, w) for color decisions - Replace stdin TTY check with IsPromptSupported() in aitools install No behavioral changes. Respects NO_COLOR and TERM=dumb throughout. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Commit: dea0180
21 interesting tests: 11 RECOVERED, 6 KNOWN, 3 flaky, 1 SKIP
Top 50 slowest tests (at least 2 minutes):
|
| w := f.file.Writer() | ||
| return handler.NewFriendlyHandler(w, &handler.Options{ | ||
| Color: cmdio.IsTTY(w), | ||
| Color: cmdio.SupportsColor(ctx, w), |
There was a problem hiding this comment.
Why let commands configure color if there is only right way to do it? Why not make NewFriendlyHandler select color automatically?
There was a problem hiding this comment.
Whether or not to log with color depends on the target io.Writer. Agree it can be moved into the function.
| stdoutIsTTY: false, | ||
| stderrIsTTY: false, | ||
| color: false, | ||
| isGitBash: false, |
There was a problem hiding this comment.
why do we have this here? It's not a "capability", it's environment, which may have some but not others capabilities? (I personally would be okay with saying if "git bash" disable all fancy stuff especially if alternative is that I have to sprinkle my code with gitbash-specific code).
There was a problem hiding this comment.
The field isn't, but the outcome (does this term prompts, etc), is an outcome of Git Bash or not.
Once we switch to better fancy stuff this will disappear; Git Bash must be supported.
|
Commit: fa62e53 |
## Changes All prompt functions now consistently write to stderr, removing the need to check if stdout is a TTY for prompt support. Depends on #4298. ## Why This simplifies the logic and follows Unix conventions: keep stdout clean for data/piping, use stderr for interactive UI elements. Now prompts work even when stdout is redirected (e.g., `databricks cmd | tee output.txt`). --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Changes
Replace scattered interactive/prompt booleans in libs/cmdio with a single capabilities struct that encapsulates all terminal capability detection (TTY status, color support, prompt support, Git Bash detection).
Changes:
No behavioral changes. Respects NO_COLOR and TERM=dumb throughout.
Tests
All tests pass.
Manually confirmed that I still see prompts and colors.