Skip to content

Commit 2cf2c02

Browse files
committed
tty: handle non-tty stdin.
When stdin is not a tty then the message `stty: stdin isn't a terminal` will be produced. Silence this message and fall back to `tput` when it fails and default to 80 if we get no results at all. Follow-up from #2714.
1 parent b2995be commit 2cf2c02

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Library/Homebrew/utils/tty.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ def strip_ansi(string)
66
end
77

88
def width
9-
(`/bin/stty size`.split[1] || 80).to_i
9+
width = `/bin/stty size 2>/dev/null`.split[1]
10+
width ||= `/usr/bin/tput cols 2>/dev/null`.split[0]
11+
width ||= 80
12+
width.to_i
1013
end
1114

1215
def truncate(string)

0 commit comments

Comments
 (0)