Term.pm

filter: Statementstmt 54.5% 24 / 44 Branchbran 54.1% 13 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 4 totaltotal 47.6% 40 / 84 CC 6 SCAR 18.3
CC
6
Cov
52%
translate_theme_colour
12.0
get_theme_var
6.0
get_theme_colour
6.0
CRAP 6.2
« Term/Widget/Scroller.pm ↑ Summary Term/Tab.pm »
1 # You may distribute under the terms of the GNU General Public License
2 #
3 # (C) Paul Evans, 2008-2023 -- leonerd@leonerd.org.uk
4  
5 package Circle::FE::Term 0.240250;
6  
7 1 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use File::ShareDir qw( dist_file );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 C<Circle::FE::Term> - Terminal frontend for the C<Circle> application host
15  
16 =cut
17  
18 1 my %theme_vars;
19  
20 {
21 1 my $theme_filename;
22  
23 1 foreach ( $ENV{CIRCLE_FE_TERM_THEME},
24 "$ENV{HOME}/.circle-fe-term.theme",
25 dist_file( "circle-fe-term", "circle-fe-term.theme" ) ) {
26 3 ▶ defined $_ or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or next 2 1 3
27 2 ▶ -e $_ or next;
Branch: 1 branch
BranchTrueFalseTotal
-e $_ or next 1 1 2
28  
29 1 $theme_filename = $_;
30 1 last;
31 }
32  
33 1 ▶ defined $theme_filename or die "Cannot find a circle-fe-term.theme";
Branch: 1 branch
BranchTrueFalseTotal
defined $theme_filename or die "Cannot find a circle-fe-term.theme" 1 0 1
34  
35 1 ▶ open( my $themefh, "<", $theme_filename ) or die "Cannot read $theme_filename - $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $themefh, "<", $theme_filename or die "Cannot read $theme_filename - $!" 1 0 1
36  
37 1 ▶ while( <$themefh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $themefh)) 75 1 76
38 75 ▶ m/^\s*#/ and next; # skip comments
Branch: 1 branch
BranchTrueFalseTotal
/^\s*#/u and next 5 70 75
39 70 ▶ m/^\s*$/ and next; # skip blanks
Branch: 1 branch
BranchTrueFalseTotal
/^\s*$/u and next 11 59 70
40  
41 59 ▶ m/^(\S*)=(.*)$/ and $theme_vars{$1} = $2, next;
Branch: 1 branch
BranchTrueFalseTotal
/^(\S*)=(.*)$/u and $theme_vars{$1} = $2, next 59 0 59
42 0 print STDERR "Unrecognised theme line: $_";
43 }
44 }
45  
46 sub get_theme_var
47 0 ▶{
Subroutine get_theme_var: not called CC=2 SCAR=17.9
Pod undocumented
48 0 my $class = shift;
49 0 my ( $varname ) = @_;
50 0 ▶ return $theme_vars{$varname} if exists $theme_vars{$varname};
Branch: 1 branch
BranchTrueFalseTotal
if exists $theme_vars{$varname} 0 0 0
51 0 print STDERR "No such theme variable $varname\n";
52 0 return undef;
53 }
54  
55 sub translate_theme_colour
56 0 ▶{
Subroutine translate_theme_colour: not called CC=3 SCAR=24.8
Pod undocumented
57 0 my $class = shift;
58 0 my ( $colourname ) = @_;
59  
60 0 ▶ return $colourname if $colourname =~ m/^#/; # Literal #rrggbb
Branch: 1 branch
BranchTrueFalseTotal
if $colourname =~ /^#/u 0 0 0
61 0 ▶ return $theme_vars{$colourname} if exists $theme_vars{$colourname}; # hope
Branch: 1 branch
BranchTrueFalseTotal
if exists $theme_vars{$colourname} 0 0 0
62 0 print STDERR "No such theme colour $colourname\n";
63 0 return undef;
64 }
65  
66 sub get_theme_colour
67 0 ▶{
Subroutine get_theme_colour: not called CC=2 SCAR=17.9
Pod undocumented
68 0 my $class = shift;
69 0 my ( $varname ) = @_;
70 0 ▶ return $theme_vars{$varname} if exists $theme_vars{$varname};
Branch: 1 branch
BranchTrueFalseTotal
if exists $theme_vars{$varname} 0 0 0
71 0 print STDERR "No such theme variable $varname for a colour\n";
72 0 return undef;
73 }
74  
75 1 my %theme_pens;
76  
77 sub get_theme_pen
78 0 ▶{
Subroutine get_theme_pen: not called CC=2 SCAR=17.9
Pod undocumented
79 0 my $class = shift;
80 0 my ( $varname ) = @_;
81 0 ▶ return $theme_pens{$varname} ||= Tickit::Pen->new( fg => $class->get_theme_colour( $varname ) );
Condition0%0/3
$theme_pens{$varname} ||= "Tickit::Pen"->new("fg", $class->get_theme_colour($varname))
l!l&&r!l&&!r
000
MC/DC0%0/2
$theme_pens{$varname} ||= "Tickit::Pen"->new("fg", $class->get_theme_colour($varname))
$theme_pens{$varname} "Tickit::Pen"->new("fg", $class->get_theme_colour($varname))
Truth table0%0/3
A ||= B
A= $theme_pens{$varname}B= "Tickit::Pen"->new("fg", $class->get_theme_colour($varname))
ABresult
1X1
011
000
82 }
83  
84 =head1 AUTHOR
85  
86 Paul Evans <leonerd@leonerd.org.uk>
87  
88 =cut
89  
90 1 0x55AA;
« Term/Widget/Scroller.pm ↑ Summary Term/Tab.pm »