blib/lib/Term/Fabulous/Render/Border.pm

filter: Statementstmt 30.4% 32 / 105 Branchbran 0.0% 0 / 62 Conditioncond 0.0% 0 / 50 MC/DCmcdc 0.0% 0 / 30 Subroutinesub 56.2% 9 / 16 Podpod 100% 1 / 1 totaltotal 15.9% 42 / 264 CC 52 SCAR 52.0
CC
52
Cov
15%
render_border
420.0
__ANON__
210.0
__ANON__
56.0
CRAP 181.4
« tools/lib/Term/Fabulous/Screenshot/BoxDrawing.pm ↑ Summary blib/lib/Term/Fabulous/Render/Target/Grid.pm »
1 package Term::Fabulous::Render::Border;
2  
3 1 ▶use v5.32;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.05';
9  
10 1 ▶use Object::Pad 0.825;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 role Term::Fabulous::Render::Border {
13 1 ▶ use List::Util qw(min max);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶ use Term::Fabulous::Render::Attr qw(blended_bg_attr color_attr clay_color); # checks truecolor support first
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶ use Term::Fabulous::Termbox qw(TB_DEFAULT TB_REVERSE);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶ use Term::Fabulous::Render::Geometry qw(cell_rect);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # The cells the command being painted may touch (Term::Fabulous::Render).
19 1 method clip_rect;
20  
21 # The cell target the frame is painted into (Term::Fabulous::Render).
22 1 method cell_target;
23  
24 # Attributes for a border cell from its location code, following
25 # Textual's get_box styles: 0 = border color on the widget's background,
26 # 1 = border color on the parent's background, 2 and 3 are 1 and 0 in
27 # reverse video. Reverse video swaps terminal-default colors correctly,
28 # which an explicit fg/bg swap of TB_DEFAULT would not.
29 # The location code a glyph gets on a side drawn on the outer
30 # background: the codes that use the widget's background use the
31 # parent's instead.
32 0 ▶ sub _on_outer ($location) {
Subroutine _on_outer: not called CC=3 SCAR=24.8
33 0 ▶ return $location == 0 ? 1 : $location == 3 ? 2 : $location;
Branch: 2 branches
BranchTrueFalseTotal
$location == 0 ? : 0 0 0
$location == 3 ? : 0 0 0
34 }
35  
36 0 ▶ sub _location_attrs ( $location, $border, $inner, $outer ) {
Subroutine _location_attrs: not called CC=5 SCAR=34.0
37 0 ▶ return ( $border, $inner ) if $location == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $location == 0 0 0 0
38 0 ▶ return ( $border, $outer ) if $location == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $location == 1 0 0 0
39 0 ▶ return ( $border | TB_REVERSE, $outer ) if $location == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $location == 2 0 0 0
40 0 ▶ return ( $border | TB_REVERSE, $inner ) if $location == 3;
Branch: 1 branch
BranchTrueFalseTotal
if $location == 3 0 0 0
41 0 die "Term::Fabulous::Render::Border: invalid border location code '$location'";
42 }
43  
44 # Draws one glyph line per side whose Clay border width is positive;
45 # HasBorderStyle has already set the width of Hidden sides to 0. The
46 # "inner" background of a cell is the shadow buffer at that cell, the
47 # "outer" one is the cell just outside the box on the same side. Each
48 # side is drawn in the style HasBorderStyle's border_style_of answers.
49 # A side or corner with a border_background_color_of has that color
50 # painted over its inner background.
51 0 ▶ method render_border ( $command, $widget, $buffer ) {
Subroutine render_border: not called CC=20 SCAR=60.4
Pod documented
52 0 ▶ return unless defined $widget && $widget->DOES('Term::Fabulous::Role::HasBorderStyle');
Branch: 1 branch
BranchTrueFalseTotal
unless defined $widget and $widget->DOES("Term::Fabulous::Role::HasBorderStyle") 0 0 0
Condition0%0/3
defined $widget and $widget->DOES("Term::Fabulous::Role::HasBorderStyle")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $widget and $widget->DOES("Term::Fabulous::Role::HasBorderStyle")
defined $widget $widget->DOES("Term::Fabulous::Role::HasBorderStyle")
Truth table0%0/3
A and B
A= defined $widgetB= $widget->DOES("Term::Fabulous::Role::HasBorderStyle")
ABresult
0X0
100
111
53  
54 0 my $data = $command->{renderData};
55 0 ▶ my $widths = $data->{width} // {};
Condition0%0/2
$data->{"width"} // {}
l!l
00
MC/DC0%0/1
$data->{"width"} // {}
$data->{"width"}
Truth table0%0/2
A
A= $data->{"width"}
Aresult
11
00
56 0 ▶ my ( $top, $right, $bottom, $left ) = map { ( $widths->{$_} // 0 ) > 0 ? 1 : 0 } qw(top right bottom left);
Branch: 1 branch
BranchTrueFalseTotal
($widths->{$_} // 0) > 0 ? : 0 0 0
Condition0%0/2
$widths->{$_} // 0
l!l
00
MC/DC0%0/1
$widths->{$_} // 0
$widths->{$_}
Truth table0%0/2
A
A= $widths->{$_}
Aresult
11
00
57 0 ▶ return unless $top || $right || $bottom || $left;
Branch: 1 branch
BranchTrueFalseTotal
unless $top or $right or $bottom or $left 0 0 0
Condition0%0/9
$top or $right or $bottom or $left
l!l&&r!l&&!r
000
$top or $right or $bottom
l!l&&r!l&&!r
000
$top or $right
l!l&&r!l&&!r
000
MC/DC0%0/4
$top or $right or $bottom or $left
$top $right $bottom $left
Truth table0%0/5
A or B or C or D
A= $topB= $rightC= $bottomD= $left
ABCDresult
1XXX1
01XX1
001X1
00011
00000
58  
59 0 my ( $x0, $y0, $x1, $y1 ) = cell_rect( $command->{boundingBox} );
60 0 my ( $last_x, $last_y ) = ( $x1 - 1, $y1 - 1 );
61 0 ▶ return if $last_x < $x0 || $last_y < $y0;
Branch: 1 branch
BranchTrueFalseTotal
if $last_x < $x0 or $last_y < $y0 0 0 0
Condition0%0/3
$last_x < $x0 or $last_y < $y0
l!l&&r!l&&!r
000
MC/DC0%0/2
$last_x < $x0 or $last_y < $y0
$last_x < $x0 $last_y < $y0
Truth table0%0/3
A or B
A= $last_x < $x0B= $last_y < $y0
ABresult
1X1
011
000
62  
63 # A box one cell high (wide) has a single row (column): draw it once.
64 0 ▶ $bottom = 0 if $top && $last_y == $y0;
Branch: 1 branch
BranchTrueFalseTotal
if $top and $last_y == $y0 0 0 0
Condition0%0/3
$top and $last_y == $y0
!ll&&!rl&&r
000
MC/DC0%0/2
$top and $last_y == $y0
$top $last_y == $y0
Truth table0%0/3
A and B
A= $topB= $last_y == $y0
ABresult
0X0
100
111
65 0 ▶ $right = 0 if $left && $last_x == $x0;
Branch: 1 branch
BranchTrueFalseTotal
if $left and $last_x == $x0 0 0 0
Condition0%0/3
$left and $last_x == $x0
!ll&&!rl&&r
000
MC/DC0%0/2
$left and $last_x == $x0
$left $last_x == $x0
Truth table0%0/3
A and B
A= $leftB= $last_x == $x0
ABresult
0X0
100
111
66  
67 0 my ( $clip_x0, $clip_y0, $clip_x1, $clip_y1 ) = @{ $self->clip_rect };
68 0 my $border_attr = color_attr( clay_color( $data->{color} ) );
69 0 my $target = $self->cell_target;
70  
71 0 ▶ my $shade_at = sub ( $x, $y ) {
Subroutine __ANON__: not called CC=5 SCAR=34.0
72 0 ▶ return TB_DEFAULT if $x < 0 || $y < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $x < 0 or $y < 0 0 0 0
Condition0%0/3
$x < 0 or $y < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$x < 0 or $y < 0
$x < 0 $y < 0
Truth table0%0/3
A or B
A= $x < 0B= $y < 0
ABresult
1X1
011
000
73 0 ▶ my $shade_row = $buffer->[$y] // return TB_DEFAULT;
Condition0%0/2
$buffer->[$y] // (return 0)
l!l
00
MC/DC0%0/1
$buffer->[$y] // (return 0)
$buffer->[$y]
Truth table0%0/2
A
A= $buffer->[$y]
Aresult
11
00
74 0 ▶ return $shade_row->[$x] // TB_DEFAULT;
Condition0%0/2
$shade_row->[$x] // 0
l!l
00
MC/DC0%0/1
$shade_row->[$x] // 0
$shade_row->[$x]
Truth table0%0/2
A
A= $shade_row->[$x]
Aresult
11
00
75 0 };
76 0 ▶ my $paint = sub ( $x, $y, $glyph, $location, $outer_x, $outer_y, $backdrop ) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
77 0 ▶ return if $y < $clip_y0 || $y >= $clip_y1;
Branch: 1 branch
BranchTrueFalseTotal
if $y < $clip_y0 or $y >= $clip_y1 0 0 0
Condition0%0/3
$y < $clip_y0 or $y >= $clip_y1
l!l&&r!l&&!r
000
MC/DC0%0/2
$y < $clip_y0 or $y >= $clip_y1
$y < $clip_y0 $y >= $clip_y1
Truth table0%0/3
A or B
A= $y < $clip_y0B= $y >= $clip_y1
ABresult
1X1
011
000
78 0 ▶ my $inner = defined $backdrop ? blended_bg_attr( $backdrop, $shade_at->( $x, $y ) ) : $shade_at->( $x, $y );
Branch: 1 branch
BranchTrueFalseTotal
defined $backdrop ? : 0 0 0
79 0 my ( $fg, $bg ) = _location_attrs( $location, $border_attr, $inner, $shade_at->( $outer_x, $outer_y ) );
80 0 $target->set_cell( $x, $y, $glyph, $fg, $bg );
81 0 };
82 0 my %outer = map { $_ => $widget->is_outer_border_side($_) } qw(top right bottom left);
83  
84 # A corner lies on the side next to it as much as on its edge: when
85 # that side is drawn on the outer background, so is the corner, on the
86 # background beside the box.
87 0 ▶ my $paint_row = sub ( $y, $outer_y, $glyphs, $locations, $edge ) {
Subroutine __ANON__: not called CC=14 SCAR=53.5
88 0 my @corners = map { $widget->border_corner_glyph("${edge}_$_") } qw(left right);
89 0 my @backdrops = map { $widget->border_background_color_of($_) } "${edge}_left", $edge, "${edge}_right";
90 0 foreach my $x ( max( $x0, $clip_x0 ) .. min( $last_x, $clip_x1 - 1 ) ) {
91 0 ▶ my $slot = $x == $x0 && $left ? 0 : $x == $last_x && $right ? 2 : 1;
Branch: 2 branches
BranchTrueFalseTotal
$x == $x0 && $left ? : 0 0 0
$x == $last_x && $right ? : 0 0 0
Condition0%0/6
$x == $x0 and $left
!ll&&!rl&&r
000
$x == $last_x and $right
!ll&&!rl&&r
000
MC/DC0%0/2
$x == $x0 and $left
$x == $x0 $left
MC/DC0%0/2
$x == $last_x and $right
$x == $last_x $right
Truth table0%0/3
A and B
A= $x == $x0B= $left
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $x == $last_xB= $right
ABresult
0X0
100
111
92 0 ▶ my $glyph = $slot == 1 ? $glyphs->[1] : $corners[ $slot / 2 ] // $glyphs->[$slot];
Branch: 1 branch
BranchTrueFalseTotal
$slot == 1 ? : 0 0 0
Condition0%0/3
$corners[$slot / 2] // $glyphs->[$slot]
l!l&&r!l&&!r
000
MC/DC0%0/2
$corners[$slot / 2] // $glyphs->[$slot]
$corners[$slot / 2] $glyphs->[$slot]
Truth table0%0/3
A // B
A= $corners[$slot / 2]B= $glyphs->[$slot]
ABresult
1X1
011
000
93 0 ▶ my $side = $slot == 0 ? 'left' : $slot == 2 ? 'right' : undef;
Branch: 2 branches
BranchTrueFalseTotal
$slot == 0 ? : 0 0 0
$slot == 2 ? : 0 0 0
94 0 my $location = $locations->[$slot];
95 0 ▶ if ( defined $side && $outer{$side} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $side and $outer{$side}) 0 0 0
Condition0%0/3
defined $side and $outer{$side}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $side and $outer{$side}
defined $side $outer{$side}
Truth table0%0/3
A and B
A= defined $sideB= $outer{$side}
ABresult
0X0
100
111
96 0 ▶ $paint->( $x, $y, $glyph, _on_outer($location), $slot == 0 ? $x - 1 : $x + 1, $y, undef );
Branch: 1 branch
BranchTrueFalseTotal
$slot == 0 ? : 0 0 0
97 0 next;
98 }
99 0 ▶ $paint->( $x, $y, $glyph, $outer{$edge} ? _on_outer($location) : $location, $x, $outer_y, $backdrops[$slot] );
Branch: 1 branch
BranchTrueFalseTotal
$outer{$edge} ? : 0 0 0
100 }
101 0 };
102 0 ▶ my $paint_column = sub ( $x, $outer_x, $glyph, $location, $side ) {
Subroutine __ANON__: not called CC=7 SCAR=40.3
103 0 ▶ return if $x < $clip_x0 || $x >= $clip_x1;
Branch: 1 branch
BranchTrueFalseTotal
if $x < $clip_x0 or $x >= $clip_x1 0 0 0
Condition0%0/3
$x < $clip_x0 or $x >= $clip_x1
l!l&&r!l&&!r
000
MC/DC0%0/2
$x < $clip_x0 or $x >= $clip_x1
$x < $clip_x0 $x >= $clip_x1
Truth table0%0/3
A or B
A= $x < $clip_x0B= $x >= $clip_x1
ABresult
1X1
011
000
104 0 ▶ my $from = $top ? $y0 + 1 : $y0;
Branch: 1 branch
BranchTrueFalseTotal
$top ? : 0 0 0
105 0 ▶ my $to = $bottom ? $last_y - 1 : $last_y;
Branch: 1 branch
BranchTrueFalseTotal
$bottom ? : 0 0 0
106 0 ▶ $location = _on_outer($location) if $outer{$side};
Branch: 1 branch
BranchTrueFalseTotal
if $outer{$side} 0 0 0
107 0 my $backdrop = $widget->border_background_color_of($side);
108 0 foreach my $y ( max( $from, $clip_y0 ) .. min( $to, $clip_y1 - 1 ) ) {
109 0 $paint->( $x, $y, $glyph, $location, $outer_x, $y, $backdrop );
110 }
111 0 };
112  
113 0 ▶ if ($top) {
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
114 0 my $style = $widget->border_style_of('top');
115 0 $paint_row->( $y0, $y0 - 1, [ $style->get_top_glyphs ], [ $style->get_top_locations ], 'top' );
116 }
117 0 ▶ if ($bottom) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bottom) 0 0 0
118 0 my $style = $widget->border_style_of('bottom');
119 0 $paint_row->( $last_y, $last_y + 1, [ $style->get_bottom_glyphs ], [ $style->get_bottom_locations ], 'bottom' );
120 }
121 0 ▶ if ($left) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left) 0 0 0
122 0 my $style = $widget->border_style_of('left');
123 0 $paint_column->( $x0, $x0 - 1, $style->get_left_glyphs, $style->get_left_locations, 'left' );
124 }
125 0 ▶ if ($right) {
Branch: 1 branch
BranchTrueFalseTotal
if ($right) 0 0 0
126 0 my $style = $widget->border_style_of('right');
127 0 $paint_column->( $last_x, $last_x + 1, $style->get_right_glyphs, $style->get_right_locations, 'right' );
128 }
129 0 return;
130 1 }
131 }
132  
133 1 1;
134  
135 __END__
« tools/lib/Term/Fabulous/Screenshot/BoxDrawing.pm ↑ Summary blib/lib/Term/Fabulous/Render/Target/Grid.pm »