Browse Source

Colorize output for warnings and errors.

If all is good, print the message in green.

PR:		274981
Inspired by:	yuri
Joe Clarke 5 months ago
parent
commit
33dea4226a
1 changed files with 15 additions and 5 deletions
  1. 15 5
      portlint.pl

+ 15 - 5
portlint.pl

@@ -20,10 +20,13 @@
 use strict;
 use warnings;
 
+BEGIN { $ENV{ NO_COLOR } = 1 if not -t STDOUT; }
+
 use Getopt::Std;
 use File::Find;
 use IPC::Open2;
 use File::Basename;
+use Term::ANSIColor qw(:constants);
 use POSIX qw(strftime);
 
 sub perror($$$$);
@@ -403,9 +406,13 @@ if ($err || $warn) {
 			print $msg, "\n";
 		}
 	}
-	printf("%d fatal %s and %d %s found.\n", $err, $errtext, $warn, $warntext);
+	if ($err > 0) {
+		print BRIGHT_RED sprintf("%d fatal %s and %d %s found.", $err, $errtext, $warn, $warntext), RESET, "\n";
+	} else {
+		print BRIGHT_YELLOW sprintf("%d fatal %s and %d %s found.", $err, $errtext, $warn, $warntext), RESET, "\n";
+	}
 } else {
-	print "looks fine.\n";
+	print BRIGHT_GREEN "looks fine.", RESET, "\n";
 }
 exit $err;
 
@@ -3664,18 +3671,21 @@ TEST_DEPENDS FETCH_DEPENDS DEPENDS_TARGET
 
 sub perror($$$$) {
 	my($type, $file, $line, $msg) = @_;
+	my $color;
 
 	if ($type eq 'FATAL') {
 		$err++;
+		$color = BRIGHT_RED;
 	} else {
 		$warn++;
+		$color = BRIGHT_YELLOW;
 	}
 	if ($grouperrs) {
 		$msg = '%%LINES%%' . $msg;
 		if ($file ne "") {
 			$msg = $file . ": " . $msg;
 		}
-		$msg = $type . ": " . $msg;
+		$msg = $color . $type . RESET . ": " . $msg;
 		if (!$errcache{$msg}) {
 			push @errlst, $msg;
 		}
@@ -3689,8 +3699,8 @@ sub perror($$$$) {
 		if ($file ne "") {
 			$msg = $file . ": " . $msg;
 		}
-		$msg = $type . ": " . $msg;
-		print $msg . "\n";
+		$msg = ": " . $msg;
+		print $color, $type, RESET, $msg . "\n";
 	}
 }