lintian: r805 - in trunk: doc frontend lib man
Author: jaalto
Date: 2007-01-30 08:13:01 +0100 (Tue, 30 Jan 2007)
New Revision: 805
Modified:
trunk/doc/README
trunk/frontend/lintian
trunk/lib/Tags.pm
trunk/man/lintian.1
Log:
* (svn):
+ [JA] Applied patch to implement following features.
Patch by Loic Minier (Closes #399714).
* lib/Tags.pm:
+ [LM] Support for ANSI color output.
* frontend/lintian:
+ [LM] Add --no-colored-output option to disable ANSI color output, even
when STDOUT is a TTY.
* man/lintian.1:
+ [LM] Document --no-colored-output.
* doc/README:
+ [LM] Document --no-colored-output option.
Modified: trunk/doc/README
===================================================================
--- trunk/doc/README 2007-01-30 07:05:23 UTC (rev 804)
+++ trunk/doc/README 2007-01-30 07:13:01 UTC (rev 805)
@@ -73,6 +73,7 @@
-l X, --unpack-level X set default unpack level to X
-o, --no-override ignore overrides
--show-overrides output tags that have been overriden
+ --no-colored-output disable color output (default is enabled on TTY)
-U X, --unpack-info X specify which info should be collected
-m, --md5sums check md5sums when processing a .changes file
--allow-root suppress lintian's warning when run as root
Modified: trunk/frontend/lintian
===================================================================
--- trunk/frontend/lintian 2007-01-30 07:05:23 UTC (rev 804)
+++ trunk/frontend/lintian 2007-01-30 07:13:01 UTC (rev 805)
@@ -52,6 +52,7 @@
my $unpack_level = undef; #flag for -l|--unpack-level switch
our $no_override = 0; #flag for -o|--no-override switch
our $show_overrides = 0; #flag for --show-overrides switch
+our $no_colored_output = 0; #flag for --no-colored-output switch
my $check_md5sums = 0; #flag for -m|--md5sums switch
my $allow_root = 0; #flag for --allow-root swtich
my $fail_on_warnings = 0; #flag for --fail-on-warnings switch
@@ -143,6 +144,7 @@
-l X, --unpack-level X set default unpack level to X
-o, --no-override ignore overrides
--show-overrides output tags that have been overriden
+ --no-colored-output disable ANSI color output (default enabled)
-U X, --unpack-info X specify which info should be collected
-m, --md5sums check md5sums when processing a .changes file
--allow-root suppress lintian\'s warning when run as root
@@ -259,6 +261,7 @@
"unpack-level|l=i" => \$unpack_level,
"no-override|o" => \$no_override,
"show-overrides" => \$show_overrides,
+ "no-colored-output" => \$no_colored_output,
"unpack-info|U=s" => \&record_unpack_info,
"md5sums|m" => \$check_md5sums,
"allow-root" => \$allow_root,
@@ -915,6 +918,7 @@
$Tags::show_info = $display_infotags;
$Tags::show_overrides = $show_overrides;
+$Tags::no_colored_output = $no_colored_output;
use warnings;
# load information about checker scripts
Modified: trunk/lib/Tags.pm
===================================================================
--- trunk/lib/Tags.pm 2007-01-30 07:05:23 UTC (rev 804)
+++ trunk/lib/Tags.pm 2007-01-30 07:13:01 UTC (rev 805)
@@ -28,6 +28,9 @@
our @ISA = qw(Exporter);
our @EXPORT = qw(tag);
+# support for ANSI color output via colored()
+use Term::ANSIColor;
+
# configuration variables and defaults
our $verbose = $::verbose;
our $debug = $::debug;
@@ -38,6 +41,7 @@
our $max_severity = 99;
our $min_significance = 1;
our $max_significance = 99;
+our $no_colored_output = 0;
# The master hash with all tag info. Key is the tag name, value another hash
# with the following keys:
@@ -75,6 +79,7 @@
my @sig_to_qualifier = ( '??', '?', '', '!' );
my @sev_to_code = qw( I W W E E );
+my @sev_to_color = ( 'bold', 'yellow', 'yellow bold', 'red', 'red bold' );
# Add a new tag, supplied as a hash reference
sub add_tag {
@@ -261,11 +266,20 @@
$extra = " @$information" if @$information;
$extra = '' if $extra eq ' ';
my $code = $codes{$tag_info->{type}};
+ # code -> severity -> color
+ my $severity = $type_to_sev{$tag_info->{type}};
+ my $color = $sev_to_color[$severity];
+ $color = '' if $no_colored_output;
+ # disable color output is STDOUT isn't a TTY
+ $color = '' if ! -t STDOUT;
$code = 'O' if $tag_info->{overridden}{override};
my $type = '';
$type = " $pkg_info->{type}" if $pkg_info->{type} ne 'binary';
- print "$code: $pkg_info->{pkg}$type: $tag_info->{tag}$extra\n";
+ my $output = "$code: $pkg_info->{pkg}$type: $tag_info->{tag}$extra\n";
+ $output = colored($output, $color) if $color;
+
+ print $output;
}
sub print_tag_new {
@@ -276,13 +290,20 @@
$extra = '' if $extra eq ' ';
my $code = $sev_to_code[$tag_info->{severity}];
$code = 'O' if $tag_info->{overridden}{override};
+ my $color = $sev_to_color[$tag_info->{severity}];
+ $color = '' if $no_colored_output;
+ # disable color output is STDOUT isn't a TTY
+ $color = '' if ! -t STDOUT;
my $qualifier = $sig_to_qualifier[$tag_info->{significance}];
$qualifier = '' if $code eq 'O';
my $type = '';
$type = " $pkg_info->{type}" if $pkg_info->{type} ne 'binary';
- print "$code$qualifier: $pkg_info->{pkg}$type: $tag_info->{tag}$extra\n";
+ my $output = "$code$qualifier: $pkg_info->{pkg}$type: $tag_info->{tag}$extra\n";
+ $output = colored($output, $color) if $color;
+ print $output;
+
}
sub tag {
Modified: trunk/man/lintian.1
===================================================================
--- trunk/man/lintian.1 2007-01-30 07:05:23 UTC (rev 804)
+++ trunk/man/lintian.1 2007-01-30 07:13:01 UTC (rev 805)
@@ -154,9 +154,13 @@
.TP
.BR \-\-show\-overrides
-Output tags that have been overriden
+Output tags that have been overriden.
.TP
+.BR \-\-no\-colored\-output
+Disable ANSI color output, even when stdout is a TTY.
+
+.TP
.BR \-U " info1,info2,..., " \-\-unpack\-info " info1,info2,..."
Collect information info1, info2, etc. even if these are not
required by the checks.
Reply to: