From a06aa4c549e51c7d1ec5d5b5083ed18e4db1bb2c Mon Sep 17 00:00:00 2001 From: Kaj Kowalski Date: Sun, 8 Feb 2026 23:14:13 +0100 Subject: [PATCH] Fix right-alignment by detecting terminal width from stderr/stdin When Claude Code captures stdout, term.GetSize on stdout fails and falls back to 80 columns. Now tries stderr and stdin first (which remain connected to the TTY), then COLUMNS env var, then 80. --- main.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 {