line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Archlinux::Term; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
110037
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
127
|
|
4
|
4
|
|
|
4
|
|
19
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
143
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
4597
|
use Term::ANSIColor qw(color); |
|
4
|
|
|
|
|
51874
|
|
|
4
|
|
|
|
|
2435
|
|
7
|
4
|
|
|
4
|
|
5125
|
use Text::Wrap qw(wrap); |
|
4
|
|
|
|
|
28764
|
|
|
4
|
|
|
|
|
264
|
|
8
|
4
|
|
|
4
|
|
34
|
use Exporter; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
2702
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(msg status substatus warning error); |
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ @EXPORT_OK ] ); |
13
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our ($Columns, $Mono) = (78, undef); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _word_wrap |
18
|
|
|
|
|
|
|
{ |
19
|
13
|
|
|
13
|
|
27
|
my ($prefix, $msg) = @_; |
20
|
|
|
|
|
|
|
|
21
|
13
|
100
|
|
|
|
21
|
if ( eval { $Columns > 0 } ) { |
|
13
|
|
|
|
|
52
|
|
22
|
12
|
|
|
|
|
34
|
my $spaces = q{ } x length $prefix; |
23
|
|
|
|
|
|
|
|
24
|
12
|
|
|
|
|
27
|
local $Text::Wrap::columns = $Columns + 1; |
25
|
12
|
|
|
|
|
46
|
return wrap( $prefix, $spaces, $msg ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
7
|
return $prefix . $msg; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _color_wrap |
32
|
|
|
|
|
|
|
{ |
33
|
11
|
|
|
11
|
|
36
|
my ($color, $prefix, @messages) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Wrap the uncolored first because ANSI color chars mess up wrap() |
36
|
|
|
|
|
|
|
# (it doesn't know the ANSI color codes are invisible) |
37
|
11
|
|
|
|
|
29
|
my $msg = join q{}, @messages; |
38
|
11
|
|
|
|
|
26
|
$msg =~ s/\s*\n\s*/ /g; |
39
|
|
|
|
|
|
|
|
40
|
11
|
|
|
|
|
48
|
my $result = _word_wrap( $prefix, $msg ); |
41
|
11
|
|
|
|
|
2650
|
my $prefix_match = quotemeta $prefix; |
42
|
|
|
|
|
|
|
|
43
|
11
|
100
|
|
|
|
45
|
return $result if ( $Mono ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Now colorize the prefix and stuff... |
46
|
8
|
|
|
|
|
192
|
$result =~ s{ \A $prefix_match } # Use \033[0;1m cuz Term::ANSIColor |
47
|
8
|
|
|
|
|
31
|
{ color( 'BOLD', $color ) . $prefix . "\e[0;1m" }exms; |
48
|
8
|
|
|
|
|
267
|
$result .= color( 'RESET' ); # ... doesnt have very bright white! |
49
|
|
|
|
|
|
|
|
50
|
8
|
|
|
|
|
503
|
return $result; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub msg |
54
|
|
|
|
|
|
|
{ |
55
|
2
|
|
|
2
|
1
|
3913
|
my @messages = @_; |
56
|
2
|
|
|
|
|
7
|
chomp $messages[-1]; |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
6
|
my $prefix = q{ } x 4; |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
13
|
print _word_wrap( $prefix, join q{}, @messages ), "\n"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub status |
64
|
|
|
|
|
|
|
{ |
65
|
5
|
|
|
5
|
1
|
13536
|
print _color_wrap( 'GREEN' => q{==> }, @_ ), "\n"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub substatus |
69
|
|
|
|
|
|
|
{ |
70
|
2
|
|
|
2
|
1
|
1641
|
print _color_wrap( 'BLUE' => q{ -> }, @_ ), "\n"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub warning |
74
|
|
|
|
|
|
|
{ |
75
|
2
|
|
|
2
|
1
|
1132
|
my @args = @_; |
76
|
2
|
|
|
|
|
7
|
chomp $args[-1]; |
77
|
2
|
|
|
|
|
7
|
warn _color_wrap( 'YELLOW' => q{==> WARNING: }, @args ), "\n"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub error |
81
|
|
|
|
|
|
|
{ |
82
|
2
|
|
|
2
|
1
|
1056
|
my @args = @_; |
83
|
2
|
|
|
|
|
6
|
chomp $args[-1]; |
84
|
2
|
|
|
|
|
7
|
die _color_wrap( 'RED' => q{==> ERROR: }, @args ), "\n"; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |