SVN: toys/stbr/queue_parser.pl

sparky sparky at pld-linux.org
Fri Oct 30 13:59:30 CET 2009


Author: sparky
Date: Fri Oct 30 13:59:29 2009
New Revision: 10886

Modified:
   toys/stbr/queue_parser.pl   (contents, props changed)
Log:
- also support terminal colours


Modified: toys/stbr/queue_parser.pl
==============================================================================
--- toys/stbr/queue_parser.pl	(original)
+++ toys/stbr/queue_parser.pl	Fri Oct 30 13:59:29 2009
@@ -37,7 +37,7 @@
 	UNSUPP => "magenta",
 );
 
-my %color_to_code = (
+my %color_to_code_irc = (
 	red => 5,
 	green => 3,
 	yellow => 7,
@@ -45,12 +45,29 @@
 	magenta => 6,
 	"" => 0,
 );
-sub color
+sub color_irc
 {
-	my $color = shift || "";
+	my $color = shift;
+	return "\017" unless $color;
 	return "\002" if $color eq "bold";
-	return "\003" . $color_to_code{$color};
+	return "\003" . $color_to_code_irc{$color};
+}
+my %color_to_code_term = (
+	red => 31,
+	green => 32,
+	yellow => 33,
+	blue => 34,
+	magenta => 35,
+	bold => 1,
+	"" => 0,
+);
+sub color_term
+{
+	my $color = shift || "";
+	return "\033[" . $color_to_code_term{$color} . "m";
+
 }
+*main::color = $ENV{TERM} ? \&color_term : \&color_irc;
 
 sub get
 {
@@ -101,6 +118,7 @@
 			($rpm) = $p =~ m{<command flags="">(.*?)</command>};
 		}
 
+		my $e = color();
 		my $all_done = 1;
 		my $some_done = 0;
 		my @status;
@@ -108,7 +126,7 @@
 		foreach my $b ( @builders ) {
 			my ( $status, $builder ) = $b =~ m{status='(.*?)'.*?>(.*?)</builder>};
 			my $color = $status_to_color{ $status } || "red";
-			push @status, "$builder: " . color($color) . "$status\017";
+			push @status, "$builder: " . color($color) . "$status$e";
 			if ( $status eq "?" ) {
 				$all_done = 0;
 			} else {
@@ -131,7 +149,8 @@
 		if ( defined $print ) {
 			$printed{$id} = $print;
 			$printed_something++;
-			print color( "yellow" ) ."$line\017: $rpm\002:\017 " . ( join ", ", @status ) . "\n";
+			my $b = color( "bold" );
+			print color( "yellow" ) ."$line$e: $rpm$b:$e " . ( join ", ", @status ) . "\n";
 		}
 	}
 	$data->{last_time} = $time if $done_so_far;


More information about the pld-cvs-commit mailing list