From: Graham Knop Date: Sun, 26 Jul 2020 17:51:07 +0000 (+0200) Subject: allow COLUMNS to override and silence terminal width, and warn less X-Git-Tag: v5.90_127~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=0cf6f36c8a07f4a0013bd98fab9ec5c9a89b6107;hp=eb4dbfbe495328a06b9115425f3f7381b732af0a allow COLUMNS to override and silence terminal width, and warn less If not connected to a terminal, there's no reason to warn that we can't detect the width. --- diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index 5fae307..fabbb81 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -403,6 +403,14 @@ sub term_width { return $_term_width if $_term_width; + if ($ENV{COLUMNS} && $ENV{COLUMNS} =~ /\A\d+\z/) { + return $_term_width = $ENV{COLUMNS}; + } + + if (!-t STDOUT && !-t STDERR) { + return $_term_width = 80; + } + if (!defined $_use_term_size_any) { eval { require Term::Size::Any; @@ -423,12 +431,9 @@ sub term_width { my $width; if ($_use_term_size_any) { - ($width) = Term::Size::Any::chars(); + $width = Term::Size::Any::chars(*STDERR) || Term::Size::Any::chars(*STDOUT); } - if (!$width && $ENV{COLUMNS} && $ENV{COLUMNS} =~ /\A\d+\z/) { - $width = $ENV{COLUMNS}; - } if (!$width || $width < 80) { $width = 80; }