Skip to content

Commit a3ea271

Browse files
committed
Fix terminal width through pipe
1 parent 624eeca commit a3ea271

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

pkg/cmd/format.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ func (t *TableWriter) AddRow(cells ...string) {
5858
}
5959

6060
// getTerminalWidth returns the terminal width. It tries the stdout
61-
// file descriptor first, then the COLUMNS env var, then defaults to 80.
61+
// file descriptor first, then falls back to stderr (which remains
62+
// connected to the terminal even when stdout is piped), then the
63+
// COLUMNS env var, then defaults to 80.
6264
func getTerminalWidth() int {
6365
if w, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil && w > 0 {
6466
return w
6567
}
68+
if w, _, err := term.GetSize(int(os.Stderr.Fd())); err == nil && w > 0 {
69+
return w
70+
}
6671
if cols := os.Getenv("COLUMNS"); cols != "" {
6772
if w, err := strconv.Atoi(cols); err == nil && w > 0 {
6873
return w

0 commit comments

Comments
 (0)