File Coverage

blib/lib/App/sdview/Style.pm
Criterion Covered Total %
statement 29 29 100.0
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod 0 2 0.0
total 38 41 92.6


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2023 -- leonerd@leonerd.org.uk
5              
6 2     2   472 use v5.26;
  2         7  
7 2     2   18 use warnings;
  2         25  
  2         62  
8 2     2   17 use experimental 'signatures';
  2         4  
  2         29  
9              
10             package App::sdview::Style 0.11;
11              
12 2     2   1256 use Convert::Color;
  2         72485  
  2         126  
13 2     2   1049 use Convert::Color::XTerm 0.06;
  2         6562  
  2         919  
14              
15             my %FORMATSTYLES = (
16             B => { bold => 1 },
17             I => { italic => 1 },
18             F => { italic => 1, under => 1 },
19             C => { monospace => 1, bg => Convert::Color->new( "xterm:235" ) },
20             L => { under => 1, fg => Convert::Color->new( "xterm:rgb(3,3,5)" ) }, # light blue
21             );
22              
23 34         51 sub convert_str ( $pkg, $s )
24 34     34 0 44 {
  34         52  
  34         44  
25             return $s->clone(
26             convert_tags => {
27 34     7   102 ( map { $_ => do { my $k = $_; sub { $FORMATSTYLES{$k}->%* } } } keys %FORMATSTYLES ),
  170         219  
  170         222  
  170         566  
  7         662  
28             },
29             );
30             }
31              
32             my %PARASTYLES = (
33             head1 => { fg => Convert::Color->new( "vga:yellow" ), bold => 1 },
34             head2 => { fg => Convert::Color->new( "vga:cyan" ), bold => 1, indent => 2 },
35             head3 => { fg => Convert::Color->new( "vga:green" ), bold => 1, indent => 4 },
36             head4 => { fg => Convert::Color->new( "xterm:217" ), under => 1, indent => 5 },
37             plain => { indent => 6, blank_after => 1 },
38             verbatim => { indent => 8, blank_after => 1, $FORMATSTYLES{C}->%* },
39             list => { indent => 6 },
40             leader => { bold => 1 },
41             table => { indent => 8 },
42             "table-heading" => { bold => 1 },
43             );
44             $PARASTYLES{item} = $PARASTYLES{plain};
45              
46 41         65 sub para_style ( $pkg, $type )
47 41     41 0 61 {
  41         71  
  41         60  
48 41 50       97 $PARASTYLES{$type} or
49             die "Unrecognised paragraph style for $type";
50              
51 41         165 return $PARASTYLES{$type};
52             }
53              
54             0x55AA;