-
Notifications
You must be signed in to change notification settings - Fork 308
Description
Description
The console package currently contains 8 instances of manual ANSI escape sequences scattered across multiple files. These should be centralized into helper functions to improve maintainability, ensure consistent TTY detection, and reduce the risk of bugs.
Suggested Changes
Create a new file pkg/console/terminal.go with centralized helper functions:
package console
import (
"fmt"
"os"
"github.com/githubnext/gh-aw/pkg/tty"
)
// ClearScreen clears the terminal screen if stderr is a TTY
func ClearScreen() {
if tty.IsStderrTerminal() {
fmt.Fprint(os.Stderr, "\033[H\033[2J")
}
}
// ClearLine clears the current line if stderr is a TTY
func ClearLine() {
if tty.IsStderrTerminal() {
fmt.Fprint(os.Stderr, "\r\033[K")
}
}
// MoveCursorUp moves cursor up n lines if stderr is a TTY
func MoveCursorUp(n int) {
if tty.IsStderrTerminal() {
fmt.Fprintf(os.Stderr, "\033[%dA", n)
}
}
// MoveCursorDown moves cursor down n lines if stderr is a TTY
func MoveCursorDown(n int) {
if tty.IsStderrTerminal() {
fmt.Fprintf(os.Stderr, "\033[%dB", n)
}
}Then replace manual ANSI codes in these files:
pkg/cli/add_interactive_orchestrator.gopkg/console/console.gopkg/console/spinner.go
Example refactoring:
// BEFORE
fmt.Fprint(os.Stderr, "\r\033[K")
// AFTER
console.ClearLine()Files Affected
pkg/console/terminal.go(new file)pkg/cli/add_interactive_orchestrator.go(2 instances)pkg/console/console.go(2 instances)pkg/console/spinner.go(4 instances)
Success Criteria
- New
terminal.gofile created with helper functions - All 8 manual ANSI escape sequences replaced with helper calls
- All helpers include TTY detection guards
- Existing tests continue to pass
- Code is more maintainable and consistent
Priority
Medium - Improves code quality and maintainability but not blocking
Source
Extracted from Terminal Stylist Report discussion #12889
Quote from source:
Found 8 instances of manual ANSI codes. Recommendation: Replace with Lipgloss equivalents where possible or centralize into helper functions.
Estimated Effort
1 day - Straightforward refactoring with clear implementation pattern
AI generated by Discussion Task Miner - Code Quality Improvement Agent
- expires on Feb 14, 2026, 1:19 PM UTC