Bug#399714: ANSI color output (attached)
Package: lintian
Version: 1.23.26
Severity: wishlist
Tags: patch
Hi,
I wish lintian would support ANSI color output. The attached patch
works for me.
Bye,
-- System Information:
Debian Release: 4.0
APT prefers unstable
APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-2-686
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Versions of packages lintian depends on:
ii binutils 2.17-3 The GNU assembler, linker and bina
ii diffstat 1.43-2 produces graph of changes introduc
ii dpkg-dev 1.13.24 package building tools for Debian
ii file 4.17-4 Determines file type using "magic"
ii gettext 0.15-3 GNU Internationalization utilities
ii intltool-debian 0.35.0+20060710.1 Help i18n of RFC822 compliant conf
ii libparse-debianchangel 1.0-1 parse Debian changelogs and output
ii man-db 2.4.3-5 The on-line manual pager
ii perl [libdigest-md5-pe 5.8.8-6.1 Larry Wall's Practical Extraction
lintian recommends no packages.
-- no debconf information
--
Loïc Minier <lool@dooz.org>
10 SIN
20 GO TO ROBOT HELL -- Temple of Robotology
diff -urN lintian-1.23.26/debian/changelog lintian-1.23.27/debian/changelog
--- lintian-1.23.26/debian/changelog 2006-11-19 02:21:41.000000000 +0100
+++ lintian-1.23.27/debian/changelog 2006-11-21 15:49:22.000000000 +0100
@@ -1,3 +1,20 @@
+lintian (1.23.27) UNRELEASED; urgency=low
+
+ * 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.
+
+ -- Loic Minier <lool@dooz.org> Tue, 21 Nov 2006 15:48:48 +0100
+
lintian (1.23.26) unstable; urgency=low
* checks/binaries{.desc,}:
diff -urN lintian-1.23.26/doc/README lintian-1.23.27/doc/README
--- lintian-1.23.26/doc/README 2004-04-15 22:35:27.000000000 +0200
+++ lintian-1.23.27/doc/README 2006-11-21 15:43:19.000000000 +0100
@@ -74,6 +74,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
diff -urN lintian-1.23.26/frontend/lintian lintian-1.23.27/frontend/lintian
--- lintian-1.23.26/frontend/lintian 2006-11-11 11:18:35.000000000 +0100
+++ lintian-1.23.27/frontend/lintian 2006-11-21 15:52:40.000000000 +0100
@@ -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
diff -urN lintian-1.23.26/lib/Tags.pm lintian-1.23.27/lib/Tags.pm
--- lintian-1.23.26/lib/Tags.pm 2006-07-15 08:43:16.000000000 +0200
+++ lintian-1.23.27/lib/Tags.pm 2006-11-21 15:50:20.000000000 +0100
@@ -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,12 +290,19 @@
$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;
}
diff -urN lintian-1.23.26/man/lintian.1 lintian-1.23.27/man/lintian.1
--- lintian-1.23.26/man/lintian.1 2006-11-11 11:18:35.000000000 +0100
+++ lintian-1.23.27/man/lintian.1 2006-11-21 15:45:47.000000000 +0100
@@ -154,7 +154,11 @@
.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,..."
Reply to: