checkpatch: colorize output to terminal
Add optional colors to make seeing message types a bit easier. Add --color command line switch, default:on Error is RED, warning is YELLOW, check is GREEN. The message type, if shown, is BLUE. Signed-off-by: Joe Perches <joe@perches.com> Tested-by: Petr Mladek <pmladek@suse.cz> Cc: Andy Whitcroft <apw@canonical.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
d8469f1620
commit
5723029711
@ -9,6 +9,7 @@ use strict;
|
|||||||
use POSIX;
|
use POSIX;
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
use Cwd 'abs_path';
|
use Cwd 'abs_path';
|
||||||
|
use Term::ANSIColor qw(:constants);
|
||||||
|
|
||||||
my $P = $0;
|
my $P = $0;
|
||||||
my $D = dirname(abs_path($P));
|
my $D = dirname(abs_path($P));
|
||||||
@ -49,6 +50,7 @@ my $min_conf_desc_length = 4;
|
|||||||
my $spelling_file = "$D/spelling.txt";
|
my $spelling_file = "$D/spelling.txt";
|
||||||
my $codespell = 0;
|
my $codespell = 0;
|
||||||
my $codespellfile = "/usr/local/share/codespell/dictionary.txt";
|
my $codespellfile = "/usr/local/share/codespell/dictionary.txt";
|
||||||
|
my $color = 1;
|
||||||
|
|
||||||
sub help {
|
sub help {
|
||||||
my ($exitcode) = @_;
|
my ($exitcode) = @_;
|
||||||
@ -93,6 +95,7 @@ Options:
|
|||||||
--codespell Use the codespell dictionary for spelling/typos
|
--codespell Use the codespell dictionary for spelling/typos
|
||||||
(default:/usr/local/share/codespell/dictionary.txt)
|
(default:/usr/local/share/codespell/dictionary.txt)
|
||||||
--codespellfile Use this codespell dictionary
|
--codespellfile Use this codespell dictionary
|
||||||
|
--color Use colors when output is STDOUT (default: on)
|
||||||
-h, --help, --version display this help and exit
|
-h, --help, --version display this help and exit
|
||||||
|
|
||||||
When FILE is - read standard input.
|
When FILE is - read standard input.
|
||||||
@ -153,6 +156,7 @@ GetOptions(
|
|||||||
'test-only=s' => \$tst_only,
|
'test-only=s' => \$tst_only,
|
||||||
'codespell!' => \$codespell,
|
'codespell!' => \$codespell,
|
||||||
'codespellfile=s' => \$codespellfile,
|
'codespellfile=s' => \$codespellfile,
|
||||||
|
'color!' => \$color,
|
||||||
'h|help' => \$help,
|
'h|help' => \$help,
|
||||||
'version' => \$help
|
'version' => \$help
|
||||||
) or help(1);
|
) or help(1);
|
||||||
@ -1672,15 +1676,26 @@ sub report {
|
|||||||
(defined $tst_only && $msg !~ /\Q$tst_only\E/)) {
|
(defined $tst_only && $msg !~ /\Q$tst_only\E/)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
my $line;
|
my $output = '';
|
||||||
if ($show_types) {
|
if (-t STDOUT && $color) {
|
||||||
$line = "$prefix$level:$type: $msg\n";
|
if ($level eq 'ERROR') {
|
||||||
} else {
|
$output .= RED;
|
||||||
$line = "$prefix$level: $msg\n";
|
} elsif ($level eq 'WARNING') {
|
||||||
|
$output .= YELLOW;
|
||||||
|
} else {
|
||||||
|
$output .= GREEN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$line = (split('\n', $line))[0] . "\n" if ($terse);
|
$output .= $prefix . $level . ':';
|
||||||
|
if ($show_types) {
|
||||||
|
$output .= BLUE if (-t STDOUT && $color);
|
||||||
|
$output .= "$type:";
|
||||||
|
}
|
||||||
|
$output .= RESET if (-t STDOUT && $color);
|
||||||
|
$output .= ' ' . $msg . "\n";
|
||||||
|
$output = (split('\n', $output))[0] . "\n" if ($terse);
|
||||||
|
|
||||||
push(our @report, $line);
|
push(our @report, $output);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user