Reduce internal tty API surface to the only production-used helper#6942
Merged
Conversation
4 tasks
Copilot
AI
changed the title
[WIP] Review Go module golang.org/x/term
Reduce internal tty API surface to the only production-used helper
Jun 3, 2026
This was referenced Jun 3, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR trims the internal/tty package down to the single exported helper that is actually used in production (IsStderrTerminal), removing unused wrapper APIs and updating the unit tests to validate behavior via a pipe-backed os.Stderr.
Changes:
- Removed unused exported helpers from
internal/tty:IsStdoutTerminal()andStderrTerminalWidth(). - Simplified
internal/ttypackage documentation to match the reduced surface. - Updated
internal/ttytests to validateIsStderrTerminal()behavior by swappingos.Stderrto a pipe, and dropped tests that only existed for the removed helpers.
Show a summary per file
| File | Description |
|---|---|
| internal/tty/tty.go | Removes unused exported helpers, leaving only IsStderrTerminal() as the package API. |
| internal/tty/tty_test.go | Removes tests tied to deleted helpers and adds a pipe-backed stderr behavior test for IsStderrTerminal(). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
golang.org/x/termreview found thatinternal/ttyexposed two helpers with no production callers:IsStdoutTerminalandStderrTerminalWidth. This change trims the package to the single stderr TTY check actually used by the logger and aligns tests with that smaller surface.API cleanup
internal/ttyhelpers:IsStdoutTerminal()StderrTerminalWidth()IsStderrTerminal()as the only exported helper in the package.Test realignment
golang.org/x/termassertions ininternal/ttytests with a package-level behavior test that swapsos.Stderrto a pipe and verifies it is not treated as a terminal.Result
internal/ttynow reflects actual usage in the codebase instead of carrying uncalled wrapper APIs.