allow COLUMNS to override and silence terminal width, and warn less
Graham Knop [Sun, 26 Jul 2020 17:51:07 +0000 (19:51 +0200)]
If not connected to a terminal, there's no reason to warn that we can't
detect the width.

lib/Catalyst/Utils.pm

index 5fae307..fabbb81 100644 (file)
@@ -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;
     }