Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753271AbbFDMFZ (ORCPT ); Thu, 4 Jun 2015 08:05:25 -0400 Received: from cantor2.suse.de ([195.135.220.15]:35949 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752399AbbFDMFV (ORCPT ); Thu, 4 Jun 2015 08:05:21 -0400 Date: Thu, 4 Jun 2015 14:05:20 +0200 From: Petr Mladek To: Joe Perches Cc: Andrew Morton , Andy Whitcroft , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] checkpatch: colorize output to terminal Message-ID: <20150604120520.GO3135@pathway.suse.cz> References: <376fce5d30bef4610eee2f1e798e2d496fbe7848.1433346576.git.joe@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <376fce5d30bef4610eee2f1e798e2d496fbe7848.1433346576.git.joe@perches.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2916 Lines: 98 On Wed 2015-06-03 08:53:39, Joe Perches wrote: > 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 Tested-by: Petr Mladek I like it. It really helps noticing the problems. Best Regards, Petr > --- > scripts/checkpatch.pl | 27 +++++++++++++++++++++------ > 1 file changed, 21 insertions(+), 6 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index eaa76bd..cef2cd4 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -9,6 +9,7 @@ use strict; > use POSIX; > use File::Basename; > use Cwd 'abs_path'; > +use Term::ANSIColor qw(:constants); > > my $P = $0; > my $D = dirname(abs_path($P)); > @@ -49,6 +50,7 @@ my $min_conf_desc_length = 4; > my $spelling_file = "$D/spelling.txt"; > my $codespell = 0; > my $codespellfile = "/usr/local/share/codespell/dictionary.txt"; > +my $color = 1; > > sub help { > my ($exitcode) = @_; > @@ -93,6 +95,7 @@ Options: > --codespell Use the codespell dictionary for spelling/typos > (default:/usr/local/share/codespell/dictionary.txt) > --codespellfile Use this codespell dictionary > + --color Use colors when output is STDOUT (default: on) > -h, --help, --version display this help and exit > > When FILE is - read standard input. > @@ -153,6 +156,7 @@ GetOptions( > 'test-only=s' => \$tst_only, > 'codespell!' => \$codespell, > 'codespellfile=s' => \$codespellfile, > + 'color!' => \$color, > 'h|help' => \$help, > 'version' => \$help > ) or help(1); > @@ -1672,15 +1676,26 @@ sub report { > (defined $tst_only && $msg !~ /\Q$tst_only\E/)) { > return 0; > } > - my $line; > + my $output = ''; > + if (-t STDOUT && $color) { > + if ($level eq 'ERROR') { > + $output .= RED; > + } elsif ($level eq 'WARNING') { > + $output .= YELLOW; > + } else { > + $output .= GREEN; > + } > + } > + $output .= $prefix . $level . ':'; > if ($show_types) { > - $line = "$prefix$level:$type: $msg\n"; > - } else { > - $line = "$prefix$level: $msg\n"; > + $output .= BLUE if (-t STDOUT && $color); > + $output .= "$type:"; > } > - $line = (split('\n', $line))[0] . "\n" if ($terse); > + $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; > } > -- > 2.1.2 > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/