line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Color::Theme::Role::ANSI; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2014-12-11'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7562
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
7
|
1
|
|
|
1
|
|
4
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
843
|
use Color::ANSI::Util (); |
|
1
|
|
|
|
|
3769
|
|
|
1
|
|
|
|
|
487
|
|
10
|
|
|
|
|
|
|
with 'Color::Theme::Role'; |
11
|
|
|
|
|
|
|
with 'Term::App::Role::Attrs'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub theme_color_to_ansi { |
14
|
2
|
|
|
2
|
1
|
919
|
my ($self, $c, $args, $is_bg) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# empty? skip |
17
|
2
|
50
|
33
|
|
|
12
|
return '' if !defined($c) || !length($c); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# resolve coderef color |
20
|
2
|
50
|
|
|
|
9
|
if (ref($c) eq 'CODE') { |
21
|
0
|
|
0
|
|
|
0
|
$args //= {}; |
22
|
0
|
|
|
|
|
0
|
$c = $c->($self, %$args); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
6
|
my $coldepth = $self->color_depth; |
26
|
|
|
|
|
|
|
|
27
|
2
|
50
|
|
|
|
468
|
if ($coldepth >= 2**24) { |
|
|
50
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
0
|
if (ref $c) { |
29
|
0
|
|
|
|
|
0
|
my $ansifg = $c->{ansi_fg}; |
30
|
0
|
0
|
0
|
|
|
0
|
$ansifg //= Color::ANSI::Util::ansi24bfg($c->{fg}) |
31
|
|
|
|
|
|
|
if defined $c->{fg}; |
32
|
0
|
|
0
|
|
|
0
|
$ansifg //= ""; |
33
|
0
|
|
|
|
|
0
|
my $ansibg = $c->{ansi_bg}; |
34
|
0
|
0
|
0
|
|
|
0
|
$ansibg //= Color::ANSI::Util::ansi24bbg($c->{bg}) |
35
|
|
|
|
|
|
|
if defined $c->{bg}; |
36
|
0
|
|
0
|
|
|
0
|
$ansibg //= ""; |
37
|
0
|
|
|
|
|
0
|
$c = $ansifg . $ansibg; |
38
|
|
|
|
|
|
|
} else { |
39
|
0
|
0
|
|
|
|
0
|
$c = $is_bg ? Color::ANSI::Util::ansi24bbg($c) : |
40
|
|
|
|
|
|
|
Color::ANSI::Util::ansi24bfg($c); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} elsif ($coldepth >= 256) { |
43
|
0
|
0
|
|
|
|
0
|
if (ref $c) { |
44
|
0
|
|
|
|
|
0
|
my $ansifg = $c->{ansi_fg}; |
45
|
0
|
0
|
0
|
|
|
0
|
$ansifg //= Color::ANSI::Util::ansi256fg($c->{fg}) |
46
|
|
|
|
|
|
|
if defined $c->{fg}; |
47
|
0
|
|
0
|
|
|
0
|
$ansifg //= ""; |
48
|
0
|
|
|
|
|
0
|
my $ansibg = $c->{ansi_bg}; |
49
|
0
|
0
|
0
|
|
|
0
|
$ansibg //= Color::ANSI::Util::ansi256bg($c->{bg}) |
50
|
|
|
|
|
|
|
if defined $c->{bg}; |
51
|
0
|
|
0
|
|
|
0
|
$ansibg //= ""; |
52
|
0
|
|
|
|
|
0
|
$c = $ansifg . $ansibg; |
53
|
|
|
|
|
|
|
} else { |
54
|
0
|
0
|
|
|
|
0
|
$c = $is_bg ? Color::ANSI::Util::ansi256bg($c) : |
55
|
|
|
|
|
|
|
Color::ANSI::Util::ansi256fg($c); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} else { |
58
|
2
|
100
|
|
|
|
5
|
if (ref $c) { |
59
|
1
|
|
|
|
|
2
|
my $ansifg = $c->{ansi_fg}; |
60
|
1
|
50
|
33
|
|
|
8
|
$ansifg //= Color::ANSI::Util::ansi16fg($c->{fg}) |
61
|
|
|
|
|
|
|
if defined $c->{fg}; |
62
|
1
|
|
50
|
|
|
48
|
$ansifg //= ""; |
63
|
1
|
|
|
|
|
2
|
my $ansibg = $c->{ansi_bg}; |
64
|
1
|
50
|
33
|
|
|
7
|
$ansibg //= Color::ANSI::Util::ansi16bg($c->{bg}) |
65
|
|
|
|
|
|
|
if defined $c->{bg}; |
66
|
1
|
|
50
|
|
|
48
|
$ansibg //= ""; |
67
|
1
|
|
|
|
|
3
|
$c = $ansifg . $ansibg; |
68
|
|
|
|
|
|
|
} else { |
69
|
1
|
50
|
|
|
|
6
|
$c = $is_bg ? Color::ANSI::Util::ansi16bg($c) : |
70
|
|
|
|
|
|
|
Color::ANSI::Util::ansi16fg($c); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
2
|
|
|
|
|
69
|
$c; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub get_theme_color_as_ansi { |
77
|
0
|
|
|
0
|
1
|
|
my ($self, $item_name, $args) = @_; |
78
|
0
|
|
0
|
|
|
|
$self->theme_color_to_ansi( |
79
|
|
|
|
|
|
|
$self->get_theme_color($item_name), |
80
|
0
|
|
|
|
|
|
{name=>$item_name, %{ $args // {} }}, |
81
|
|
|
|
|
|
|
$item_name =~ /_bg$/, |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
# ABSTRACT: Role for class wanting to support color themes (ANSI support) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |