Caa/DriverANSI.pm

filter: Statementstmt 35.2% 12 / 34 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 5 totaltotal 27.7% 15 / 54 CC 5 SCAR 22.0
CC
5
Cov
29%
set_color
20.0
putchar
6.0
init
2.0
CRAP 9.0
« Caa.pm ↑ Summary Caa/DitherOrdered2.pm »
1 package Image::Caa::DriverANSI;
2
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 9 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
7 9 my ($class) = @_;
8
9 9 my $self = bless {}, $class;
10
11 $self->{color_map} = {
12 9 int(Image::Caa::CAA_COLOR_BLACK) => [30,1],
13 int(Image::Caa::CAA_COLOR_RED) => [31,1],
14 int(Image::Caa::CAA_COLOR_GREEN) => [32,1],
15 int(Image::Caa::CAA_COLOR_YELLOW) => [33,1],
16 int(Image::Caa::CAA_COLOR_BLUE) => [34,1],
17 int(Image::Caa::CAA_COLOR_MAGENTA) => [35,1],
18 int(Image::Caa::CAA_COLOR_CYAN) => [36,1],
19 int(Image::Caa::CAA_COLOR_LIGHTGRAY) => [37,1],
20
21 int(Image::Caa::CAA_COLOR_DARKGRAY) => [30,0],
22 int(Image::Caa::CAA_COLOR_LIGHTRED) => [31,0],
23 int(Image::Caa::CAA_COLOR_LIGHTGREEN) => [32,0],
24 int(Image::Caa::CAA_COLOR_BROWN) => [33,0],
25 int(Image::Caa::CAA_COLOR_LIGHTBLUE) => [34,0],
26 int(Image::Caa::CAA_COLOR_LIGHTMAGENTA) => [35,0],
27 int(Image::Caa::CAA_COLOR_LIGHTCYAN) => [36,0],
28 int(Image::Caa::CAA_COLOR_WHITE) => [37,0],
29 };
30
31 9 $self->{color_pairs} = {};
32
33 9 return $self;
34 }
35
36 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
37 0 my ($self) = @_;
38
39 0 $self->{current_color_key} = '';
40 0 $self->{last_x} = 0;
41 }
42
43 0 ▶sub set_color{
Subroutine set_color: not called CC=4 SCAR=30.0
Pod undocumented
44 0 my ($self, $fg, $bg) = @_;
45
46 0 my $key = "$fg:$bg";
47
48 0 $self->{current_color_key} = $key;
49
50 0 ▶ if (!defined $self->{color_pairs}->{$key}){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"color_pairs"}{$key}) 0 0 0
51
52 0 my ($fg_col, $fg_dark) = @{$self->{color_map}->{$fg}};
53 0 my ($bg_col, $bg_dark) = @{$self->{color_map}->{$bg}};
54
55 0 $bg_col += 10;
56
57 0 ▶ $self->{color_pairs}->{$key} = "\e[${fg_col};".($fg_dark?2:1).";${bg_col};".($bg_dark?6:5)."m";
Branch: 2 branches
BranchTrueFalseTotal
$fg_dark ? : 0 0 0
$bg_dark ? : 0 0 0
58 }
59 }
60
61 0 ▶sub putchar{
Subroutine putchar: not called CC=2 SCAR=17.9
Pod undocumented
62 0 my ($self, $x, $y, $outch) = @_;
63
64 0 ▶ if ($x < $self->{last_x}){
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $self->{"last_x"}) 0 0 0
65
66 0 print "\n";
67 }
68
69 0 $self->{last_x} = $x;
70
71 0 print $self->{color_pairs}->{$self->{current_color_key}};
72 0 print $outch;
73 0 print "\e[0m";
74 }
75
76 0 ▶sub fini {
Subroutine fini: not called CC=1 SCAR=6.9
Pod undocumented
77 0 my ($self) = @_;
78
79 0 print "\n";
80 }
81
82 1 1;
« Caa.pm ↑ Summary Caa/DitherOrdered2.pm »