Skip to content
Snippets Groups Projects
Commit 2cf2c020 authored by Mike McQuaid's avatar Mike McQuaid
Browse files

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.
parent b2995be4
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,10 @@ module Tty
end
def width
(`/bin/stty size`.split[1] || 80).to_i
width = `/bin/stty size 2>/dev/null`.split[1]
width ||= `/usr/bin/tput cols 2>/dev/null`.split[0]
width ||= 80
width.to_i
end
def truncate(string)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment