lib/TUI/Drivers/HardwareInfo/Termbox.pm

filter: Statementstmt 34.5% 210 / 608 Branchbran 6.4% 19 / 294 Conditioncond 10.8% 19 / 176 MC/DCmcdc 0.0% 0 / 107 Subroutinesub 62.6% 47 / 75 Podpod 0.0% 0 / 27 totaltotal 22.9% 295 / 1287 CC 207 SCAR 50.6
CC
207
Cov
23%
__ANON__
650.0
setScreenMode
462.0
getColorCount
420.0
CRAP 157.5
« lib/TUI/Help/HelpViewer.pm ↑ Summary lib/TUI/StdDlg/SortedListBox.pm »
1 package TUI::Drivers::HardwareInfo::Termbox;
2 # ABSTRACT: Termbox driver for TUI::Drivers::HardwareInfo
3
4 # -------------------------------------------------------------------------
5 # Boilerplate
6 # -------------------------------------------------------------------------
7
8 141 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 141 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 141 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11
12 141 our $VERSION = '2.000003';
13 141 $VERSION =~ tr/_//d;
14 141 our $AUTHORITY = 'cpan:BRICKPOOL';
15
16 # -------------------------------------------------------------------------
17 # Import modules
18 # -------------------------------------------------------------------------
19
20 141 ▶use constant PERL_ONLY => $^O eq 'MSWin32'
Subroutine BEGIN: called CC=6 SCAR=25.4
21 || exists $ENV{PERL_ONLY} && $ENV{PERL_ONLY}
22 || exists $ENV{ESCDELAY} && $ENV{ESCDELAY}
23 0 ▶ || !eval { require Termbox; Termbox->VERSION( 2 ); 1 };
Condition33%5/15
$^O eq 'MSWin32' || exists $ENV{'PERL_ONLY'} && $ENV{'PERL_ONLY'} || exists $ENV{'ESCDELAY'} && $ENV{'ESCDELAY'} || !eval { do { require Termbox; 'Termbox'->VERSION(2); 1 } }
l!l&&r!l&&!r
01410
$^O eq "MSWin32" or exists $ENV{"PERL_ONLY"} and $ENV{"PERL_ONLY"} or exists $ENV{"ESCDELAY"} and $ENV{"ESCDELAY"}
l!l&&r!l&&!r
00141
$^O eq "MSWin32" or exists $ENV{"PERL_ONLY"} and $ENV{"PERL_ONLY"}
l!l&&r!l&&!r
00141
exists $ENV{"PERL_ONLY"} and $ENV{"PERL_ONLY"}
!ll&&!rl&&r
14100
exists $ENV{"ESCDELAY"} and $ENV{"ESCDELAY"}
!ll&&!rl&&r
14100
MC/DC0%0/6
$^O eq 'MSWin32' || exists $ENV{'PERL_ONLY'} && $ENV{'PERL_ONLY'} || exists $ENV{'ESCDELAY'} && $ENV{'ESCDELAY'} || !eval { do { require Termbox; 'Termbox'->VERSION(2); 1 } }
$^O eq "MSWin32" exists $ENV{"PERL_ONLY"} $ENV{"PERL_ONLY"} exists $ENV{"ESCDELAY"} $ENV{"ESCDELAY"} !eval { do { require Termbox; 'Termbox'->VERSION(2); 1 } }
Truth table8%1/12
A or B and C or D and E || not(F)
A= $^O eq "MSWin32"B= exists $ENV{"PERL_ONLY"}C= $ENV{"PERL_ONLY"}D= exists $ENV{"ESCDELAY"}E= $ENV{"ESCDELAY"}F= !eval { do { require Termbox; 'Termbox'->VERSION(2); 1 } }
ABCDEFresult
1XXXXX1
011XXX1
00X11X1
01011X1
00X0X11
00X1011
0100X11
0101011
00X0X00
00X1000
0100X00
0101000
24
25 141 ▶use PerlX::Assert::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 141 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 141 ▶use Errno qw( EINTR );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 141 ▶use List::Util qw( min max );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 141 ▶use Scalar::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
30 blessed
31 looks_like_number
32 readonly
33 141 );
34 141 ▶use if PERL_ONLY, 'Termbox::PP';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 141 ▶use Termbox qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
36 141 ▶use Time::HiRes qw( time );
Subroutine BEGIN: called CC=1 SCAR=0.0
37 141 ▶use TUI::toolkit::boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
38
39 141 ▶use TUI::Drivers::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
40 evCommand
41 evKeyDown
42 :smXXXX
43 :kbXXXX
44 :meXXXX
45 :mbXXXX
46 141 );
47 141 ▶use TUI::Drivers::ScreenCharacter;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 141 ▶use TUI::Drivers::ColorAttr;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 141 ▶use TUI::Drivers::Colors qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
50 BIOStoXTerm16
51 RGBtoXTerm16
52 RGBtoXTerm256
53 XTerm256toXTerm16
54 141 );
55 141 ▶use TUI::Drivers::ScreenCell;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 141 ▶use TUI::Memory qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
57 disposeCache
58 newCache
59 141 );
60 141 ▶use TUI::Views::Const qw( cmScreenChanged );
Subroutine BEGIN: called CC=1 SCAR=0.0
61
62 # -------------------------------------------------------------------------
63 # Define constants
64 # -------------------------------------------------------------------------
65
66 141 ▶use constant TB_NONE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
67
68 # Do not delay too much on ESC key presses, as the Alt modifier works well
69 # in most modern terminals. Still, this delay helps Termbox::PP distinguish
70 # special key sequences.
71 141 ▶use constant ESCDELAY => exists $ENV{ESCDELAY} && $ENV{ESCDELAY} > 0
Subroutine BEGIN: called CC=3 SCAR=12.5
72 ? $ENV{ESCDELAY}
73 141 ▶ : 100;
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{'ESCDELAY'} && $ENV{'ESCDELAY'} > 0 ? : 0 141 141
Condition33%1/3
exists $ENV{"ESCDELAY"} and $ENV{"ESCDELAY"} > 0
!ll&&!rl&&r
14100
MC/DC0%0/2
exists $ENV{"ESCDELAY"} and $ENV{"ESCDELAY"} > 0
exists $ENV{"ESCDELAY"} $ENV{"ESCDELAY"} > 0
Truth table33%1/3
A and B
A= exists $ENV{"ESCDELAY"}B= $ENV{"ESCDELAY"} > 0
ABresult
0X0
100
111
74
75 # Provide missing key constants and compatibility aliases when they are not
76 # supplied by the selected Termbox implementation.
77 141 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=15.4
78 141 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
79 141 my %compat = (
80 TB_KEY_CTRL_A => 0x01,
81 TB_KEY_CTRL_B => 0x02,
82 TB_KEY_CTRL_C => 0x03,
83 TB_KEY_CTRL_D => 0x04,
84 TB_KEY_CTRL_E => 0x05,
85 TB_KEY_CTRL_F => 0x06,
86 TB_KEY_CTRL_G => 0x07,
87 TB_KEY_BACKSPACE => 0x08,
88 TB_KEY_CTRL_H => 0x08,
89 TB_KEY_TAB => 0x09,
90 TB_KEY_CTRL_I => 0x09,
91 TB_KEY_CTRL_J => 0x0a,
92 TB_KEY_CTRL_K => 0x0b,
93 TB_KEY_CTRL_L => 0x0c,
94 TB_KEY_ENTER => 0x0d,
95 TB_KEY_CTRL_M => 0x0d,
96 TB_KEY_CTRL_N => 0x0e,
97 TB_KEY_CTRL_O => 0x0f,
98 TB_KEY_CTRL_P => 0x10,
99 TB_KEY_CTRL_Q => 0x11,
100 TB_KEY_CTRL_R => 0x12,
101 TB_KEY_CTRL_S => 0x13,
102 TB_KEY_CTRL_T => 0x14,
103 TB_KEY_CTRL_U => 0x15,
104 TB_KEY_CTRL_V => 0x16,
105 TB_KEY_CTRL_W => 0x17,
106 TB_KEY_CTRL_X => 0x18,
107 TB_KEY_CTRL_Y => 0x19,
108 TB_KEY_CTRL_Z => 0x1a,
109 TB_KEY_ESC => 0x1b,
110 TB_KEY_SPACE => 0x20,
111 TB_KEY_BACKSPACE2 => 0x7f,
112 );
113 141 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
114 141 ▶ while ( my ( $name, $value ) = each %compat ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %compat) 4512 141 4653
115 4512 ▶ next if defined &{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$name;} 4512 0 4512
116 # The constant could be called even if it is not yet visible as a symbol
117 0 ▶ next if __PACKAGE__->can( $name );
Branch: 1 branch
BranchTrueFalseTotal
if __PACKAGE__->can($name) 0 0 0
118 0 ▶ *{$name} = sub () { $value };
Subroutine __ANON__: not called CC=1 SCAR=6.9
119 }
120 }
121
122 # Provide missing high-intensity black constant when they are not supplied by
123 # the selected Termbox implementation.
124 141 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.9
125 141 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
126 141 ▶ if ( !defined &TB_HI_BLACK ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined &TUI::Drivers::HardwareInfo::Termbox::TB_HI_BLACK) 0 141 141
127 0 ▶ *TB_HI_BLACK = sub () { TB_256_BLACK };
Subroutine __ANON__: not called CC=1 SCAR=6.9
128 }
129 }
130
131 # Provide missing TrueColor-related API constants when they are not supplied by
132 # the selected Termbox implementation.
133 141 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=14.0
134 141 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
135 141 my %compat = (
136 TB_OUTPUT_TRUECOLOR => 5,
137 TB_TRUECOLOR_BOLD => 0x01000000,
138 TB_TRUECOLOR_UNDERLINE => 0x02000000,
139 TB_TRUECOLOR_REVERSE => 0x04000000,
140 TB_TRUECOLOR_BLINK => 0x10000000,
141 TB_TRUECOLOR_BLACK => 0x20000000,
142 );
143 141 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
144 141 ▶ while ( my ( $name, $value ) = each %compat ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %compat) 846 141 987
145 846 ▶ next if defined &{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$name;} 0 846 846
146 846 ▶ next if __PACKAGE__->can( $name );
Branch: 1 branch
BranchTrueFalseTotal
if __PACKAGE__->can($name) 0 846 846
147 0 ▶ *{$name} = sub () { $value };
Subroutine __ANON__: not called CC=1 SCAR=0.4
148 }
149 }
150
151 # -------------------------------------------------------------------------
152 # Declare global variables
153 # -------------------------------------------------------------------------
154
155 141 our $insertState = true;
156 141 our $platform = '';
157 141 our $pendingEvent = 0;
158
159 # Track mouse button state.
160 141 our $lastButtons = 0;
161
162 # -------------------------------------------------------------------------
163 # Import global variables
164 # -------------------------------------------------------------------------
165
166 141 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
167 $ctrlBreakHit
168 141 );
169 {
170 141 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
171 141 *ctrlBreakHit = \$TUI::Drivers::SystemError::ctrlBreakHit;
172 }
173
174 # -------------------------------------------------------------------------
175 # Local variables
176 # -------------------------------------------------------------------------
177
178 141 my $screenMode = 0;
179 141 my $outputMode = 0;
180 141 my $initialized = false;
181 141 my $cursorSize = 15;
182 141 my @lastSize = ( 0, 0 );
183 141 my $tb_event = Termbox::Event->new();
184
185 # Codepage 437 to Unicode translation map.
186 141 my @CP437_TO_UTF8 = (
187 ord "\x{2007}", ord "\x{263a}", ord "\x{263b}", ord "\x{2665}",
188 ord "\x{2666}", ord "\x{2663}", ord "\x{2660}", ord "\x{2022}",
189 ord "\x{25d8}", ord "\x{25cb}", ord "\x{25d9}", ord "\x{2642}",
190 ord "\x{2640}", ord "\x{266a}", ord "\x{266b}", ord "\x{263c}",
191 # Termius has 25b6 and 25c0 here, which are better unicode equivalents.
192 # ord "\x{25ba}", ord "\x{25c4}", ord "\x{2195}", ord "\x{203c}",
193 ord "\x{25b6}", ord "\x{25c0}", ord "\x{2195}", ord "\x{203c}",
194 ord "\x{00b6}", ord "\x{00a7}", ord "\x{25ac}", ord "\x{21a8}",
195 ord "\x{2191}", ord "\x{2193}", ord "\x{2192}", ord "\x{2190}",
196 ord "\x{221f}", ord "\x{2194}", ord "\x{25b2}", ord "\x{25bc}",
197 ord "\x{0020}", ord "\x{0021}", ord "\x{0022}", ord "\x{0023}",
198 ord "\x{0024}", ord "\x{0025}", ord "\x{0026}", ord "\x{0027}",
199 ord "\x{0028}", ord "\x{0029}", ord "\x{002a}", ord "\x{002b}",
200 ord "\x{002c}", ord "\x{002d}", ord "\x{002e}", ord "\x{002f}",
201 ord "\x{0030}", ord "\x{0031}", ord "\x{0032}", ord "\x{0033}",
202 ord "\x{0034}", ord "\x{0035}", ord "\x{0036}", ord "\x{0037}",
203 ord "\x{0038}", ord "\x{0039}", ord "\x{003a}", ord "\x{003b}",
204 ord "\x{003c}", ord "\x{003d}", ord "\x{003e}", ord "\x{003f}",
205 ord "\x{0040}", ord "\x{0041}", ord "\x{0042}", ord "\x{0043}",
206 ord "\x{0044}", ord "\x{0045}", ord "\x{0046}", ord "\x{0047}",
207 ord "\x{0048}", ord "\x{0049}", ord "\x{004a}", ord "\x{004b}",
208 ord "\x{004c}", ord "\x{004d}", ord "\x{004e}", ord "\x{004f}",
209 ord "\x{0050}", ord "\x{0051}", ord "\x{0052}", ord "\x{0053}",
210 ord "\x{0054}", ord "\x{0055}", ord "\x{0056}", ord "\x{0057}",
211 ord "\x{0058}", ord "\x{0059}", ord "\x{005a}", ord "\x{005b}",
212 ord "\x{005c}", ord "\x{005d}", ord "\x{005e}", ord "\x{005f}",
213 ord "\x{0060}", ord "\x{0061}", ord "\x{0062}", ord "\x{0063}",
214 ord "\x{0064}", ord "\x{0065}", ord "\x{0066}", ord "\x{0067}",
215 ord "\x{0068}", ord "\x{0069}", ord "\x{006a}", ord "\x{006b}",
216 ord "\x{006c}", ord "\x{006d}", ord "\x{006e}", ord "\x{006f}",
217 ord "\x{0070}", ord "\x{0071}", ord "\x{0072}", ord "\x{0073}",
218 ord "\x{0074}", ord "\x{0075}", ord "\x{0076}", ord "\x{0077}",
219 ord "\x{0078}", ord "\x{0079}", ord "\x{007a}", ord "\x{007b}",
220 ord "\x{007c}", ord "\x{007d}", ord "\x{007e}", ord "\x{2302}",
221 ord "\x{00c7}", ord "\x{00fc}", ord "\x{00e9}", ord "\x{00e2}",
222 ord "\x{00e4}", ord "\x{00e0}", ord "\x{00e5}", ord "\x{00e7}",
223 ord "\x{00ea}", ord "\x{00eb}", ord "\x{00e8}", ord "\x{00ef}",
224 ord "\x{00ee}", ord "\x{00ec}", ord "\x{00c4}", ord "\x{00c5}",
225 ord "\x{00c9}", ord "\x{00e6}", ord "\x{00c6}", ord "\x{00f4}",
226 ord "\x{00f6}", ord "\x{00f2}", ord "\x{00fb}", ord "\x{00f9}",
227 ord "\x{00ff}", ord "\x{00d6}", ord "\x{00dc}", ord "\x{00a2}",
228 ord "\x{00a3}", ord "\x{00a5}", ord "\x{20a7}", ord "\x{0192}",
229 ord "\x{00e1}", ord "\x{00ed}", ord "\x{00f3}", ord "\x{00fa}",
230 ord "\x{00f1}", ord "\x{00d1}", ord "\x{00aa}", ord "\x{00ba}",
231 ord "\x{00bf}", ord "\x{2310}", ord "\x{00ac}", ord "\x{00bd}",
232 ord "\x{00bc}", ord "\x{00a1}", ord "\x{00ab}", ord "\x{00bb}",
233 ord "\x{2591}", ord "\x{2592}", ord "\x{2593}", ord "\x{2502}",
234 ord "\x{2524}", ord "\x{2561}", ord "\x{2562}", ord "\x{2556}",
235 ord "\x{2555}", ord "\x{2563}", ord "\x{2551}", ord "\x{2557}",
236 ord "\x{255d}", ord "\x{255c}", ord "\x{255b}", ord "\x{2510}",
237 ord "\x{2514}", ord "\x{2534}", ord "\x{252c}", ord "\x{251c}",
238 ord "\x{2500}", ord "\x{253c}", ord "\x{255e}", ord "\x{255f}",
239 ord "\x{255a}", ord "\x{2554}", ord "\x{2569}", ord "\x{2566}",
240 ord "\x{2560}", ord "\x{2550}", ord "\x{256c}", ord "\x{2567}",
241 ord "\x{2568}", ord "\x{2564}", ord "\x{2565}", ord "\x{2559}",
242 ord "\x{2558}", ord "\x{2552}", ord "\x{2553}", ord "\x{256b}",
243 ord "\x{256a}", ord "\x{2518}", ord "\x{250c}", ord "\x{2588}",
244 ord "\x{2584}", ord "\x{258c}", ord "\x{2590}", ord "\x{2580}",
245 ord "\x{03b1}", ord "\x{00df}", ord "\x{0393}", ord "\x{03c0}",
246 ord "\x{03a3}", ord "\x{03c3}", ord "\x{00b5}", ord "\x{03c4}",
247 ord "\x{03a6}", ord "\x{0398}", ord "\x{03a9}", ord "\x{03b4}",
248 ord "\x{221e}", ord "\x{03c6}", ord "\x{03b5}", ord "\x{2229}",
249 ord "\x{2261}", ord "\x{00b1}", ord "\x{2265}", ord "\x{2264}",
250 ord "\x{2320}", ord "\x{2321}", ord "\x{00f7}", ord "\x{2248}",
251 ord "\x{00b0}", ord "\x{2219}", ord "\x{00b7}", ord "\x{221a}",
252 ord "\x{207f}", ord "\x{00b2}", ord "\x{25a0}", ord "\x{00a0}",
253 );
254 141 my @UTF8_TO_CP437 = map { chr } @CP437_TO_UTF8;
255
256 # Key Event conversion
257 my (
258 141 $convertCharCode,
259 $convertKeyCode,
260 );
261
262 # Attribute conversion
263 141 my $TB_ATTR;
264 141 my $attrBold = TB_BOLD;
265 141 my $attrUnderline = TB_UNDERLINE;
266 141 my $attrReverse = TB_REVERSE;
267 141 my $attrBlink = TB_BLINK;
268 141 my $attrBlack = TB_HI_BLACK;
269 my (
270 141 $convertColor,
271 $convertNoColor,
272 $convertIndexed8,
273 $convertIndexed16,
274 $convertIndexed256,
275 $convertDirect,
276 );
277
278 # -------------------------------------------------------------------------
279 # Initialization and cleanup
280 # -------------------------------------------------------------------------
281
282 141 ▶INIT {
Subroutine INIT: called CC=4 SCAR=15.9
283 141 ▶ if ( eval { require Perl::OSType; 1 } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { require Perl::OSType; 1 } }) { } 141 0 141
elsif ($TUI::Drivers::HardwareInfo::Termbox::OSNAME eq 'MSWin32') { } 0 0 0
284 141 $platform = Perl::OSType::os_type( $OSNAME );
285 } elsif ( $OSNAME eq 'MSWin32' ) {
286 0 $platform = 'Windows';
287 }
288 141 ▶ $platform ||= 'Unix';
Condition50%1/2
$TUI::Drivers::HardwareInfo::Termbox::platform ||= "Unix"
l!l
1410
MC/DC0%0/1
$TUI::Drivers::HardwareInfo::Termbox::platform ||= "Unix"
$TUI::Drivers::HardwareInfo::Termbox::platform
Truth table50%1/2
A
A= $TUI::Drivers::HardwareInfo::Termbox::platform
Aresult
11
00
289 141 __PACKAGE__->resume();
290 }
291
292 141 ▶sub resume { # void ($class)
Subroutine resume: called CC=12 SCAR=44.2
Pod undocumented
293 141 my ( $class ) = @_;
294 141 assert ( @_ == 1 );
295 141 ▶ assert ( $class and !ref $class );
Condition33%1/3
$class && !ref($class)
!ll&&!rl&&r
00141
MC/DC0%0/2
$class && !ref($class)
$class !ref($class)
Truth table33%1/3
A && not(B)
A= $classB= !ref($class)
ABresult
0X0
100
111
296
297 141 ▶ return if $initialized;
Branch: 1 branch
BranchTrueFalseTotal
if $initialized 0 141 141
298 141 newCache( $TB_ATTR, 256 );
299
300 # https://github.com/neovim/neovim/issues/36635
301 141 ▶ $ENV{TERM} //= 'xterm-256color' if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 141 141
Condition0%0/2
$ENV{"TERM"} //= "xterm-256color"
l!l
00
MC/DC0%0/1
$ENV{"TERM"} //= "xterm-256color"
$ENV{"TERM"}
Truth table0%0/2
A
A= $ENV{"TERM"}
Aresult
11
00
302
303 # Initialize Termbox and set the input/output modes.
304 141 my $err = tb_init();
305 141 ▶ return if $err != TB_OK;
Branch: 1 branch
BranchTrueFalseTotal
if $err != 0 141 0 141
306 0 $err = tb_set_input_mode( TB_INPUT_ALT | TB_INPUT_MOUSE );
307 0 ▶ return if $err != TB_OK;
Branch: 1 branch
BranchTrueFalseTotal
if $err != 0 0 0 0
308 0 ▶ $outputMode = $class->getColorCount() >= 16
Branch: 1 branch
BranchTrueFalseTotal
$class->getColorCount >= 16 ? : 0 0 0
309 ? TB_OUTPUT_256
310 : TB_OUTPUT_NORMAL;
311 0 $err = tb_set_output_mode( $outputMode );
312 0 ▶ return if $err != TB_OK;
Branch: 1 branch
BranchTrueFalseTotal
if $err != 0 0 0 0
313 0 my $cols = tb_width();
314 0 ▶ return if $cols <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $cols <= 0 0 0 0
315 0 my $rows = tb_height();
316 0 ▶ return if $rows <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rows <= 0 0 0 0
317
318 0 @lastSize = ( $cols, $rows );
319
320 # NOTE: The following workaround for detecting a single TB_KEY_ESC relies
321 # on deprecated function tb_set_func() and Termbox::PP internals.
322 # The tb_set_func() API itself is backend-independent, but the access to
323 # raw input buffer is currently only available in the PP backend.
324 0 if ( PERL_ONLY ) {
325 141 ▶ no warnings 'deprecated';
Subroutine BEGIN: called CC=1 SCAR=0.0
326 0 ▶ $err = tb_set_func( TB_FUNC_EXTRACT_PRE, sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
327 0 my ( $event, $consumed_ref ) = @_;
328
329 0 state $esc_seen_at;
330 0 ▶ if ( $Termbox::global->{inbuf} eq "\e" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Termbox::global->{"inbuf"} eq "\e") 0 0 0
331 0 my $now = int(( time() - $BASETIME ) * 1000);
332 0 ▶ $esc_seen_at //= $now;
Condition0%0/3
$esc_seen_at //= $now
l!l&&r!l&&!r
000
MC/DC0%0/2
$esc_seen_at //= $now
$esc_seen_at $now
Truth table0%0/3
A //= B
A= $esc_seen_atB= $now
ABresult
1X1
011
000
333 0 my $elapsed = $now - $esc_seen_at;
334
335 0 ▶ return TB_ERR_NEED_MORE
Branch: 1 branch
BranchTrueFalseTotal
if $elapsed < 100 0 0 0
336 if $elapsed < ESCDELAY;
337
338 0 $$consumed_ref = 1;
339
340 0 $event->{type} = TB_EVENT_KEY;
341 0 $event->{mod} = TB_NONE;
342 0 $event->{key} = TB_KEY_ESC;
343 0 $event->{ch} = 0;
344
345 0 $esc_seen_at = undef;
346 0 return TB_OK;
347 }
348 0 $esc_seen_at = undef;
349 0 return TB_ERR;
350 0 });
351 0 ▶ return tb_strerror( $err ) if $err != TB_OK;
Branch: 1 branch
BranchTrueFalseTotal
if $err != 0 0 0 0
352 }
353
354 0 $initialized = true;
355 0 return;
356 }
357
358 141 ▶END {
Subroutine END: called CC=1 SCAR=0.0
359 141 __PACKAGE__->suspend();
360 }
361
362 141 ▶sub suspend { # void ($class)
Subroutine suspend: called CC=6 SCAR=31.7
Pod undocumented
363 141 assert ( @_ == 1 );
364 141 ▶ assert ( $_[0] and !ref $_[0] );
Condition33%1/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
00141
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table33%1/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
365
366 141 ▶ return unless $initialized;
Branch: 1 branch
BranchTrueFalseTotal
unless $initialized 141 0 141
367
368 # Restore the cursor style on exit
369 # https://unix.stackexchange.com/q/697650
370 {
371 0 ▶ my $term = $ENV{TERM} // '';
Condition0%0/2
$ENV{"TERM"} // ""
l!l
00
MC/DC0%0/1
$ENV{"TERM"} // ""
$ENV{"TERM"}
Truth table0%0/2
A
A= $ENV{"TERM"}
Aresult
11
00
372 0 ▶ if ( $term eq 'linux' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($term eq 'linux') { } 0 0 0
elsif ($term) { } 0 0 0
373 0 tb_send( $_ = "\x1B[?0c", bytes::length( $_ ) );
374 } elsif ( $term ) {
375 0 tb_send( $_ = "\x1B[0 q", bytes::length( $_ ) );
376 }
377 }
378 0 tb_set_func( TB_FUNC_EXTRACT_PRE, undef ) if PERL_ONLY;
379 0 tb_shutdown();
380
381 0 disposeCache( $TB_ATTR );
382 0 $initialized = false;
383 0 return;
384 }
385
386 # -------------------------------------------------------------------------
387 # General system functions
388 # -------------------------------------------------------------------------
389
390 1 ▶sub getTickCount { # $ticks ($class)
Subroutine getTickCount: called CC=2 SCAR=7.6
Pod undocumented
391 1 assert ( @_ == 1 );
392 1 ▶ assert ( $_[0] and !ref $_[0] );
Condition33%1/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
001
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table33%1/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
393 # Return Turbo Vision compatible clock ticks (~18.2 Hz).
394 1 return int( ( time() - $BASETIME ) * 1000 / 55 );
395 }
396
397 1 ▶sub getPlatform { # $osname ($class)
Subroutine getPlatform: called CC=2 SCAR=7.6
Pod undocumented
398 1 assert ( @_ == 1 );
399 1 ▶ assert ( $_[0] and !ref $_[0] );
Condition33%1/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
001
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table33%1/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
400 1 return $platform;
401 }
402
403 # -------------------------------------------------------------------------
404 # Caret functions
405 # -------------------------------------------------------------------------
406
407 2 ▶sub setCaretSize { # void ($class, $size)
Subroutine setCaretSize: called CC=9 SCAR=40.6
Pod undocumented
408 2 my ( $class, $size ) = @_;
409 2 assert ( @_ == 2 );
410 2 ▶ assert ( $class and !ref $class );
Condition33%1/3
$class && !ref($class)
!ll&&!rl&&r
002
MC/DC0%0/2
$class && !ref($class)
$class !ref($class)
Truth table33%1/3
A && not(B)
A= $classB= !ref($class)
ABresult
0X0
100
111
411 2 assert ( looks_like_number $size );
412 2 assert ( $initialized );
413 0 ▶ if ( $size <= 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($size <= 0) { } 0 0 0
elsif ($size != $cursorSize) { } 0 0 0
414 0 $cursorSize = 0; # hidden
415 0 tb_hide_cursor();
416 }
417 elsif ( $size != $cursorSize ) {
418 0 $cursorSize = max( 0, min( $size, 100 ) );
419
420 0 ▶ my $term = $ENV{TERM} // '';
Condition0%0/2
$ENV{"TERM"} // ""
l!l
00
MC/DC0%0/1
$ENV{"TERM"} // ""
$ENV{"TERM"}
Truth table0%0/2
A
A= $ENV{"TERM"}
Aresult
11
00
421 0 ▶ if ( $term eq 'linux' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($term eq 'linux') { } 0 0 0
elsif ($term) { } 0 0 0
422 # Linux VGA console cursor style
423 # https://unix.stackexchange.com/a/92743
424 0 my $raw = sprintf(
425 "\x1B[?%dc",
426 2 + int( ( $cursorSize - 1 ) * 4 / 99 + 0.5 )
427 );
428 0 tb_send( $raw, bytes::length( $raw ) );
429 }
430 elsif ( $term ) {
431 # DECSCUSR (DEC Set Cursor Style)
432 # https://unix.stackexchange.com/a/597558
433 0 my $raw;
434 0 ▶ if ( $cursorSize < 50 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cursorSize < 50) { } 0 0 0
elsif ($cursorSize < 100) { } 0 0 0
435 0 $raw = "\x1B[3 q"; # blinking underline
436 }
437 elsif ( $cursorSize < 100 ) {
438 0 $raw = "\x1B[5 q"; # blinking bar
439 }
440 else {
441 0 $raw = "\x1B[1 q"; # blinking block
442 }
443 0 $raw .= "\x1B[?25h";
444 0 tb_send( $raw, bytes::length( $raw ) );
445 }
446 else {
447 # Show cursor; (-1,-1) is clamped to (0,0).
448 0 tb_set_cursor( -1, -1 );
449 }
450 }
451 0 return;
452 }
453
454 2 ▶sub getCaretSize { # $size ($class)
Subroutine getCaretSize: called CC=2 SCAR=7.6
Pod undocumented
455 2 assert ( @_ == 1 );
456 2 ▶ assert ( $_[0] and !ref $_[0] );
Condition33%1/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
002
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table33%1/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
457 2 return min( max( $cursorSize, 0 ), 100 );
458 }
459
460 0 ▶sub setCaretPosition { # void ($class, $x, $y)
Subroutine setCaretPosition: not called CC=2 SCAR=17.9
Pod undocumented
461 0 my ( $class, $x, $y ) = @_;
462 0 assert ( @_ == 3 );
463 0 ▶ assert ( $class and !ref $class );
Condition0%0/3
$class && !ref($class)
!ll&&!rl&&r
000
MC/DC0%0/2
$class && !ref($class)
$class !ref($class)
Truth table0%0/3
A && not(B)
A= $classB= !ref($class)
ABresult
0X0
100
111
464 0 assert ( looks_like_number $x );
465 0 assert ( looks_like_number $y );
466 0 assert ( $initialized );
467 0 tb_set_cursor( $x, $y );
468 0 return;
469 }
470
471 1 ▶sub isCaretVisible { # $visible ($class)
Subroutine isCaretVisible: called CC=2 SCAR=7.6
Pod undocumented
472 1 assert ( @_ == 1 );
473 1 ▶ assert ( $_[0] and !ref $_[0] );
Condition33%1/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
001
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table33%1/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
474 1 return $cursorSize > 0;
475 }
476
477 # -------------------------------------------------------------------------
478 # Screen functions
479 # -------------------------------------------------------------------------
480
481 1 ▶sub getScreenRows { # $rows ($class)
Subroutine getScreenRows: called CC=4 SCAR=22.3
Pod undocumented
482 1 assert ( @_ == 1 );
483 1 ▶ assert ( $_[0] and !ref $_[0] );
Condition33%1/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
001
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table33%1/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
484 1 assert ( $initialized );
485 0 my $rows = tb_height();
486 0 ▶ return 25
Branch: 1 branch
BranchTrueFalseTotal
if $rows == 0 0 0 0
487 if $rows == 0; # Borland's compatibility DOS default (only for rows)
488 0 ▶ return $rows > 0 ? $rows : 0;
Branch: 1 branch
BranchTrueFalseTotal
$rows > 0 ? : 0 0 0
489 }
490
491 0 ▶sub getScreenCols { # $cols ($class)
Subroutine getScreenCols: not called CC=3 SCAR=24.8
Pod undocumented
492 0 assert ( @_ == 1 );
493 0 ▶ assert ( $_[0] and !ref $_[0] );
Condition0%0/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table0%0/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
494 0 assert ( $initialized );
495 0 my $cols = tb_width();
496 0 ▶ return $cols > 0 ? $cols : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cols > 0 ? : 0 0 0
497 }
498
499 134 ▶sub getScreenMode { # $mode ($class)
Subroutine getScreenMode: called CC=7 SCAR=35.8
Pod undocumented
500 134 assert ( @_ == 1 );
501 134 ▶ assert ( $_[0] and !ref $_[0] );
Condition33%1/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
00134
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table33%1/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
502 134 assert ( $initialized );
503
504 0 my $rows = tb_height();
505 0 ▶ return 0 unless $rows > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $rows > 0 0 0 0
506
507 # Invalid or unspecified mode.
508 0 ▶ unless ( $screenMode ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($screenMode) 0 0 0
509 # https://no-color.org/
510 $screenMode = exists $ENV{NO_COLOR} && $ENV{NO_COLOR}
511 0 ▶ ? smMono
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{'NO_COLOR'} && $ENV{'NO_COLOR'} ? : 0 0 0
Condition0%0/3
exists $ENV{"NO_COLOR"} and $ENV{"NO_COLOR"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $ENV{"NO_COLOR"} and $ENV{"NO_COLOR"}
exists $ENV{"NO_COLOR"} $ENV{"NO_COLOR"}
Truth table0%0/3
A and B
A= exists $ENV{"NO_COLOR"}B= $ENV{"NO_COLOR"}
ABresult
0X0
100
111
512 : smCO80;
513 }
514
515 0 my $mode = $screenMode;
516 0 $mode &= ~smFont8x8;
517 0 ▶ $mode |= smFont8x8 if $rows > 25;
Branch: 1 branch
BranchTrueFalseTotal
if $rows > 25 0 0 0
518 0 return $mode;
519 }
520
521 0 ▶sub setScreenMode { # void ($class, $mode)
Subroutine setScreenMode: not called CC=21 SCAR=61.4
Pod undocumented
522 0 my ( $class, $mode ) = @_;
523 0 assert ( @_ == 2 );
524 0 ▶ assert ( $class and !ref $class );
Condition0%0/3
$class && !ref($class)
!ll&&!rl&&r
000
MC/DC0%0/2
$class && !ref($class)
$class !ref($class)
Truth table0%0/3
A && not(B)
A= $classB= !ref($class)
ABresult
0X0
100
111
525 0 assert ( looks_like_number $mode );
526 0 assert ( $initialized );
527
528 0 ▶ return unless tb_height() > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless tb_height() > 0 0 0 0
529
530 # Fix the requested mode to a valid output mode.
531 0 my $base = $mode & 0xff;
532 0 ▶ if ( $base != smCO80
Branch: 1 branch
BranchTrueFalseTotal
if ($base != 3 and $base != 2 and $base != 7) 0 0 0
Condition0%0/6
$base != 3 and $base != 2 and $base != 7
!ll&&!rl&&r
000
$base != 3 and $base != 2
!ll&&!rl&&r
000
MC/DC0%0/3
$base != 3 and $base != 2 and $base != 7
$base != 3 $base != 2 $base != 7
Truth table0%0/4
A and B and C
A= $base != 3B= $base != 2C= $base != 7
ABCresult
0XX0
10X0
1100
1111
533 && $base != smBW80
534 && $base != smMono
535 ) {
536 0 $mode = ( $mode & 0xff00 ) | smCO80;
537 }
538 0 $mode &= ~smUpdate;
539 0 ▶ $mode &= ~smColorHigh
Branch: 1 branch
BranchTrueFalseTotal
if $mode & 1024 and !tb_has_truecolor() || $class->getColorCount < 16777216 0 0 0
Condition0%0/6
$mode & 1024 and !tb_has_truecolor() || $class->getColorCount < 16777216
!ll&&!rl&&r
000
not tb_has_truecolor() or $class->getColorCount < 16777216
l!l&&r!l&&!r
000
MC/DC0%0/3
$mode & 1024 and !tb_has_truecolor() || $class->getColorCount < 16777216
$mode & 1024 not tb_has_truecolor() $class->getColorCount < 16777216
Truth table0%0/4
A and not(B) or C
A= $mode & 1024B= not tb_has_truecolor()C= $class->getColorCount < 16777216
ABCresult
0XX0
1000
11X1
1011
540 if ( $mode & smColorHigh )
541 && ( !tb_has_truecolor() || $class->getColorCount() < 256*256*256 );
542 0 ▶ $mode &= ~smColor256
Branch: 1 branch
BranchTrueFalseTotal
if $mode & 512 and $class->getColorCount < 256 0 0 0
Condition0%0/3
$mode & 512 and $class->getColorCount < 256
!ll&&!rl&&r
000
MC/DC0%0/2
$mode & 512 and $class->getColorCount < 256
$mode & 512 $class->getColorCount < 256
Truth table0%0/3
A and B
A= $mode & 512B= $class->getColorCount < 256
ABresult
0X0
100
111
543 if ( $mode & smColor256 )
544 && $class->getColorCount() < 256;
545
546 # Set the appropriate output mode based on the requested screen mode.
547 0 ▶ if ( $mode & smColorHigh ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($mode & 1024) { } 0 0 0
elsif ($mode & 512) { } 0 0 0
elsif ($class->getColorCount >= 16) { } 0 0 0
548 0 ▶ tb_set_output_mode( TB_OUTPUT_TRUECOLOR )
Branch: 1 branch
BranchTrueFalseTotal
if tb_has_truecolor() and $outputMode != 5 0 0 0
Condition0%0/3
tb_has_truecolor() and $outputMode != 5
!ll&&!rl&&r
000
MC/DC0%0/2
tb_has_truecolor() and $outputMode != 5
tb_has_truecolor() $outputMode != 5
Truth table0%0/3
A and B
A= tb_has_truecolor()B= $outputMode != 5
ABresult
0X0
100
111
549 if tb_has_truecolor()
550 && $outputMode != TB_OUTPUT_TRUECOLOR
551 }
552 elsif ( $mode & smColor256 ) {
553 0 ▶ tb_set_output_mode( TB_OUTPUT_256 )
Branch: 1 branch
BranchTrueFalseTotal
if $outputMode != 2 0 0 0
554 if $outputMode != TB_OUTPUT_256;
555 }
556 elsif ( $class->getColorCount() >= 16 ) {
557 0 ▶ tb_set_output_mode( TB_OUTPUT_256 )
Branch: 1 branch
BranchTrueFalseTotal
if $outputMode != 2 0 0 0
558 if $outputMode != TB_OUTPUT_256;
559 }
560 else {
561 0 ▶ tb_set_output_mode( TB_OUTPUT_NORMAL )
Branch: 1 branch
BranchTrueFalseTotal
if $outputMode != 1 0 0 0
562 if $outputMode != TB_OUTPUT_NORMAL;
563 }
564
565 # Clear the attribute cache, since the color mapping has changed.
566 0 %$TB_ATTR = ();
567
568 # Save the current output state
569 0 $screenMode = $mode;
570 0 $outputMode = tb_set_output_mode( TB_OUTPUT_CURRENT );
571
572 # Update attribute constants according to the active output mode.
573 # Termbox may uses different attribute ranges in TrueColor mode.
574 0 ▶ if ( tb_has_truecolor() && $outputMode == TB_OUTPUT_TRUECOLOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (tb_has_truecolor() and $outputMode == 5) { } 0 0 0
Condition0%0/3
tb_has_truecolor() and $outputMode == 5
!ll&&!rl&&r
000
MC/DC0%0/2
tb_has_truecolor() and $outputMode == 5
tb_has_truecolor() $outputMode == 5
Truth table0%0/3
A and B
A= tb_has_truecolor()B= $outputMode == 5
ABresult
0X0
100
111
575 0 $attrBold = TB_TRUECOLOR_BOLD;
576 0 $attrUnderline = TB_TRUECOLOR_UNDERLINE;
577 0 $attrReverse = TB_TRUECOLOR_REVERSE;
578 0 $attrBlink = TB_TRUECOLOR_BLINK;
579 0 $attrBlack = TB_TRUECOLOR_BLACK;
580 }
581 else {
582 0 $attrBold = TB_BOLD;
583 0 $attrUnderline = TB_UNDERLINE;
584 0 $attrReverse = TB_REVERSE;
585 0 $attrBlink = TB_BLINK;
586 0 $attrBlack = TB_HI_BLACK;
587 }
588
589 0 return;
590 }
591
592 0 ▶sub clearScreen { # void ($class, $w, $h)
Subroutine clearScreen: not called CC=2 SCAR=17.9
Pod undocumented
593 0 my ( $class, $w, $h ) = @_;
594 0 assert ( @_ == 3 );
595 0 ▶ assert ( $class and !ref $class );
Condition0%0/3
$class && !ref($class)
!ll&&!rl&&r
000
MC/DC0%0/2
$class && !ref($class)
$class !ref($class)
Truth table0%0/3
A && not(B)
A= $classB= !ref($class)
ABresult
0X0
100
111
596 0 assert ( looks_like_number $w );
597 0 assert ( looks_like_number $h );
598 0 assert ( $initialized );
599 0 tb_clear();
600 0 return;
601 }
602
603 0 ▶sub screenWrite { # void ($class, $x, $y, $buf, $len)
Subroutine screenWrite: not called CC=4 SCAR=30.0
Pod undocumented
604 0 my ( $class, $x, $y, $buf, $len ) = @_;
605 0 assert ( @_ == 5 );
606 0 ▶ assert ( $class and !ref $class );
Condition0%0/3
$class && !ref($class)
!ll&&!rl&&r
000
MC/DC0%0/2
$class && !ref($class)
$class !ref($class)
Truth table0%0/3
A && not(B)
A= $classB= !ref($class)
ABresult
0X0
100
111
607 0 assert ( looks_like_number $x );
608 0 assert ( looks_like_number $y );
609 0 assert ( ref $buf );
610 0 assert ( looks_like_number $len );
611 0 assert ( $initialized );
612
613 0 ▶ for ( my $i = 0 ; $i < $len ; ++$i, ++$x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
614 0 my $cell = $buf->[$i];
615 0 my $character = $cell->[0];
616 0 my $attribute = $cell->[1];
617
618 # Fast path equivalent for the code below:
619 # my $ch = Encode::decode( cp437 => $character->getText() );
620 0 my $ch = $UTF8_TO_CP437[ ord( $$character ) & 0xff ];
621
622 # Cached attribute conversion for the code below:
623 # my $attr = [
624 # $attribute->getForeground->$convertColor( true ),
625 # $attribute->getBackground->$convertColor( false ),
626 # ];
627 0 my $attr = $TB_ATTR->{$$attribute};
628 0 ▶ unless ( $attr ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attr) 0 0 0
629 0 $attr = [
630 $attribute->getForeground->$convertColor( true ),
631 $attribute->getBackground->$convertColor( false ),
632 ];
633 0 $TB_ATTR->{$$attribute} = $attr;
634 }
635
636 0 tb_set_cell( $x, $y, $ch, @$attr );
637 }
638
639 0 tb_present();
640 0 return;
641 }
642
643 0 ▶sub allocateScreenBuffer { # \@buffer ($class)
Subroutine allocateScreenBuffer: not called CC=6 SCAR=37.4
Pod undocumented
644 0 my ( $class ) = @_;
645 0 assert ( @_ == 1 );
646 0 ▶ assert ( $class and !ref $class );
Condition0%0/3
$class && !ref($class)
!ll&&!rl&&r
000
MC/DC0%0/2
$class && !ref($class)
$class !ref($class)
Truth table0%0/3
A && not(B)
A= $classB= !ref($class)
ABresult
0X0
100
111
647 0 assert ( $initialized );
648 0 $class->reloadScreenInfo();
649
650 0 my $cols = tb_width();
651 0 my $rows = tb_height();
652
653 0 ▶ return []
Branch: 1 branch
BranchTrueFalseTotal
if $cols <= 0 or $rows <= 0 0 0 0
Condition0%0/3
$cols <= 0 or $rows <= 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$cols <= 0 or $rows <= 0
$cols <= 0 $rows <= 0
Truth table0%0/3
A or B
A= $cols <= 0B= $rows <= 0
ABresult
1X1
011
000
654 if $cols <= 0 || $rows <= 0;
655
656 # Make sure we allocate at least enough for a 80x50 screen.
657 0 ▶ $cols = 80 if $cols < 80;
Branch: 1 branch
BranchTrueFalseTotal
if $cols < 80 0 0 0
658 0 ▶ $rows = 50 if $rows < 50;
Branch: 1 branch
BranchTrueFalseTotal
if $rows < 50 0 0 0
659
660 0 return [ map { TScreenCell->new() } 1 .. $cols * $rows ];
661 }
662
663 0 ▶sub freeScreenBuffer { # void ($class, \@buffer)
Subroutine freeScreenBuffer: not called CC=3 SCAR=24.8
Pod undocumented
664 0 assert ( @_ == 2 );
665 0 ▶ assert ( $_[0] and !ref $_[0] );
Condition0%0/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table0%0/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
666 0 ▶ assert ( ref $_[1] and !readonly @{ $_[1] } );
Condition0%0/3
ref $_[1] && !&readonly(scalar @{$_[1];})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[1] && !&readonly(scalar @{$_[1];})
ref $_[1] !&readonly(scalar @{$_[1];})
Truth table0%0/3
A && not(B)
A= ref $_[1]B= !&readonly(scalar @{$_[1];})
ABresult
0X0
100
111
667 0 $_[1] = [];
668 0 return;
669 }
670
671 # -------------------------------------------------------------------------
672 # Mouse functions
673 # -------------------------------------------------------------------------
674
675 135 ▶sub getButtonCount { # $num ($class)
Subroutine getButtonCount: called CC=3 SCAR=12.5
Pod undocumented
676 135 assert ( @_ == 1 );
677 135 ▶ assert ( $_[0] and !ref $_[0] );
Condition33%1/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
00135
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table33%1/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
678
679 # Termbox reports mouse events, but not a physical button count.
680 # Return a practical compatibility value.
681 135 ▶ return $initialized ? 3 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$initialized ? : 0 135 135
682 }
683
684 135 ▶sub cursorOn { # void ($class)
Subroutine cursorOn: called CC=2 SCAR=9.9
Pod undocumented
685 135 assert ( @_ == 1 );
686 135 ▶ assert ( $_[0] and !ref $_[0] );
Condition33%1/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
00135
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table33%1/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
687 135 assert ( $initialized );
688 0 my $mode = tb_set_input_mode( TB_INPUT_CURRENT );
689 0 tb_set_input_mode( $mode | TB_INPUT_MOUSE );
690 0 return;
691 }
692
693 192 ▶sub cursorOff { # void ($class)
Subroutine cursorOff: called CC=2 SCAR=9.9
Pod undocumented
694 192 assert ( @_ == 1 );
695 192 ▶ assert ( $_[0] and !ref $_[0] );
Condition33%1/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
00192
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table33%1/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
696 192 assert ( $initialized );
697 0 my $mode = tb_set_input_mode( TB_INPUT_CURRENT );
698 0 tb_set_input_mode( $mode & ~TB_INPUT_MOUSE );
699 0 return;
700 }
701
702 # -------------------------------------------------------------------------
703 # Event functions
704 # -------------------------------------------------------------------------
705
706 0 ▶sub clearPendingEvent { # void ($class)
Subroutine clearPendingEvent: not called CC=2 SCAR=17.9
Pod undocumented
707 0 assert ( @_ == 1 );
708 0 ▶ assert ( $_[0] and !ref $_[0] );
Condition0%0/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table0%0/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
709 0 $pendingEvent = 0;
710 0 return;
711 }
712
713 0 ▶sub getMouseEvent { # $bool ($class, $event)
Subroutine getMouseEvent: not called CC=11 SCAR=48.8
Pod undocumented
714 0 my ( $class, $event ) = @_;
715 0 assert ( @_ == 2 );
716 0 ▶ assert ( $class and !ref $class );
Condition0%0/3
$class && !ref($class)
!ll&&!rl&&r
000
MC/DC0%0/2
$class && !ref($class)
$class !ref($class)
Truth table0%0/3
A && not(B)
A= $classB= !ref($class)
ABresult
0X0
100
111
717 0 assert ( blessed $event );
718 0 assert ( $initialized );
719
720 # Check for pending events
721 0 ▶ unless ( $pendingEvent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($TUI::Drivers::HardwareInfo::Termbox::pendingEvent) 0 0 0
722 0 my $rv = tb_peek_event( $tb_event, 0 );
723 0 ▶ $pendingEvent = 1 if $rv == TB_OK;
Branch: 1 branch
BranchTrueFalseTotal
if $rv == 0 0 0 0
724 }
725
726 # Return false if there are no pending events
727 0 ▶ return false
Branch: 1 branch
BranchTrueFalseTotal
unless $TUI::Drivers::HardwareInfo::Termbox::pendingEvent 0 0 0
728 unless $pendingEvent;
729
730 # Return if the event is not a mouse event
731 0 ▶ return false
Branch: 1 branch
BranchTrueFalseTotal
if $tb_event->type != 3 0 0 0
732 if $tb_event->type != TB_EVENT_MOUSE;
733
734 # Track the state of mouse buttons
735 0 my $buttons = $lastButtons;
736 0 ▶ if ( $tb_event->key == TB_KEY_MOUSE_LEFT ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tb_event->key == 65512) { } 0 0 0
elsif ($tb_event->key == 65511) { } 0 0 0
elsif ($tb_event->key == 65509) { } 0 0 0
737 0 $buttons |= mbLeftButton;
738 }
739 elsif ( $tb_event->key == TB_KEY_MOUSE_RIGHT ) {
740 0 $buttons |= mbRightButton;
741 }
742 elsif ( $tb_event->key == TB_KEY_MOUSE_RELEASE ) {
743 0 $buttons = 0;
744 }
745
746 # Mouse position
747 0 my @where = ( $tb_event->x, $tb_event->y );
748 0 $event->{where}{x} = $where[0];
749 0 $event->{where}{y} = $where[1];
750
751 # Button state
752 0 $event->{buttons} = $buttons;
753
754 # Event flags. Double-clicks are detected by TEventQueue.
755 0 $event->{eventFlags} = 0;
756 0 ▶ $event->{eventFlags} |= meMouseMoved
Branch: 1 branch
BranchTrueFalseTotal
if $tb_event->mod & 8 0 0 0
757 if $tb_event->mod & TB_MOD_MOTION;
758
759 # Mouse modifier state.
760 0 ▶ $event->{controlKeyState} = $insertState ? kbInsState : 0;
Branch: 1 branch
BranchTrueFalseTotal
$TUI::Drivers::HardwareInfo::Termbox::insertState ? : 0 0 0
761
762 # Save the last button state
763 0 $lastButtons = $buttons;
764
765 # Clear the pending event flag because we have consumed the event
766 0 $pendingEvent = 0;
767 0 return true;
768 }
769
770 0 ▶sub getKeyEvent { # $bool ($class, $event)
Subroutine getKeyEvent: not called CC=15 SCAR=54.8
Pod undocumented
771 0 my ( $class, $event ) = @_;
772 0 assert ( @_ == 2 );
773 0 ▶ assert ( $class and !ref $class );
Condition0%0/3
$class && !ref($class)
!ll&&!rl&&r
000
MC/DC0%0/2
$class && !ref($class)
$class !ref($class)
Truth table0%0/3
A && not(B)
A= $classB= !ref($class)
ABresult
0X0
100
111
774 0 assert ( blessed $event );
775 0 assert ( $initialized );
776
777 # Check for pending events
778 0 ▶ unless ( $pendingEvent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($TUI::Drivers::HardwareInfo::Termbox::pendingEvent) 0 0 0
779 0 my $rv = tb_peek_event( $tb_event, 0 );
780 0 ▶ $pendingEvent = 1 if $rv == TB_OK;
Branch: 1 branch
BranchTrueFalseTotal
if $rv == 0 0 0 0
781 }
782
783 # Return false if there are no pending events
784 0 ▶ return false
Branch: 1 branch
BranchTrueFalseTotal
unless $TUI::Drivers::HardwareInfo::Termbox::pendingEvent 0 0 0
785 unless $pendingEvent;
786
787 # Handle resize events immediately
788 0 ▶ if ( $tb_event->type == TB_EVENT_RESIZE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tb_event->type == 2) 0 0 0
789 0 $pendingEvent = 0;
790 0 ▶ if ( $class->screenChanged() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->screenChanged) 0 0 0
791 0 $event->{what} = evCommand;
792 0 $event->{message}{command} = cmScreenChanged;
793 0 $event->{message}{infoPtr} = undef;
794 0 return true;
795 }
796 0 return false;
797 }
798
799 # Return if the event is not a key event
800 0 ▶ return false
Branch: 1 branch
BranchTrueFalseTotal
if $tb_event->type != 1 0 0 0
801 if $tb_event->type != TB_EVENT_KEY;
802
803 0 $event->{what} = evKeyDown;
804
805 # Set the key code and character code in the event structure.
806 0 my $keyCode = $tb_event->$convertKeyCode();
807 0 $event->{keyDown}{keyCode} = $keyCode;
808 0 ▶ if ( $keyCode == kbNoKey ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($keyCode == 0) { } 0 0 0
elsif ($keyCode == 20992) { } 0 0 0
809 0 my $charCode = $tb_event->$convertCharCode();
810 0 $event->{keyDown}{charScan}{charCode} = $charCode;
811 }
812 elsif ( $keyCode == kbIns ) {
813 0 $insertState = !$insertState;
814 }
815
816 # Update the shift state and control key state in the event structure
817 0 my $shiftState = 0;
818 0 ▶ $shiftState |= kbAltShift
Branch: 1 branch
BranchTrueFalseTotal
if $tb_event->mod & 1 0 0 0
819 if $tb_event->mod & TB_MOD_ALT;
820 0 ▶ $shiftState |= kbCtrlShift
Branch: 1 branch
BranchTrueFalseTotal
if $tb_event->mod & 2 0 0 0
821 if $tb_event->mod & TB_MOD_CTRL;
822 0 ▶ $shiftState |= kbShift
Branch: 1 branch
BranchTrueFalseTotal
if $tb_event->mod & 4 0 0 0
823 if $tb_event->mod & TB_MOD_SHIFT;
824 0 ▶ $shiftState |= kbInsState
Branch: 1 branch
BranchTrueFalseTotal
if $TUI::Drivers::HardwareInfo::Termbox::insertState 0 0 0
825 if $insertState;
826 0 $event->{keyDown}{controlKeyState} = $shiftState;
827
828 # Set the Ctrl-Break flag if Ctrl-C was pressed
829 0 ▶ $ctrlBreakHit ||= $event->{keyDown}{keyCode} == kbCtrlC;
Condition0%0/3
$TUI::Drivers::HardwareInfo::Termbox::ctrlBreakHit ||= $event->{"keyDown"}{"keyCode"} == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$TUI::Drivers::HardwareInfo::Termbox::ctrlBreakHit ||= $event->{"keyDown"}{"keyCode"} == 3
$TUI::Drivers::HardwareInfo::Termbox::ctrlBreakHit $event->{"keyDown"}{"keyCode"} == 3
Truth table0%0/3
A ||= B
A= $TUI::Drivers::HardwareInfo::Termbox::ctrlBreakHitB= $event->{"keyDown"}{"keyCode"} == 3
ABresult
1X1
011
000
830
831 0 $pendingEvent = 0;
832 0 return true;
833 }
834
835 # -------------------------------------------------------------------------
836 # System functions
837 # -------------------------------------------------------------------------
838
839 0 ▶sub setCtrlBrkHandler { # $success ($class, $install)
Subroutine setCtrlBrkHandler: not called CC=3 SCAR=24.8
Pod undocumented
840 0 my ( $class, $install ) = @_;
841 0 assert ( @_ == 2 );
842 0 ▶ assert ( $class and !ref $class );
Condition0%0/3
$class && !ref($class)
!ll&&!rl&&r
000
MC/DC0%0/2
$class && !ref($class)
$class !ref($class)
Truth table0%0/3
A && not(B)
A= $classB= !ref($class)
ABresult
0X0
100
111
843 0 ▶ assert ( !defined $install or !ref $install );
Condition0%0/3
defined $install && ref $install
!ll&&!rl&&r
000
MC/DC0%0/2
defined $install && ref $install
defined $install ref $install
Truth table0%0/3
A && B
A= defined $installB= ref $install
ABresult
0X0
100
111
844 # Termbox handles terminal input itself. No direct Ctrl-Break handler.
845 0 return true;
846 }
847
848 0 ▶sub setCritErrorHandler { # $bool ($class, $install)
Subroutine setCritErrorHandler: not called CC=3 SCAR=24.8
Pod undocumented
849 0 assert ( @_ == 2 );
850 0 ▶ assert ( $_[0] and !ref $_[0] );
Condition0%0/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table0%0/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
851 0 ▶ assert ( !defined $_[1] or !ref $_[1] );
Condition0%0/3
defined $_[1] && ref $_[1]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[1] && ref $_[1]
defined $_[1] ref $_[1]
Truth table0%0/3
A && B
A= defined $_[1]B= ref $_[1]
ABresult
0X0
100
111
852 # Not applicable for Termbox.
853 0 return true;
854 }
855
856 # -------------------------------------------------------------------------
857 # Additional functions (not part of the original Borland interface)
858 # -------------------------------------------------------------------------
859
860 0 ▶sub getColorCount { # $count ($class)
Subroutine getColorCount: not called CC=20 SCAR=60.4
Pod undocumented
861 0 assert ( @_ == 1 );
862 0 ▶ assert ( $_[0] and !ref $_[0] );
Condition0%0/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table0%0/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
863
864 # Cache the color count to avoid recalculating it multiple times
865 0 state $COLORS;
866 0 ▶ return $COLORS if defined $COLORS;
Branch: 1 branch
BranchTrueFalseTotal
if defined $COLORS 0 0 0
867
868 # Is Windows 10 or later? (build 10586)
869 0 ▶ if ( $^O eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
870 # Simple OS version test for very old systems
871 0 require Win32;
872 0 ▶ return $COLORS = 16
Branch: 1 branch
BranchTrueFalseTotal
if (Win32::GetOSVersion())[1] < 6 0 0 0
873 if ( Win32::GetOSVersion() )[1] < 6;
874
875 # Check if we can enable Virtual Terminal processing.
876 0 require Win32API::File;
877 0 require Win32::Console;
878 0 my $ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
879
880 0 my $console = Win32::Console->new( Win32API::File::STD_OUTPUT_HANDLE() );
881 0 ▶ return $COLORS = 16 unless $console;
Branch: 1 branch
BranchTrueFalseTotal
unless $console 0 0 0
882
883 0 $^E = 0;
884 0 my $mode = $console->Mode();
885 0 ▶ return $COLORS = 16 if $^E;
Branch: 1 branch
BranchTrueFalseTotal
if $^E 0 0 0
886
887 0 $console->Mode($mode | $ENABLE_VIRTUAL_TERMINAL_PROCESSING);
888 0 ▶ my $isVT = !$^E
Condition0%0/5
!$^E && ($console->Mode // 0) & $ENABLE_VIRTUAL_TERMINAL_PROCESSING
!ll&&!rl&&r
000
$console->Mode // 0
l!l
00
MC/DC0%0/2
!$^E && ($console->Mode // 0) & $ENABLE_VIRTUAL_TERMINAL_PROCESSING
!$^E $console->Mode
Truth table0%0/3
not(A) && B
A= !$^EB= $console->Mode
ABresult
0X0
100
111
889 && ( $console->Mode() // 0 ) & $ENABLE_VIRTUAL_TERMINAL_PROCESSING;
890
891 0 $console->Mode( $mode );
892
893 # VT processing implies modern console host.
894 # Only modern VT hosts support 24-bit colors.
895 0 ▶ return $COLORS = !$isVT ? 16
Branch: 2 branches
BranchTrueFalseTotal
!$isVT ? : 0 0 0
!tb_has_truecolor() ? : 0 0 0
896 : !tb_has_truecolor() ? 256
897 : 256*256*256;
898 }
899
900 # First check COLORTERM environment
901 0 ▶ if ( tb_has_truecolor() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (tb_has_truecolor()) 0 0 0
902 0 ▶ my $colorterm = $ENV{COLORTERM} // '';
Condition0%0/2
$ENV{"COLORTERM"} // ""
l!l
00
MC/DC0%0/1
$ENV{"COLORTERM"} // ""
$ENV{"COLORTERM"}
Truth table0%0/2
A
A= $ENV{"COLORTERM"}
Aresult
11
00
903 0 ▶ return $COLORS = 256*256*256
Branch: 1 branch
BranchTrueFalseTotal
if $colorterm =~ /\A(?:truecolor|24bit)\z/i 0 0 0
904 if $colorterm =~ /\A(?:truecolor|24bit)\z/i;
905 }
906
907 # Next check terminfo database
908 0 my $colors = eval {
909 0 require Term::Cap;
910 0 ▶ local $SIG{__WARN__} = sub { }; # Suppress warnings from Tgetent
Subroutine __ANON__: not called CC=1 SCAR=6.9
911 0 Term::Cap->Tgetent()->{_Co};
912 };
913 0 ▶ return $COLORS = $colors
Branch: 1 branch
BranchTrueFalseTotal
if not $@ and defined $colors and $colors >= 8 0 0 0
Condition0%0/6
not $@ and defined $colors and $colors >= 8
!ll&&!rl&&r
000
not $@ and defined $colors
!ll&&!rl&&r
000
MC/DC0%0/3
not $@ and defined $colors and $colors >= 8
not $@ defined $colors $colors >= 8
Truth table0%0/4
not(A) and B and C
A= not $@B= defined $colorsC= $colors >= 8
ABCresult
0XX0
10X0
1100
1111
914 if !$@ && defined $colors && $colors >=8;
915
916 # Otherwise check for common TERM values that indicate color support.
917 0 ▶ my $term = $ENV{TERM} // '';
Condition0%0/2
$ENV{"TERM"} // ""
l!l
00
MC/DC0%0/1
$ENV{"TERM"} // ""
$ENV{"TERM"}
Truth table0%0/2
A
A= $ENV{"TERM"}
Aresult
11
00
918 0 ▶ return $COLORS = 256 if $term =~ /256color/i;
Branch: 1 branch
BranchTrueFalseTotal
if $term =~ /256color/i 0 0 0
919
920 # Let's assume all terminals disguising themselves as 'xterm'
921 # support at least 16 colors.
922 0 ▶ return $COLORS = 16 if $term =~ /xterm/;
Branch: 1 branch
BranchTrueFalseTotal
if $term =~ /xterm/ 0 0 0
923
924 # Fall back to a conservative default of 8 colors.
925 0 return $COLORS = 8;
926 } #/ sub getColorCount
927
928 0 ▶sub reloadScreenInfo { # void ($class)
Subroutine reloadScreenInfo: not called CC=2 SCAR=17.9
Pod undocumented
929 0 assert ( @_ == 1 );
930 0 ▶ assert ( $_[0] and !ref $_[0] );
Condition0%0/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table0%0/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
931 0 tb_invalidate();
932 0 return;
933 }
934
935 0 ▶sub screenChanged { # $bool ($class)
Subroutine screenChanged: not called CC=4 SCAR=30.0
Pod undocumented
936 0 assert ( @_ == 1 );
937 0 ▶ assert ( $_[0] and !ref $_[0] );
Condition0%0/3
$_[0] && !ref($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0] !ref($_[0])
Truth table0%0/3
A && not(B)
A= $_[0]B= !ref($_[0])
ABresult
0X0
100
111
938 0 my $cols = tb_width();
939 0 my $rows = tb_height();
940 0 ▶ if ( $cols != $lastSize[0] || $rows != $lastSize[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cols != $lastSize[0] or $rows != $lastSize[1]) 0 0 0
Condition0%0/3
$cols != $lastSize[0] or $rows != $lastSize[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$cols != $lastSize[0] or $rows != $lastSize[1]
$cols != $lastSize[0] $rows != $lastSize[1]
Truth table0%0/3
A or B
A= $cols != $lastSize[0]B= $rows != $lastSize[1]
ABresult
1X1
011
000
941 0 @lastSize = ( $cols, $rows );
942 0 return true;
943 }
944 0 return false;
945 }
946
947 # -------------------------------------------------------------------------
948 # Key Event conversion
949 # -------------------------------------------------------------------------
950
951 141 my %TV_TO_TB = (
952 # Control keys
953 kbCtrlA() => [ TB_MOD_CTRL, TB_KEY_CTRL_A, 0 ],
954 kbCtrlB() => [ TB_MOD_CTRL, TB_KEY_CTRL_B, 0 ],
955 kbCtrlC() => [ TB_MOD_CTRL, TB_KEY_CTRL_C, 0 ],
956 kbCtrlD() => [ TB_MOD_CTRL, TB_KEY_CTRL_D, 0 ],
957 kbCtrlE() => [ TB_MOD_CTRL, TB_KEY_CTRL_E, 0 ],
958 kbCtrlF() => [ TB_MOD_CTRL, TB_KEY_CTRL_F, 0 ],
959 kbCtrlG() => [ TB_MOD_CTRL, TB_KEY_CTRL_G, 0 ],
960 kbCtrlH() => [ TB_MOD_CTRL, TB_KEY_CTRL_H, 0 ],
961 kbCtrlI() => [ TB_MOD_CTRL, TB_KEY_CTRL_I, 0 ],
962 kbCtrlJ() => [ TB_MOD_CTRL, TB_KEY_CTRL_J, 0 ],
963 kbCtrlK() => [ TB_MOD_CTRL, TB_KEY_CTRL_K, 0 ],
964 kbCtrlL() => [ TB_MOD_CTRL, TB_KEY_CTRL_L, 0 ],
965 kbCtrlM() => [ TB_MOD_CTRL, TB_KEY_CTRL_M, 0 ],
966 kbCtrlN() => [ TB_MOD_CTRL, TB_KEY_CTRL_N, 0 ],
967 kbCtrlO() => [ TB_MOD_CTRL, TB_KEY_CTRL_O, 0 ],
968 kbCtrlP() => [ TB_MOD_CTRL, TB_KEY_CTRL_P, 0 ],
969 kbCtrlQ() => [ TB_MOD_CTRL, TB_KEY_CTRL_Q, 0 ],
970 kbCtrlR() => [ TB_MOD_CTRL, TB_KEY_CTRL_R, 0 ],
971 kbCtrlS() => [ TB_MOD_CTRL, TB_KEY_CTRL_S, 0 ],
972 kbCtrlT() => [ TB_MOD_CTRL, TB_KEY_CTRL_T, 0 ],
973 kbCtrlU() => [ TB_MOD_CTRL, TB_KEY_CTRL_U, 0 ],
974 kbCtrlV() => [ TB_MOD_CTRL, TB_KEY_CTRL_V, 0 ],
975 kbCtrlW() => [ TB_MOD_CTRL, TB_KEY_CTRL_W, 0 ],
976 kbCtrlX() => [ TB_MOD_CTRL, TB_KEY_CTRL_X, 0 ],
977 kbCtrlY() => [ TB_MOD_CTRL, TB_KEY_CTRL_Y, 0 ],
978 kbCtrlZ() => [ TB_MOD_CTRL, TB_KEY_CTRL_Z, 0 ],
979
980 # Extended key codes
981 kbEsc() => [ TB_NONE, TB_KEY_ESC, 0 ],
982 kbAltSpace() => [ TB_MOD_ALT, TB_KEY_SPACE, 0 ],
983
984 kbCtrlIns() => [ TB_MOD_CTRL, TB_KEY_INSERT, 0 ],
985 kbShiftIns() => [ TB_MOD_SHIFT, TB_KEY_INSERT, 0 ],
986
987 kbCtrlDel() => [ TB_MOD_CTRL, TB_KEY_DELETE, 0 ],
988 kbShiftDel() => [ TB_MOD_SHIFT, TB_KEY_DELETE, 0 ],
989
990 kbBack() => [ TB_MOD_CTRL, TB_KEY_BACKSPACE2, 0 ],
991 kbCtrlBack() => [ TB_MOD_CTRL, TB_KEY_BACKSPACE, 0 ],
992
993 kbShiftTab() => [ TB_NONE, TB_KEY_BACK_TAB, 0 ],
994 kbTab() => [ TB_NONE, TB_KEY_TAB, 0 ],
995
996 kbCtrlEnter() => [ TB_MOD_CTRL, TB_KEY_CTRL_J, 0 ],
997 kbEnter() => [ TB_MOD_CTRL, TB_KEY_ENTER, 0 ],
998
999 # Alt letters
1000 kbAltQ() => [ TB_MOD_ALT, 0, ord('q') ],
1001 kbAltW() => [ TB_MOD_ALT, 0, ord('w') ],
1002 kbAltE() => [ TB_MOD_ALT, 0, ord('e') ],
1003 kbAltR() => [ TB_MOD_ALT, 0, ord('r') ],
1004 kbAltT() => [ TB_MOD_ALT, 0, ord('t') ],
1005 kbAltY() => [ TB_MOD_ALT, 0, ord('y') ],
1006 kbAltU() => [ TB_MOD_ALT, 0, ord('u') ],
1007 kbAltI() => [ TB_MOD_ALT, 0, ord('i') ],
1008 kbAltO() => [ TB_MOD_ALT, 0, ord('o') ],
1009 kbAltP() => [ TB_MOD_ALT, 0, ord('p') ],
1010
1011 kbAltA() => [ TB_MOD_ALT, 0, ord('a') ],
1012 kbAltS() => [ TB_MOD_ALT, 0, ord('s') ],
1013 kbAltD() => [ TB_MOD_ALT, 0, ord('d') ],
1014 kbAltF() => [ TB_MOD_ALT, 0, ord('f') ],
1015 kbAltG() => [ TB_MOD_ALT, 0, ord('g') ],
1016 kbAltH() => [ TB_MOD_ALT, 0, ord('h') ],
1017 kbAltJ() => [ TB_MOD_ALT, 0, ord('j') ],
1018 kbAltK() => [ TB_MOD_ALT, 0, ord('k') ],
1019 kbAltL() => [ TB_MOD_ALT, 0, ord('l') ],
1020
1021 kbAltZ() => [ TB_MOD_ALT, 0, ord('z') ],
1022 kbAltX() => [ TB_MOD_ALT, 0, ord('x') ],
1023 kbAltC() => [ TB_MOD_ALT, 0, ord('c') ],
1024 kbAltV() => [ TB_MOD_ALT, 0, ord('v') ],
1025 kbAltB() => [ TB_MOD_ALT, 0, ord('b') ],
1026 kbAltN() => [ TB_MOD_ALT, 0, ord('n') ],
1027 kbAltM() => [ TB_MOD_ALT, 0, ord('m') ],
1028
1029 # Function keys
1030 kbF1() => [ TB_NONE, TB_KEY_F1, 0 ],
1031 kbF2() => [ TB_NONE, TB_KEY_F2, 0 ],
1032 kbF3() => [ TB_NONE, TB_KEY_F3, 0 ],
1033 kbF4() => [ TB_NONE, TB_KEY_F4, 0 ],
1034 kbF5() => [ TB_NONE, TB_KEY_F5, 0 ],
1035 kbF6() => [ TB_NONE, TB_KEY_F6, 0 ],
1036 kbF7() => [ TB_NONE, TB_KEY_F7, 0 ],
1037 kbF8() => [ TB_NONE, TB_KEY_F8, 0 ],
1038 kbF9() => [ TB_NONE, TB_KEY_F9, 0 ],
1039 kbF10() => [ TB_NONE, TB_KEY_F10, 0 ],
1040 kbF11() => [ TB_NONE, TB_KEY_F11, 0 ],
1041 kbF12() => [ TB_NONE, TB_KEY_F12, 0 ],
1042
1043 kbShiftF1() => [ TB_MOD_SHIFT, TB_KEY_F1, 0 ],
1044 kbShiftF2() => [ TB_MOD_SHIFT, TB_KEY_F2, 0 ],
1045 kbShiftF3() => [ TB_MOD_SHIFT, TB_KEY_F3, 0 ],
1046 kbShiftF4() => [ TB_MOD_SHIFT, TB_KEY_F4, 0 ],
1047 kbShiftF5() => [ TB_MOD_SHIFT, TB_KEY_F5, 0 ],
1048 kbShiftF6() => [ TB_MOD_SHIFT, TB_KEY_F6, 0 ],
1049 kbShiftF7() => [ TB_MOD_SHIFT, TB_KEY_F7, 0 ],
1050 kbShiftF8() => [ TB_MOD_SHIFT, TB_KEY_F8, 0 ],
1051 kbShiftF9() => [ TB_MOD_SHIFT, TB_KEY_F9, 0 ],
1052 kbShiftF10() => [ TB_MOD_SHIFT, TB_KEY_F10, 0 ],
1053 kbShiftF11() => [ TB_MOD_SHIFT, TB_KEY_F11, 0 ],
1054 kbShiftF12() => [ TB_MOD_SHIFT, TB_KEY_F12, 0 ],
1055
1056 kbCtrlF1() => [ TB_MOD_CTRL, TB_KEY_F1, 0 ],
1057 kbCtrlF2() => [ TB_MOD_CTRL, TB_KEY_F2, 0 ],
1058 kbCtrlF3() => [ TB_MOD_CTRL, TB_KEY_F3, 0 ],
1059 kbCtrlF4() => [ TB_MOD_CTRL, TB_KEY_F4, 0 ],
1060 kbCtrlF5() => [ TB_MOD_CTRL, TB_KEY_F5, 0 ],
1061 kbCtrlF6() => [ TB_MOD_CTRL, TB_KEY_F6, 0 ],
1062 kbCtrlF7() => [ TB_MOD_CTRL, TB_KEY_F7, 0 ],
1063 kbCtrlF8() => [ TB_MOD_CTRL, TB_KEY_F8, 0 ],
1064 kbCtrlF9() => [ TB_MOD_CTRL, TB_KEY_F9, 0 ],
1065 kbCtrlF10() => [ TB_MOD_CTRL, TB_KEY_F10, 0 ],
1066 kbCtrlF11() => [ TB_MOD_CTRL, TB_KEY_F11, 0 ],
1067 kbCtrlF12() => [ TB_MOD_CTRL, TB_KEY_F12, 0 ],
1068
1069 kbAltF1() => [ TB_MOD_ALT, TB_KEY_F1, 0 ],
1070 kbAltF2() => [ TB_MOD_ALT, TB_KEY_F2, 0 ],
1071 kbAltF3() => [ TB_MOD_ALT, TB_KEY_F3, 0 ],
1072 kbAltF4() => [ TB_MOD_ALT, TB_KEY_F4, 0 ],
1073 kbAltF5() => [ TB_MOD_ALT, TB_KEY_F5, 0 ],
1074 kbAltF6() => [ TB_MOD_ALT, TB_KEY_F6, 0 ],
1075 kbAltF7() => [ TB_MOD_ALT, TB_KEY_F7, 0 ],
1076 kbAltF8() => [ TB_MOD_ALT, TB_KEY_F8, 0 ],
1077 kbAltF9() => [ TB_MOD_ALT, TB_KEY_F9, 0 ],
1078 kbAltF10() => [ TB_MOD_ALT, TB_KEY_F10, 0 ],
1079 kbAltF11() => [ TB_MOD_ALT, TB_KEY_F11, 0 ],
1080 kbAltF12() => [ TB_MOD_ALT, TB_KEY_F12, 0 ],
1081
1082 # Navigation
1083 kbHome() => [ TB_NONE, TB_KEY_HOME, 0 ],
1084 kbEnd() => [ TB_NONE, TB_KEY_END, 0 ],
1085
1086 kbPgUp() => [ TB_NONE, TB_KEY_PGUP, 0 ],
1087 kbPgDn() => [ TB_NONE, TB_KEY_PGDN, 0 ],
1088
1089 kbUp() => [ TB_NONE, TB_KEY_ARROW_UP, 0 ],
1090 kbDown() => [ TB_NONE, TB_KEY_ARROW_DOWN, 0 ],
1091 kbLeft() => [ TB_NONE, TB_KEY_ARROW_LEFT, 0 ],
1092 kbRight() => [ TB_NONE, TB_KEY_ARROW_RIGHT, 0 ],
1093
1094 kbCtrlLeft() => [ TB_MOD_CTRL, TB_KEY_ARROW_LEFT, 0 ],
1095 kbCtrlRight() => [ TB_MOD_CTRL, TB_KEY_ARROW_RIGHT, 0 ],
1096
1097 kbCtrlHome() => [ TB_MOD_CTRL, TB_KEY_HOME, 0 ],
1098 kbCtrlEnd() => [ TB_MOD_CTRL, TB_KEY_END, 0 ],
1099
1100 kbCtrlPgUp() => [ TB_MOD_CTRL, TB_KEY_PGUP, 0 ],
1101 kbCtrlPgDn() => [ TB_MOD_CTRL, TB_KEY_PGDN, 0 ],
1102
1103 kbIns() => [ TB_NONE, TB_KEY_INSERT, 0 ],
1104 kbDel() => [ TB_NONE, TB_KEY_DELETE, 0 ],
1105
1106 # Alt digits
1107 kbAlt1() => [ TB_MOD_ALT, 0, ord('1') ],
1108 kbAlt2() => [ TB_MOD_ALT, 0, ord('2') ],
1109 kbAlt3() => [ TB_MOD_ALT, 0, ord('3') ],
1110 kbAlt4() => [ TB_MOD_ALT, 0, ord('4') ],
1111 kbAlt5() => [ TB_MOD_ALT, 0, ord('5') ],
1112 kbAlt6() => [ TB_MOD_ALT, 0, ord('6') ],
1113 kbAlt7() => [ TB_MOD_ALT, 0, ord('7') ],
1114 kbAlt8() => [ TB_MOD_ALT, 0, ord('8') ],
1115 kbAlt9() => [ TB_MOD_ALT, 0, ord('9') ],
1116 kbAlt0() => [ TB_MOD_ALT, 0, ord('0') ],
1117
1118 kbAltMinus() => [ TB_MOD_ALT, 0, ord('-') ],
1119 kbAltEqual() => [ TB_MOD_ALT, 0, ord('=') ],
1120
1121 kbAltBack() => [
1122 TB_MOD_ALT | TB_MOD_CTRL,
1123 TB_KEY_BACKSPACE2,
1124 0
1125 ],
1126
1127 kbNoKey() => [ TB_NONE, 0, 0 ],
1128
1129 # kbGrayMinus() => collides with '-'
1130 # kbGrayPlus() => collides with '+'
1131 # kbCtrlPrtSc() => no event generated (effectively collides with kbNoKey())
1132 );
1133 141 my %TB_TO_TV; {
1134 141 ▶ while ( my ( $tv_key, $tb_key ) = each %TV_TO_TB ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %TV_TO_TB) 19740 141 19881
1135 19740 my ( $mod, $key, $ch ) = @$tb_key;
1136
1137 # Default: first mapping wins.
1138 # This avoids accidental replacement caused by hash iteration order.
1139 19740 my $id = join( ':', ( $mod, $key, $ch ) );
1140 $TB_TO_TV{$id} = $tv_key
1141 19740 ▶ unless exists $TB_TO_TV{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $TB_TO_TV{$id} 19317 423 19740
1142 }
1143
1144 # VT control-code collisions.
1145 #
1146 # VT stream TV keys Preferred
1147 # ------------------------------------------------
1148 # 0x08 Ctrl-H, Ctrl-Back Ctrl-Back
1149 # 0x09 Ctrl-I, Tab Tab
1150 # 0x0A Ctrl-J, Ctrl-Enter Ctrl-Enter
1151 # 0x0D Ctrl-M, Enter Enter
1152 141 $TB_TO_TV{ join( ':', TB_MOD_CTRL, TB_KEY_BACKSPACE, 0 ) }
1153 = kbCtrlBack();
1154 141 $TB_TO_TV{ join( ':', TB_MOD_CTRL, TB_KEY_TAB, 0 ) }
1155 = kbTab();
1156 141 $TB_TO_TV{ join( ':', TB_MOD_CTRL, TB_KEY_CTRL_J, 0 ) }
1157 = kbCtrlEnter();
1158 141 $TB_TO_TV{ join( ':', TB_MOD_CTRL, TB_KEY_ENTER, 0 ) }
1159 = kbEnter();
1160 }
1161 141 my %CP437 = map { $CP437_TO_UTF8[$_] => $_ } 0..255;
1162
1163 0 ▶$convertCharCode = sub { # $charCode ($event)
Subroutine __ANON__: not called CC=7 SCAR=40.3
1164 0 my ( $event ) = @_;
1165
1166 0 my $cp = $event->ch;
1167
1168 # Support the official Unicode values instead only the Termius equivalents
1169 0 ▶ return 0x10 if $cp == ord "\x{25ba}";
Branch: 1 branch
BranchTrueFalseTotal
if $cp == 9658 0 0 0
1170 0 ▶ return 0x11 if $cp == ord "\x{25c4}";
Branch: 1 branch
BranchTrueFalseTotal
if $cp == 9668 0 0 0
1171
1172 return $CP437{$cp}
1173 0 ▶ if $cp && exists $CP437{$cp};
Branch: 1 branch
BranchTrueFalseTotal
if $cp and exists $CP437{$cp} 0 0 0
Condition0%0/3
$cp and exists $CP437{$cp}
!ll&&!rl&&r
000
MC/DC0%0/2
$cp and exists $CP437{$cp}
$cp exists $CP437{$cp}
Truth table0%0/3
A and B
A= $cpB= exists $CP437{$cp}
ABresult
0X0
100
111
1174
1175 0 my $key = $event->key;
1176
1177 0 ▶ return $key
Branch: 1 branch
BranchTrueFalseTotal
if $key <= 31 or $key == 127 0 0 0
Condition0%0/3
$key <= 31 or $key == 127
l!l&&r!l&&!r
000
MC/DC0%0/2
$key <= 31 or $key == 127
$key <= 31 $key == 127
Truth table0%0/3
A or B
A= $key <= 31B= $key == 127
ABresult
1X1
011
000
1178 if $key <= 0x1f || $key == 0x7f;
1179
1180 0 return 0;
1181 141 };
1182
1183 0 ▶$convertKeyCode = sub { # $keyCode ($event)
Subroutine __ANON__: not called CC=25 SCAR=64.8
1184 0 my ( $event ) = @_;
1185
1186 0 my $mod = $event->mod;
1187 0 my $key = $event->key;
1188 0 my $ch = $event->ch;
1189
1190 # Keep only keyboard modifier bits relevant for the key mapping.
1191 0 $mod &= TB_MOD_ALT | TB_MOD_CTRL | TB_MOD_SHIFT;
1192
1193 0 my $id = join( ':', $mod, $key, $ch );
1194 return $TB_TO_TV{$id}
1195 0 ▶ if exists $TB_TO_TV{$id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $TB_TO_TV{$id} 0 0 0
1196
1197 # Some Alt/Ctrl key combinations have no dedicated Borland key code.
1198 # Map them to the corresponding unmodified key.
1199 0 ▶ if ( $mod & ( TB_MOD_CTRL | TB_MOD_ALT ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod & 3) 0 0 0
1200 0 ▶ return kbUp if $key == TB_KEY_ARROW_UP;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65517 0 0 0
1201 0 ▶ return kbDown if $key == TB_KEY_ARROW_DOWN;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65516 0 0 0
1202 0 ▶ return kbIns if $key == TB_KEY_INSERT;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65523 0 0 0
1203 0 ▶ return kbDel if $key == TB_KEY_DELETE;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65522 0 0 0
1204 0 ▶ return kbTab if $key == TB_KEY_TAB;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 9 0 0 0
1205 0 ▶ return kbEnter if $key == TB_KEY_ENTER;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 13 0 0 0
1206 }
1207 0 ▶ if ( $mod & TB_MOD_ALT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod & 1) 0 0 0
1208 0 ▶ return kbLeft if $key == TB_KEY_ARROW_LEFT;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65515 0 0 0
1209 0 ▶ return kbRight if $key == TB_KEY_ARROW_RIGHT;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65514 0 0 0
1210 0 ▶ return kbHome if $key == TB_KEY_HOME;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65521 0 0 0
1211 0 ▶ return kbEnd if $key == TB_KEY_END;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65520 0 0 0
1212 0 ▶ return kbPgUp if $key == TB_KEY_PGUP;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65519 0 0 0
1213 0 ▶ return kbPgDn if $key == TB_KEY_PGDN;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65518 0 0 0
1214 }
1215
1216 # Shift selects text in the editor through controlKeyState. Shifted
1217 # navigation keys keep the unmodified key code, as in Turbo Vision.
1218 0 ▶ if ( $mod & TB_MOD_SHIFT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod & 4) 0 0 0
1219 0 ▶ return kbUp if $key == TB_KEY_ARROW_UP;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65517 0 0 0
1220 0 ▶ return kbDown if $key == TB_KEY_ARROW_DOWN;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65516 0 0 0
1221 0 ▶ return kbLeft if $key == TB_KEY_ARROW_LEFT;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65515 0 0 0
1222 0 ▶ return kbRight if $key == TB_KEY_ARROW_RIGHT;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65514 0 0 0
1223 0 ▶ return kbHome if $key == TB_KEY_HOME;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65521 0 0 0
1224 0 ▶ return kbEnd if $key == TB_KEY_END;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65520 0 0 0
1225 0 ▶ return kbPgUp if $key == TB_KEY_PGUP;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65519 0 0 0
1226 0 ▶ return kbPgDn if $key == TB_KEY_PGDN;
Branch: 1 branch
BranchTrueFalseTotal
if $key == 65518 0 0 0
1227 }
1228
1229 0 return kbNoKey();
1230 141 };
1231
1232 # -------------------------------------------------------------------------
1233 # Attribute conversion
1234 # -------------------------------------------------------------------------
1235
1236 # The following content is inspired by the framework
1237 # "A modern port of Turbo Vision 2.0", which is licensed under MIT licence.
1238 #
1239 # Copyright 2019-2026 by magiblot <magiblot@hotmail.com>
1240 #
1241 # I<ansiwrit.cpp>
1242
1243 0 ▶$convertColor = sub { # $tb_color ($color, $isFg)
Subroutine __ANON__: not called CC=7 SCAR=40.3
1244 0 my ( $color, $isFg ) = @_;
1245 0 assert ( @_ == 2 );
1246 0 assert ( blessed $color );
1247 0 assert ( !ref $isFg );
1248 0 ▶ return $color->$convertNoColor( $isFg )
Branch: 1 branch
BranchTrueFalseTotal
if ($screenMode & 255) == 7 0 0 0
1249 if ( $screenMode & 0xff ) == smMono;
1250
1251 0 ▶ return TB_DEFAULT
Branch: 1 branch
BranchTrueFalseTotal
if ($screenMode & 255) != 2 and ($screenMode & 255) != 3 0 0 0
Condition0%0/3
($screenMode & 255) != 2 and ($screenMode & 255) != 3
!ll&&!rl&&r
000
MC/DC0%0/2
($screenMode & 255) != 2 and ($screenMode & 255) != 3
($screenMode & 255) != 2 ($screenMode & 255) != 3
Truth table0%0/3
A and B
A= ($screenMode & 255) != 2B= ($screenMode & 255) != 3
ABresult
0X0
100
111
1252 if ( $screenMode & 0xff ) != smBW80
1253 && ( $screenMode & 0xff ) != smCO80;
1254
1255 0 ▶ return $color->$convertDirect( $isFg )
Branch: 1 branch
BranchTrueFalseTotal
if $screenMode & 1024 0 0 0
1256 if $screenMode & smColorHigh;
1257
1258 0 ▶ return $color->$convertIndexed256( $isFg )
Branch: 1 branch
BranchTrueFalseTotal
if $screenMode & 512 0 0 0
1259 if $screenMode & smColor256;
1260
1261 0 ▶ return $color->$convertIndexed16( $isFg )
Branch: 1 branch
BranchTrueFalseTotal
if $outputMode > 1 0 0 0
1262 if $outputMode > TB_OUTPUT_NORMAL;
1263
1264 0 return $color->$convertIndexed8( $isFg );
1265 141 };
1266
1267 0 ▶$convertNoColor = sub { # $tb_color ($color, $isFg)
Subroutine __ANON__: not called CC=6 SCAR=37.4
1268 0 my ( $color, $isFg ) = @_;
1269 0 assert ( @_ == 2 );
1270 0 assert ( blessed $color );
1271 0 assert ( !ref $isFg );
1272 0 my $c = TB_DEFAULT;
1273 0 ▶ if ( $color->isBIOS() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color->isBIOS) 0 0 0
1274 0 my $bios = $color->asBIOS();
1275 0 ▶ if ( $isFg ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($isFg) { } 0 0 0
elsif (($bios & 7) == 7) { } 0 0 0
1276 0 ▶ if ( $bios & 0x8 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bios & 8) { } 0 0 0
elsif ($bios == 1) { } 0 0 0
1277 0 $c |= $attrBold;
1278 }
1279 elsif ( $bios == 0x1 ) {
1280 0 $c |= $attrUnderline;
1281 }
1282 }
1283 elsif ( ( $bios & 0x7 ) == 0x7 ) {
1284 0 $c |= $attrReverse;
1285 }
1286 }
1287 0 return $c;
1288 141 };
1289
1290 0 ▶$convertIndexed8 = sub { # $tb_color ($color, $isFg)
Subroutine __ANON__: not called CC=5 SCAR=34.0
1291 0 my ( $color, $isFg ) = @_;
1292 0 assert ( @_ == 2 );
1293 0 assert ( blessed $color );
1294 0 assert ( !ref $isFg );
1295 0 my $idx = $color->$convertIndexed16( $isFg );
1296 0 my $c = ( $idx & 0x7 ) + 1;
1297 0 ▶ if ( $idx & 0x8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx & 8) 0 0 0
1298 0 ▶ $c |= $isFg ? $attrBold : $attrBlink;
Branch: 1 branch
BranchTrueFalseTotal
$isFg ? : 0 0 0
1299 }
1300 0 ▶ $c = TB_BLACK if $idx & $attrBlack;
Branch: 1 branch
BranchTrueFalseTotal
if $idx & $attrBlack 0 0 0
1301 0 ▶ $c = TB_DEFAULT if $idx == TB_DEFAULT;
Branch: 1 branch
BranchTrueFalseTotal
if $idx == 0 0 0 0
1302 0 return $c;
1303 141 };
1304
1305 0 ▶$convertIndexed16 = sub { # $tb_color ($color, $isFg)
Subroutine __ANON__: not called CC=8 SCAR=42.8
1306 0 my ( $color, $isFg ) = @_;
1307 0 assert ( @_ == 2 );
1308 0 assert ( blessed $color );
1309 0 assert ( !ref $isFg );
1310 0 ▶ if ( $color->isBIOS() ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($color->isBIOS) { } 0 0 0
elsif ($color->isXTerm) { } 0 0 0
elsif ($color->isRGB) { } 0 0 0
1311 0 my $idx = BIOStoXTerm16( $color->asBIOS() );
1312 0 ▶ return $idx == TB_DEFAULT ? $attrBlack : $idx;
Branch: 1 branch
BranchTrueFalseTotal
$idx == 0 ? : 0 0 0
1313 }
1314 elsif ( $color->isXTerm() ) {
1315 0 my $idx = $color->asXTerm();
1316 0 ▶ $idx = XTerm256toXTerm16( $idx )
Branch: 1 branch
BranchTrueFalseTotal
if $idx >= 16 0 0 0
1317 if $idx >= 16;
1318 0 ▶ return $idx == TB_DEFAULT ? $attrBlack : $idx;
Branch: 1 branch
BranchTrueFalseTotal
$idx == 0 ? : 0 0 0
1319 }
1320 elsif ( $color->isRGB() ) {
1321 0 my $idx = RGBtoXTerm16( $color->asRGB() );
1322 0 ▶ return $idx == TB_DEFAULT ? $attrBlack : $idx;
Branch: 1 branch
BranchTrueFalseTotal
$idx == 0 ? : 0 0 0
1323 }
1324 0 return TB_DEFAULT;
1325 141 };
1326
1327 0 ▶$convertIndexed256 = sub { # $tb_color ($color, $isFg)
Subroutine __ANON__: not called CC=5 SCAR=34.0
1328 0 my ( $color, $isFg ) = @_;
1329 0 assert ( @_ == 2 );
1330 0 assert ( blessed $color );
1331 0 assert ( !ref $isFg );
1332 0 ▶ if ( $color->isXTerm() ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($color->isXTerm) { } 0 0 0
elsif ($color->isRGB) { } 0 0 0
1333 0 my $idx = $color->asXTerm();
1334 0 ▶ return $idx == TB_DEFAULT ? $attrBlack : $idx;
Branch: 1 branch
BranchTrueFalseTotal
$idx == 0 ? : 0 0 0
1335 }
1336 elsif ( $color->isRGB() ) {
1337 0 my $idx = RGBtoXTerm256( $color->asRGB() );
1338 0 ▶ return $idx == TB_DEFAULT ? $attrBlack : $idx;
Branch: 1 branch
BranchTrueFalseTotal
$idx == 0 ? : 0 0 0
1339 }
1340 0 return $color->$convertIndexed16( $isFg );
1341 141 };
1342
1343 141 my @XTERM256 = (
1344 # 0-15: system colors
1345 0x000000, 0x800000, 0x008000, 0x808000,
1346 0x000080, 0x800080, 0x008080, 0xc0c0c0,
1347 0x808080, 0xff0000, 0x00ff00, 0xffff00,
1348 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff,
1349 ); {
1350 141 my @level = ( 0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff );
1351
1352 # 16-231: color cubes
1353 141 for my $r ( @level ) {
1354 846 for my $g ( @level ) {
1355 5076 for my $b ( @level ) {
1356 30456 push @XTERM256, ( $r << 16 ) | ( $g << 8 ) | $b;
1357 }
1358 }
1359 }
1360
1361 # 232-255: gray scale
1362 141 for my $i ( 0 .. 23 ) {
1363 3384 my $v = 8 + $i * 10;
1364 3384 push @XTERM256, ( $v << 16 ) | ( $v << 8 ) | $v;
1365 }
1366 }
1367
1368 0 ▶$convertDirect = sub { # $tb_color ($color, $isFg)
Subroutine __ANON__: not called CC=4 SCAR=30.0
1369 0 my ( $color, $isFg ) = @_;
1370 0 assert ( @_ == 2 );
1371 0 assert ( blessed $color );
1372 0 assert ( !ref $isFg );
1373 0 ▶ if ( $color->isRGB() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color->isRGB) 0 0 0
1374 0 my $idx = $color->asRGB();
1375 0 ▶ return $idx == TB_DEFAULT ? $attrBlack : $idx;
Branch: 1 branch
BranchTrueFalseTotal
$idx == 0 ? : 0 0 0
1376 }
1377 0 my $idx = $color->$convertIndexed256( $isFg );
1378 0 my $c = $XTERM256[ $idx & 0xff ];
1379 0 ▶ $c = $attrBlack if $idx & $attrBlack;
Branch: 1 branch
BranchTrueFalseTotal
if $idx & $attrBlack 0 0 0
1380 0 return $c;
1381 141 };
1382
1383 141 1;
1384
1385 __END__
« lib/TUI/Help/HelpViewer.pm ↑ Summary lib/TUI/StdDlg/SortedListBox.pm »