diff --git a/main.go b/main.go index c822e08..75ee1d7 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "bufio" "encoding/json" + "errors" "fmt" "os" "path/filepath" @@ -212,10 +213,23 @@ func getGitInfo(cwd string) string { } // termWidthFunc returns the terminal width. +// Tries stderr and stdin as fallbacks since stdout is typically piped +// when Claude Code captures the status line output. // Replaced in tests to avoid depending on a real TTY. var termWidthFunc = func() (int, error) { - width, _, err := term.GetSize(int(os.Stdout.Fd())) - return width, err + for _, fd := range []uintptr{os.Stderr.Fd(), os.Stdin.Fd(), os.Stdout.Fd()} { + if width, _, err := term.GetSize(int(fd)); err == nil { + return width, nil + } + } + // Fall back to COLUMNS env var + if cols := os.Getenv("COLUMNS"); cols != "" { + var w int + if _, err := fmt.Sscanf(cols, "%d", &w); err == nil && w > 0 { + return w, nil + } + } + return 0, errors.New("no terminal detected") } func getTerminalWidth() int {