line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ColorThemeUtil::ANSI; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2021-02-06'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'ColorThemeUtil-ANSI'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
68527
|
use 5.010001; |
|
1
|
|
|
|
|
11
|
|
9
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
10
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use Exporter 'import'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
286
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
14
|
|
|
|
|
|
|
item_color_to_ansi |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub item_color_to_ansi { |
18
|
1
|
|
|
1
|
1
|
718
|
require Color::ANSI::Util; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
9508
|
my ($color, $is_bg) = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
50
|
33
|
|
|
10
|
return unless defined $color && length($color); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# force color depth detection |
25
|
1
|
|
|
|
|
4
|
Color::ANSI::Util::_color_depth(); |
26
|
|
|
|
|
|
|
|
27
|
1
|
50
|
|
|
|
17
|
return "" if !$Color::ANSI::Util::_color_depth; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
2
|
my $ansi; |
30
|
1
|
50
|
|
|
|
15
|
if (ref $color eq 'HASH') { |
|
|
50
|
|
|
|
|
|
31
|
0
|
|
|
|
|
0
|
my $ansifg = $color->{ansi_fg}; |
32
|
|
|
|
|
|
|
$ansifg //= Color::ANSI::Util::ansifg($color->{fg}) |
33
|
0
|
0
|
0
|
|
|
0
|
if defined $color->{fg}; |
34
|
0
|
|
0
|
|
|
0
|
$ansifg //= ""; |
35
|
0
|
|
|
|
|
0
|
my $ansibg = $color->{ansi_bg}; |
36
|
|
|
|
|
|
|
$ansibg //= Color::ANSI::Util::ansibg($color->{bg}) |
37
|
0
|
0
|
0
|
|
|
0
|
if defined $color->{bg}; |
38
|
0
|
|
0
|
|
|
0
|
$ansibg //= ""; |
39
|
0
|
|
|
|
|
0
|
$ansi = $ansifg . $ansibg; |
40
|
|
|
|
|
|
|
} elsif (ref $color) { |
41
|
0
|
|
|
|
|
0
|
die "Cannot handle color $color"; |
42
|
|
|
|
|
|
|
} else { |
43
|
1
|
50
|
|
|
|
6
|
$ansi = $is_bg ? Color::ANSI::Util::ansibg($color) : |
44
|
|
|
|
|
|
|
Color::ANSI::Util::ansifg($color); |
45
|
|
|
|
|
|
|
} |
46
|
1
|
|
|
|
|
1213
|
$ansi; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
# ABSTRACT: Utility routines related to color themes and ANSI code |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__END__ |