diff options
author | Joe Perches <joe@perches.com> | 2015-06-25 18:03:03 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-25 20:00:41 -0400 |
commit | 57230297116faf5b0a995916d5dd5fedab54cba3 (patch) | |
tree | 081ddaa65c4245c1b902823a20073ce4d29f87bb /scripts | |
parent | d8469f16207c626d71749ada88c13db1238df39e (diff) |
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>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 1b999cc035ff..d52293f65374 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -9,6 +9,7 @@ use strict; | |||
9 | use POSIX; | 9 | use POSIX; |
10 | use File::Basename; | 10 | use File::Basename; |
11 | use Cwd 'abs_path'; | 11 | use Cwd 'abs_path'; |
12 | use Term::ANSIColor qw(:constants); | ||
12 | 13 | ||
13 | my $P = $0; | 14 | my $P = $0; |
14 | my $D = dirname(abs_path($P)); | 15 | my $D = dirname(abs_path($P)); |
@@ -49,6 +50,7 @@ my $min_conf_desc_length = 4; | |||
49 | my $spelling_file = "$D/spelling.txt"; | 50 | my $spelling_file = "$D/spelling.txt"; |
50 | my $codespell = 0; | 51 | my $codespell = 0; |
51 | my $codespellfile = "/usr/local/share/codespell/dictionary.txt"; | 52 | my $codespellfile = "/usr/local/share/codespell/dictionary.txt"; |
53 | my $color = 1; | ||
52 | 54 | ||
53 | sub help { | 55 | sub help { |
54 | my ($exitcode) = @_; | 56 | my ($exitcode) = @_; |
@@ -93,6 +95,7 @@ Options: | |||
93 | --codespell Use the codespell dictionary for spelling/typos | 95 | --codespell Use the codespell dictionary for spelling/typos |
94 | (default:/usr/local/share/codespell/dictionary.txt) | 96 | (default:/usr/local/share/codespell/dictionary.txt) |
95 | --codespellfile Use this codespell dictionary | 97 | --codespellfile Use this codespell dictionary |
98 | --color Use colors when output is STDOUT (default: on) | ||
96 | -h, --help, --version display this help and exit | 99 | -h, --help, --version display this help and exit |
97 | 100 | ||
98 | When FILE is - read standard input. | 101 | When FILE is - read standard input. |
@@ -153,6 +156,7 @@ GetOptions( | |||
153 | 'test-only=s' => \$tst_only, | 156 | 'test-only=s' => \$tst_only, |
154 | 'codespell!' => \$codespell, | 157 | 'codespell!' => \$codespell, |
155 | 'codespellfile=s' => \$codespellfile, | 158 | 'codespellfile=s' => \$codespellfile, |
159 | 'color!' => \$color, | ||
156 | 'h|help' => \$help, | 160 | 'h|help' => \$help, |
157 | 'version' => \$help | 161 | 'version' => \$help |
158 | ) or help(1); | 162 | ) or help(1); |
@@ -1672,15 +1676,26 @@ sub report { | |||
1672 | (defined $tst_only && $msg !~ /\Q$tst_only\E/)) { | 1676 | (defined $tst_only && $msg !~ /\Q$tst_only\E/)) { |
1673 | return 0; | 1677 | return 0; |
1674 | } | 1678 | } |
1675 | my $line; | 1679 | my $output = ''; |
1680 | if (-t STDOUT && $color) { | ||
1681 | if ($level eq 'ERROR') { | ||
1682 | $output .= RED; | ||
1683 | } elsif ($level eq 'WARNING') { | ||
1684 | $output .= YELLOW; | ||
1685 | } else { | ||
1686 | $output .= GREEN; | ||
1687 | } | ||
1688 | } | ||
1689 | $output .= $prefix . $level . ':'; | ||
1676 | if ($show_types) { | 1690 | if ($show_types) { |
1677 | $line = "$prefix$level:$type: $msg\n"; | 1691 | $output .= BLUE if (-t STDOUT && $color); |
1678 | } else { | 1692 | $output .= "$type:"; |
1679 | $line = "$prefix$level: $msg\n"; | ||
1680 | } | 1693 | } |
1681 | $line = (split('\n', $line))[0] . "\n" if ($terse); | 1694 | $output .= RESET if (-t STDOUT && $color); |
1695 | $output .= ' ' . $msg . "\n"; | ||
1696 | $output = (split('\n', $output))[0] . "\n" if ($terse); | ||
1682 | 1697 | ||
1683 | push(our @report, $line); | 1698 | push(our @report, $output); |
1684 | 1699 | ||
1685 | return 1; | 1700 | return 1; |
1686 | } | 1701 | } |