line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Tel::Color::CiscoPingRainbow; |
2
|
1
|
|
|
1
|
|
755
|
use parent 'App::Tel::Color::Base'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
3
|
1
|
|
|
1
|
|
52
|
use Term::ANSIColor; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
270
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head2 new |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $color = App::Tel::CiscoPingRainbowColors->new; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
New color object.. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
17
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
return bless( { |
20
|
|
|
|
|
|
|
'current_color' => 0, |
21
|
|
|
|
|
|
|
'ping' => 0, |
22
|
|
|
|
|
|
|
}, $class); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _next_color { |
26
|
0
|
|
|
0
|
|
|
my $self = shift; |
27
|
0
|
|
|
|
|
|
return colored(shift, $App::Tel::ColorObject::colors[$self->{current_color}++ % scalar(@App::Tel::ColorObject::colors)]); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 colorize |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $output = $self->colorize($input); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Given a line of text from a cisco router, this will try to colorize it. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub colorize { |
40
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
41
|
0
|
|
|
|
|
|
$_ = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# We need to define a start point in the buffer that the dot regex isn't |
44
|
|
|
|
|
|
|
# allowed to search before so that this line and ones before it with |
45
|
|
|
|
|
|
|
# dots don't get red dots. |
46
|
0
|
0
|
|
|
|
|
if (/Sending \d+, \d+-byte ICMP Echos to/) { |
47
|
0
|
|
|
|
|
|
$self->{ping}=1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
if ($self->{ping}) { |
51
|
0
|
|
|
|
|
|
s/(\!)/$self->_next_color($1)/eg; |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
s/(\.)/colored('.', 'red')/eg; |
|
0
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if (/Success rate is/) { |
54
|
0
|
|
|
|
|
|
$self->{ping}=0; |
55
|
0
|
|
|
|
|
|
$self->{current_color}=0; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
return $_; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |