blib/lib/Term/Fabulous/Static.pm

filter: Statementstmt 88.2% 15 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.3% 21 / 23 CC 1 SCAR 0.5
CC
1
Cov
88%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Term/Fabulous/Role/SearchContainer.pm ↑ Summary blib/lib/Term/Fabulous/Text/Markup.pm »
1 package Term::Fabulous::Static;
2  
3 2 ▶use v5.32;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 our $VERSION = '0.05';
9  
10 2 ▶use Object::Pad 0.825;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶use Clay::UI;
Subroutine BEGIN: called CC=1 SCAR=2.6
13 use Term::Fabulous::Render;
14 use Term::Fabulous::Render::Target::Grid;
15  
16 class Term::Fabulous::Static
17 :isa(Clay::UI)
18 :does(Term::Fabulous::Render)
19 :strict(params)
20 {
21 use Encode qw(encode);
22 use Scalar::Util qw(openhandle);
23  
24 use constant DEFAULT_MAX_HEIGHT => 4096;
25  
26 field $trim_trailing_whitespace :param :reader = 1;
27 field $cell_target :reader = Term::Fabulous::Render::Target::Grid->new;
28  
29 # Clay::UI needs a height, and content is expected to end far before it.
30 sub BUILDARGS ( $class, %params ) {
31 die "Term::Fabulous::Static: measure_text cannot be replaced; text is always measured in terminal columns" if exists $params{measure_text};
32 $params{height} //= DEFAULT_MAX_HEIGHT;
33 return %params;
34 }
35  
36 sub _checked_options ( $method, $options, @known ) {
37 my %is_known = map { $_ => 1 } @known;
38 my @unknown = sort grep { !$is_known{$_} } keys %$options;
39 die "Term::Fabulous::Static: $method does not accept " . join( ', ', @unknown ) . " (known options: " . join( ', ', @known ) . ")" if @unknown;
40 return;
41 }
42  
43 method pointer_state () {
44 return undef;
45 }
46  
47 # The lines are printed into whatever the terminal shows; the theme's
48 # background token paints nothing here (Term::Fabulous::Render).
49 method screen_background () {
50 return undef;
51 }
52  
53 method cell ( $x, $y ) {
54 return $cell_target->cell( $x, $y );
55 }
56  
57 method render_lines (%options) {
58 _checked_options( render_lines => \%options, 'colors' );
59 my %format = ( columns => $self->width, colors => $options{colors} // 1, trim_trailing_whitespace => $trim_trailing_whitespace );
60 $self->draw;
61 return map { $cell_target->row_text( $_, %format ) } 0 .. $cell_target->grid_height - 1;
62 }
63  
64 method render_string (%options) {
65 _checked_options( render_string => \%options, 'colors' );
66 return join '', map { "$_\n" } $self->render_lines(%options);
67 }
68  
69 method print (%options) {
70 _checked_options( print => \%options, qw(fh colors) );
71 my $fh = $options{fh} // \*STDOUT;
72 die "Term::Fabulous::Static: fh must be an open file handle" unless openhandle($fh);
73 my $colors = $options{colors} // ( -t $fh ? 1 : 0 ); ## no critic (InputOutput::ProhibitInteractiveTest) $fh is any handle, not STDIN
74 print {$fh} encode( 'UTF-8', $self->render_string( colors => $colors ) );
75 return;
76 }
77 }
78  
79 1;
80  
81 __END__
« blib/lib/Term/Fabulous/Role/SearchContainer.pm ↑ Summary blib/lib/Term/Fabulous/Text/Markup.pm »