-
Notifications
You must be signed in to change notification settings - Fork 105
[Code Quality] Centralize ANSI escape sequences in pkg/console/terminal.go #14364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Code Quality] Centralize ANSI escape sequences in pkg/console/terminal.go #14364
Conversation
|
@copilot work |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
I've completed centralizing the ANSI escape sequences in pkg/console/terminal.go. Changes made (commit 73c481b):
All ANSI escape sequences are now in one location with helper functions, making the code more maintainable and preventing TTY detection bugs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR centralizes terminal control behavior by moving ClearScreen() and ClearLine() into pkg/console/terminal.go, consolidating ANSI escape usage and ensuring consistent TTY gating for terminal control output.
Changes:
- Added
ClearScreen()andClearLine()helpers topkg/console/terminal.goalongside existing cursor movement helpers. - Removed
ClearScreen()andClearLine()frompkg/console/console.goto avoid duplication.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/console/terminal.go | Adds ClearScreen() and ClearLine() implementations using centralized ANSI constants and tty.IsStderrTerminal() gating. |
| pkg/console/console.go | Removes duplicated ClearScreen() / ClearLine() now hosted in terminal.go. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR centralizes all ANSI escape sequences into
pkg/console/terminal.goto improve code maintainability and consistency.Changes Made
ClearScreen()andClearLine()fromconsole.gototerminal.goterminal.go:ClearScreen()- clears terminal screenClearLine()- clears current lineMoveCursorUp(n int)- moves cursor up n linesMoveCursorDown(n int)- moves cursor down n linesansiClearScreen = "\033[H\033[2J"ansiClearLine = "\033[K"ansiCarriageReturn = "\r"tty.IsStderrTerminal()before emitting ANSI codes to prevent codes in non-TTY environmentsFiles Modified
pkg/console/terminal.go- AddedClearScreen()andClearLine()functionspkg/console/console.go- RemovedClearScreen()andClearLine()functionsBenefits
terminal.goTesting
console.go,spinner.go, andadd_interactive_orchestrator.goThe implementation fully meets all success criteria from the issue: all manual ANSI escape sequences are now replaced with helper functions, TTY detection is consistently applied, and the code is more maintainable.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.