/[Sack]/trunk/lib/Sack/Color.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Sack/Color.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 102 - (show annotations)
Mon Oct 5 20:31:28 2009 UTC (14 years, 8 months ago) by dpavlin
File size: 484 byte(s)
color [port] in warn messages

1 package Sock::Color;
2
3 use warnings;
4 use strict;
5
6 sub BEGIN {
7
8 sub port2color {
9 my $port = shift;
10 return "\e[1m0\e[0m" if $port == 0;
11
12 my $c = ( $port % 6 ) + 31;
13 return "\e[${c}m$port\e[0m";
14 }
15
16 $SIG{__WARN__} = sub {
17 return unless @_;
18 my $msg = join('', @_);
19 if ( $msg !~ m{[\n\r]$} ) {
20 my @loc = caller(1);
21 $msg .= " in $loc[1] +$loc[2]\n" if @loc;
22 }
23 $msg =~ s{\[(0|\d\d\d\d)\]}{ '[' . port2color($1) . ']' }eg;
24 print STDERR $msg;
25 return 1;
26 };
27
28 }
29
30 1;

  ViewVC Help
Powered by ViewVC 1.1.26