VT102.pm

filter: Statementstmt 76.2% 580 / 761 Branchbran 63.3% 257 / 406 Conditioncond 47.2% 34 / 72 MC/DCmcdc 34.0% 16 / 47 Subroutinesub 70.1% 61 / 87 Podpod 100% 25 / 25 totaltotal 69.6% 973 / 1398 CC 232 SCAR 39.2
CC
232
Cov
70%
sgr_change
506.0
row_sgrtext
156.0
_process_escseq
45.6
CRAP 50.6
↑ Summary VT102/examples/sanitize-dump.pl »
1 # Term::VT102 - module for VT102 emulation in Perl
2 #
3 # Copyright (C) Andrew Wood
4 # NO WARRANTY - see COPYING.
5 #
6  
7 package Term::VT102;
8  
9 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 14 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 ▶ use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 14 $VERSION = '0.91';
16  
17 14 @ISA = qw(Exporter);
18 }
19  
20  
21 # Return the packed version of a set of attributes fg, bg, bo, fa, st, ul,
22 # bl, rv.
23 #
24 132 ▶sub attr_pack {
Subroutine attr_pack: called CC=2 SCAR=6.9
Pod documented
25 132 ▶ shift if ref($_[0]); # called in object context, ditch the object
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 118 14 132
26 132 my ($fg, $bg, $bo, $fa, $st, $ul, $bl, $rv) = @_;
27 132 my $num = 0;
28  
29 132 $num = ($fg & 7)
30 | (($bg & 7) << 4)
31 | ($bo << 8)
32 | ($fa << 9)
33 | ($st << 10)
34 | ($ul << 11)
35 | ($bl << 12)
36 | ($rv << 13);
37 132 return pack ('S', $num);
38 }
39  
40  
41 # Return the unpacked version of a packed attribute.
42 #
43 30 ▶sub attr_unpack {
Subroutine attr_unpack: called CC=2 SCAR=7.0
Pod documented
44 30 ▶ shift if ref($_[0]); # called in object context, ditch the object
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 30 0 30
45 30 my $data = shift;
46 30 my ($num, $fg, $bg, $bo, $fa, $st, $ul, $bl, $rv);
47  
48 30 $num = unpack ('S', $data);
49  
50 30 ($fg, $bg, $bo, $fa, $st, $ul, $bl, $rv) = (
51 $num & 7,
52 ($num >> 4) & 7,
53 ($num >> 8) & 1,
54 ($num >> 9) & 1,
55 ($num >> 10) & 1,
56 ($num >> 11) & 1,
57 ($num >> 12) & 1,
58 ($num >> 13) & 1
59 );
60  
61 30 return ($fg, $bg, $bo, $fa, $st, $ul, $bl, $rv);
62 }
63  
64  
65 # Default attribute set (in both packed and unpacked flavors)
66 #
67 14 ▶use constant DEFAULT_ATTR => (7, 0, 0, 0, 0, 0, 0, 0);
Subroutine BEGIN: called CC=1 SCAR=0.0
68 14 ▶use constant DEFAULT_ATTR_PACKED => attr_pack(&DEFAULT_ATTR);
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70  
71 # Constructor function.
72 #
73 81 ▶sub new {
Subroutine new: called CC=6 SCAR=18.0
Pod documented
74 81 my ($proto, %init) = @_;
75 81 ▶ my $class = ref ($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0810
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
76 81 my $self = {};
77  
78 81 $self->{'_ctlseq'} = { ( # control characters
79 "\000" => 'NUL', # ignored
80 "\005" => 'ENQ', # trigger answerback message
81 "\007" => 'BEL', # beep
82 "\010" => 'BS', # backspace one column
83 "\011" => 'HT', # horizontal tab to next tab stop
84 "\012" => 'LF', # line feed
85 "\013" => 'VT', # line feed
86 "\014" => 'FF', # line feed
87 "\015" => 'CR', # carriage return
88 "\016" => 'SO', # activate G1 character set & newline
89 "\017" => 'SI', # activate G0 character set
90 "\021" => 'XON', # resume transmission
91 "\023" => 'XOFF', # stop transmission, ignore characters
92 "\030" => 'CAN', # interrupt escape sequence
93 "\032" => 'SUB', # interrupt escape sequence
94 "\033" => 'ESC', # start escape sequence
95 "\177" => 'DEL', # ignored
96 "\233" => 'CSI' # equivalent to ESC [
97 ) };
98  
99 81 $self->{'_escseq'} = { ( # escape sequences
100 'c' => 'RIS', # reset
101 'D' => 'IND', # line feed
102 'E' => 'NEL', # newline
103 'H' => 'HTS', # set tab stop at current column
104 'M' => 'RI', # reverse line feed
105 'Z' => 'DECID', # DEC private ID; return ESC [ ? 6 c (VT102)
106 '7' => 'DECSC', # save state (position, charset, attributes)
107 '8' => 'DECRC', # restore most recently saved state
108 '[' => 'CSI', # control sequence introducer
109 '[[' => 'IGN', # ignored control sequence
110 '%@' => 'CSDFL', # select default charset (ISO646/8859-1)
111 '%G' => 'CSUTF8', # select UTF-8
112 '%8' => 'CSUTF8', # select UTF-8 (obsolete)
113 '#8' => 'DECALN', # DEC alignment test - fill screen with E's
114 '(8' => 'G0DFL', # G0 charset = default mapping (ISO8859-1)
115 '(0' => 'G0GFX', # G0 charset = VT100 graphics mapping
116 '(U' => 'G0ROM', # G0 charset = null mapping (straight to ROM)
117 '(K' => 'G0USR', # G0 charset = user defined mapping
118 '(B' => 'G0TXT', # G0 charset = ASCII mapping
119 ')8' => 'G1DFL', # G1 charset = default mapping (ISO8859-1)
120 ')0' => 'G1GFX', # G1 charset = VT100 graphics mapping
121 ')U' => 'G1ROM', # G1 charset = null mapping (straight to ROM)
122 ')K' => 'G1USR', # G1 charset = user defined mapping
123 ')B' => 'G1TXT', # G1 charset = ASCII mapping
124 '*8' => 'G2DFL', # G2 charset = default mapping (ISO8859-1)
125 '*0' => 'G2GFX', # G2 charset = VT100 graphics mapping
126 '*U' => 'G2ROM', # G2 charset = null mapping (straight to ROM)
127 '*K' => 'G2USR', # G2 charset = user defined mapping
128 '+8' => 'G3DFL', # G3 charset = default mapping (ISO8859-1)
129 '+0' => 'G3GFX', # G3 charset = VT100 graphics mapping
130 '+U' => 'G3ROM', # G3 charset = null mapping (straight to ROM)
131 '+K' => 'G3USR', # G3 charset = user defined mapping
132 '>' => 'DECPNM', # set numeric keypad mode
133 '=' => 'DECPAM', # set application keypad mode
134 'N' => 'SS2', # select G2 charset for next char only
135 'O' => 'SS3', # select G3 charset for next char only
136 'P' => 'DCS', # device control string (ended by ST)
137 'X' => 'SOS', # start of string
138 '^' => 'PM', # privacy message (ended by ST)
139 '_' => 'APC', # application program command (ended by ST)
140 "\\" => 'ST', # string terminator
141 'n' => 'LS2', # invoke G2 charset
142 'o' => 'LS3', # invoke G3 charset
143 '|' => 'LS3R', # invoke G3 charset as GR
144 '}' => 'LS2R', # invoke G2 charset as GR
145 '~' => 'LS1R', # invoke G1 charset as GR
146 ']' => 'OSC', # operating system command
147 'g' => 'BEL', # alternate BEL
148 ) };
149  
150 81 $self->{'_csiseq'} = { ( # ECMA-48 CSI sequences
151 '[' => 'IGN', # ignored control sequence
152 '@' => 'ICH', # insert blank characters
153 'A' => 'CUU', # move cursor up
154 'B' => 'CUD', # move cursor down
155 'C' => 'CUF', # move cursor right
156 'D' => 'CUB', # move cursor left
157 'E' => 'CNL', # move cursor down and to column 1
158 'F' => 'CPL', # move cursor up and to column 1
159 'G' => 'CHA', # move cursor to column in current row
160 'H' => 'CUP', # move cursor to row, column
161 'J' => 'ED', # erase display
162 'K' => 'EL', # erase line
163 'L' => 'IL', # insert blank lines
164 'M' => 'DL', # delete lines
165 'P' => 'DCH', # delete characters on current line
166 'X' => 'ECH', # erase characters on current line
167 'a' => 'HPR', # move cursor right
168 'c' => 'DA', # return ESC [ ? 6 c (VT102)
169 'd' => 'VPA', # move to row (current column)
170 'e' => 'VPR', # move cursor down
171 'f' => 'HVP', # move cursor to row, column
172 'g' => 'TBC', # clear tab stop (CSI 3 g = clear all stops)
173 'h' => 'SM', # set mode
174 'l' => 'RM', # reset mode
175 'm' => 'SGR', # set graphic rendition
176 'n' => 'DSR', # device status report
177 'q' => 'DECLL', # set keyboard LEDs
178 'r' => 'DECSTBM', # set scrolling region to (top, bottom) rows
179 's' => 'CUPSV', # save cursor position
180 'u' => 'CUPRS', # restore cursor position
181 '`' => 'HPA' # move cursor to column in current row
182 ) };
183  
184 81 $self->{'_modeseq'} = { ( # ANSI/DEC specified modes for SM/RM
185 # ANSI Specified Modes
186 '0' => 'IGN', # Error (Ignored)
187 '1' => 'GATM', # guarded-area transfer mode (ignored)
188 '2' => 'KAM', # keyboard action mode (always reset)
189 '3' => 'CRM', # control representation mode (always reset)
190 '4' => 'IRM', # insertion/replacement mode (always reset)
191 '5' => 'SRTM', # status-reporting transfer mode
192 '6' => 'ERM', # erasure mode (always set)
193 '7' => 'VEM', # vertical editing mode (ignored)
194 '10' => 'HEM', # horizontal editing mode
195 '11' => 'PUM', # positioning unit mode
196 '12' => 'SRM', # send/receive mode (echo on/off)
197 '13' => 'FEAM', # format effector action mode
198 '14' => 'FETM', # format effector transfer mode
199 '15' => 'MATM', # multiple area transfer mode
200 '16' => 'TTM', # transfer termination mode
201 '17' => 'SATM', # selected area transfer mode
202 '18' => 'TSM', # tabulation stop mode
203 '19' => 'EBM', # editing boundary mode
204 '20' => 'LNM', # Line Feed / New Line Mode
205 # DEC Private Modes
206 '?0' => 'IGN', # Error (Ignored)
207 '?1' => 'DECCKM', # Cursorkeys application (set); Cursorkeys normal (reset)
208 '?2' => 'DECANM', # ANSI (set); VT52 (reset)
209 '?3' => 'DECCOLM', # 132 columns (set); 80 columns (reset)
210 '?4' => 'DECSCLM', # Jump scroll (set); Smooth scroll (reset)
211 '?5' => 'DECSCNM', # Reverse screen (set); Normal screen (reset)
212 '?6' => 'DECOM', # Sets relative coordinates (set); Sets absolute coordinates (reset)
213 '?7' => 'DECAWM', # Auto Wrap
214 '?8' => 'DECARM', # Auto Repeat
215 '?9' => 'DECINLM', # Interlace
216 '?18' => 'DECPFF', # Send FF to printer after print screen (set); No char after PS (reset)
217 '?19' => 'DECPEX', # Print screen: prints full screen (set); prints scroll region (reset)
218 '?25' => 'DECTCEM', # Cursor on (set); Cursor off (reset)
219 ) };
220  
221 81 $self->{'_funcs'} = { ( # supported character sequences
222 'BS' => \&_code_BS, # backspace one column
223 'CR' => \&_code_CR, # carriage return
224 'DA' => \&_code_DA, # return ESC [ ? 6 c (VT102)
225 'DL' => \&_code_DL, # delete lines
226 'ED' => \&_code_ED, # erase display
227 'EL' => \&_code_EL, # erase line
228 'FF' => \&_code_LF, # line feed
229 'HT' => \&_code_HT, # horizontal tab to next tab stop
230 'IL' => \&_code_IL, # insert blank lines
231 'LF' => \&_code_LF, # line feed
232 'PM' => \&_code_PM, # privacy message (ended by ST)
233 'RI' => \&_code_RI, # reverse line feed
234 'RM' => \&_code_RM, # reset mode
235 'SI' => undef, # activate G0 character set
236 'SM' => \&_code_SM, # set mode
237 'SO' => undef, # activate G1 character set & CR
238 'ST' => undef, # string terminator
239 'VT' => \&_code_LF, # line feed
240 'APC' => \&_code_APC, # application program command (ended by ST)
241 'BEL' => \&_code_BEL, # beep
242 'CAN' => \&_code_CAN, # interrupt escape sequence
243 'CHA' => \&_code_CHA, # move cursor to column in current row
244 'CNL' => \&_code_CNL, # move cursor down and to column 1
245 'CPL' => \&_code_CPL, # move cursor up and to column 1
246 'CRM' => undef, # control representation mode
247 'CSI' => \&_code_CSI, # equivalent to ESC [
248 'CUB' => \&_code_CUB, # move cursor left
249 'CUD' => \&_code_CUD, # move cursor down
250 'CUF' => \&_code_CUF, # move cursor right
251 'CUP' => \&_code_CUP, # move cursor to row, column
252 'CUU' => \&_code_CUU, # move cursor up
253 'DCH' => \&_code_DCH, # delete characters on current line
254 'DCS' => \&_code_DCS, # device control string (ended by ST)
255 'DEL' => \&_code_IGN, # ignored
256 'DSR' => \&_code_DSR, # device status report
257 'EBM' => undef, # editing boundary mode
258 'ECH' => \&_code_ECH, # erase characters on current line
259 'ENQ' => undef, # trigger answerback message
260 'ERM' => undef, # erasure mode
261 'ESC' => \&_code_ESC, # start escape sequence
262 'HEM' => undef, # horizontal editing mode
263 'HPA' => \&_code_CHA, # move cursor to column in current row
264 'HPR' => \&_code_CUF, # move cursor right
265 'HTS' => \&_code_HTS, # set tab stop at current column
266 'HVP' => \&_code_CUP, # move cursor to row, column
267 'ICH' => \&_code_ICH, # insert blank characters
268 'IGN' => \&_code_IGN, # ignored control sequence
269 'IND' => \&_code_LF, # line feed
270 'IRM' => undef, # insert/replace mode
271 'KAM' => undef, # keyboard action mode
272 'LNM' => undef, # line feed / newline mode
273 'LS2' => undef, # invoke G2 charset
274 'LS3' => undef, # invoke G3 charset
275 'NEL' => \&_code_NEL, # newline
276 'NUL' => \&_code_IGN, # ignored
277 'OSC' => \&_code_OSC, # operating system command
278 'PUM' => undef, # positioning unit mode
279 'RIS' => \&_code_RIS, # reset
280 'SGR' => \&_code_SGR, # set graphic rendition
281 'SOS' => undef, # start of string
282 'SRM' => undef, # send/receive mode (echo on/off)
283 'SS2' => undef, # select G2 charset for next char only
284 'SS3' => undef, # select G3 charset for next char only
285 'SUB' => \&_code_CAN, # interrupt escape sequence
286 'TBC' => \&_code_TBC, # clear tab stop (CSI 3 g = clear all stops)
287 'TSM' => undef, # tabulation stop mode
288 'TTM' => undef, # transfer termination mode
289 'VEM' => undef, # vertical editing mode
290 'VPA' => \&_code_VPA, # move to row (current column)
291 'VPR' => \&_code_CUD, # move cursor down
292 'XON' => \&_code_XON, # resume transmission
293 'FEAM' => undef, # format effector action mode
294 'FETM' => undef, # format effector transfer mode
295 'GATM' => undef, # guarded-area transfer mode
296 'LS1R' => undef, # invoke G1 charset as GR
297 'LS2R' => undef, # invoke G2 charset as GR
298 'LS3R' => undef, # invoke G3 charset as GR
299 'MATM' => undef, # multiple area transfer mode
300 'SATM' => undef, # selected area transfer mode
301 'SRTM' => undef, # status-reporting transfer mode
302 'XOFF' => \&_code_XOFF, # stop transmission, ignore characters
303 'CSDFL' => undef, # select default charset (ISO646/8859-1)
304 'CUPRS' => \&_code_CUPRS, # restore cursor position
305 'CUPSV' => \&_code_CUPSV, # save cursor position
306 'DECID' => \&_code_DA, # DEC private ID; return ESC [ ? 6 c (VT102)
307 'DECLL' => undef, # set keyboard LEDs
308 'DECOM' => undef, # relative/absolute coordinate mode
309 'DECRC' => \&_code_DECRC, # restore most recently saved state
310 'DECSC' => \&_code_DECSC, # save state (position, charset, attributes)
311 'G0DFL' => undef, # G0 charset = default mapping (ISO8859-1)
312 'G0GFX' => undef, # G0 charset = VT100 graphics mapping
313 'G0ROM' => undef, # G0 charset = null mapping (straight to ROM)
314 'G0TXT' => undef, # G0 charset = ASCII mapping
315 'G0USR' => undef, # G0 charset = user defined mapping
316 'G1DFL' => undef, # G1 charset = default mapping (ISO8859-1)
317 'G1GFX' => undef, # G1 charset = VT100 graphics mapping
318 'G1ROM' => undef, # G1 charset = null mapping (straight to ROM)
319 'G1TXT' => undef, # G1 charset = ASCII mapping
320 'G1USR' => undef, # G1 charset = user defined mapping
321 'G2DFL' => undef, # G2 charset = default mapping (ISO8859-1)
322 'G2GFX' => undef, # G2 charset = VT100 graphics mapping
323 'G2ROM' => undef, # G2 charset = null mapping (straight to ROM)
324 'G2USR' => undef, # G2 charset = user defined mapping
325 'G3DFL' => undef, # G3 charset = default mapping (ISO8859-1)
326 'G3GFX' => undef, # G3 charset = VT100 graphics mapping
327 'G3ROM' => undef, # G3 charset = null mapping (straight to ROM)
328 'G3USR' => undef, # G3 charset = user defined mapping
329 'CSUTF8' => undef, # select UTF-8 (obsolete)
330 'DECALN' => \&_code_DECALN,# DEC alignment test - fill screen with E's
331 'DECANM' => undef, # ANSI/VT52 mode
332 'DECARM' => undef, # auto repeat mode
333 'DECAWM' => undef, # auto wrap mode
334 'DECCKM' => undef, # cursor key mode
335 'DECPAM' => undef, # set application keypad mode
336 'DECPEX' => undef, # print screen / scrolling region
337 'DECPFF' => undef, # sent FF after print screen, or not
338 'DECPNM' => undef, # set numeric keypad mode
339 'DECCOLM' => undef, # 132 column mode
340 'DECINLM' => undef, # interlace mode
341 'DECSCLM' => undef, # jump/smooth scroll mode
342 'DECSCNM' => undef, # reverse/normal screen mode
343 'DECSTBM' => \&_code_DECSTBM, # set scrolling region
344 'DECTCEM' => \&_code_DECTCEM, # Cursor on (set); Cursor off (reset)
345 ) };
346  
347 81 $self->{'_callbacks'} = { ( # available callbacks
348 'BELL' => undef, # bell character received
349 'CLEAR' => undef, # screen cleared
350 'OUTPUT' => undef, # data to be sent back to originator
351 'ROWCHANGE' => undef, # screen row changed
352 'SCROLL_DOWN' => undef, # text about to move up (par=top row)
353 'SCROLL_UP' => undef, # text about to move down (par=bott.)
354 'UNKNOWN' => undef, # unknown character / sequence
355 'STRING' => undef, # string received
356 'XICONNAME' => undef, # xterm icon name changed
357 'XWINTITLE' => undef, # xterm window title changed
358 'LINEFEED' => undef, # line feed about to be processed
359 ) };
360  
361 81 $self->{'_callbackarg'} = { () }; # stored arguments for callbacks
362  
363 81 $self->{'_decsc'} = [ () ]; # saved state for DECSC/DECRC
364 81 $self->{'_cupsv'} = [ () ]; # saved state for CUPSV/CUPRS
365 81 $self->{'_xon'} = 1; # state is XON (characters accepted)
366  
367 81 $self->{'cols'} = 80; # default: 80 columns
368 81 $self->{'rows'} = 24; # default: 24 rows
369  
370 81 $self->{'_tabstops'} = []; # tab stops
371  
372 $self->{'cols'} = $init{'cols'}
373 81 ▶ if ((defined $init{'cols'}) && ($init{'cols'} > 0));
Branch: 1 branch
BranchTrueFalseTotal
if defined $init{"cols"} and $init{"cols"} > 0 79 2 81
Condition66%2/3
defined $init{"cols"} and $init{"cols"} > 0
!ll&&!rl&&r
0279
MC/DC50%1/2
defined $init{"cols"} and $init{"cols"} > 0
defined $init{"cols"} $init{"cols"} > 0
Truth table66%2/3
A and B
A= defined $init{"cols"}B= $init{"cols"} > 0
ABresult
0X0
100
111
374 $self->{'rows'} = $init{'rows'}
375 81 ▶ if ((defined $init{'rows'}) && ($init{'rows'} > 0));
Branch: 1 branch
BranchTrueFalseTotal
if defined $init{"rows"} and $init{"rows"} > 0 79 2 81
Condition66%2/3
defined $init{"rows"} and $init{"rows"} > 0
!ll&&!rl&&r
0279
MC/DC50%1/2
defined $init{"rows"} and $init{"rows"} > 0
defined $init{"rows"} $init{"rows"} > 0
Truth table66%2/3
A and B
A= defined $init{"rows"}B= $init{"rows"} > 0
ABresult
0X0
100
111
376  
377 81 bless ($self, $class);
378  
379 81 $self->reset ();
380  
381 81 return $self;
382 }
383  
384  
385 # Call a callback function with the given parameters.
386 #
387 823 ▶sub callback_call {
Subroutine callback_call: called CC=2 SCAR=6.9
Pod documented
388 823 my ($self, $callback, $par1, $par2) = (@_);
389 823 my ($func, $arg);
390  
391 823 $func = $self->{'_callbacks'}->{$callback};
392 823 ▶ return if (not defined $func);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $func 819 4 823
393  
394 4 $arg = $self->{'_callbackarg'}->{$callback};
395  
396 4 &{$func} ($self, $callback, $par1, $par2, $arg);
397 }
398  
399  
400 # Set a callback function.
401 #
402 8 ▶sub callback_set {
Subroutine callback_set: called CC=1 SCAR=0.0
Pod documented
403 8 my ($self, $callback, $ref, $arg) = (@_);
404 8 $self->{'_callbacks'}->{$callback} = $ref;
405 8 $self->{'_callbackarg'}->{$callback} = $arg;
406 }
407  
408  
409 # Reset the terminal to "power-on" values.
410 #
411 81 ▶sub reset {
Subroutine reset: called CC=3 SCAR=11.0
Pod documented
412 81 my $self = shift;
413 81 my ($a, $b, $i);
414  
415 81 $self->{'x'} = 1; # default X position: 1
416 81 $self->{'y'} = 1; # default Y position: 1
417  
418 81 $self->{'attr'} = DEFAULT_ATTR_PACKED;
419  
420 81 $self->{'ti'} = ''; # default: blank window title
421 81 $self->{'ic'} = ''; # default: blank icon title
422  
423 81 $self->{'srt'} = 1; # scrolling region top: row 1
424 81 $self->{'srb'} = $self->{'rows'}; # scrolling region bottom
425  
426 81 $self->{'opts'} = {}; # blank all options
427 81 $self->{'opts'}->{'LINEWRAP'} = 0; # line wrapping off
428 81 $self->{'opts'}->{'LFTOCRLF'} = 0; # don't map LF -> CRLF
429 81 $self->{'opts'}->{'IGNOREXOFF'} = 1; # ignore XON/XOFF by default
430  
431 81 $self->{'scrt'} = [ () ]; # blank screen text
432 81 $self->{'scra'} = [ () ]; # blank screen attributes
433  
434 81 $a = "\000" x $self->{'cols'}; # set text to NUL
435 81 $b = $self->{'attr'} x $self->{'cols'}; # set attributes to default
436  
437 81 foreach $i (1 .. $self->{'rows'}) {
438 1452 ($self->{'scrt'}->[$i], $self->{'scra'}->[$i]) = ($a, $b);
439 }
440  
441 81 $self->{'_tabstops'} = []; # reset tab stops
442 81 ▶ for ($i = 1; $i < $self->{'cols'}; $i += 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"cols"}) 342 81 423
443 342 $self->{'_tabstops'}->[$i] = 1;
444 }
445  
446 81 $self->{'_buf'} = undef; # blank the esc-sequence buffer
447 81 $self->{'_inesc'} = ''; # not in any escape sequence
448 81 $self->{'_xon'} = 1; # state is XON (chars accepted)
449  
450 81 $self->{'cursor'} = 1; # turn cursor on
451 }
452  
453  
454 # Resize the terminal.
455 #
456 0 ▶sub resize {
Subroutine resize: not called CC=1 SCAR=6.9
Pod documented
457 0 my $self = shift;
458 0 my $cols = shift;
459 0 my $rows = shift;
460  
461 0 $self->callback_call ('CLEAR', 0, 0);
462  
463 0 $self->{'cols'} = $cols;
464 0 $self->{'rows'} = $rows;
465  
466 0 $self->reset ();
467 }
468  
469  
470 # Return the package version.
471 #
472 1 ▶sub version {
Subroutine version: called CC=1 SCAR=0.0
Pod documented
473 1 return $VERSION;
474 }
475  
476  
477 # Return the current number of columns.
478 #
479 0 ▶sub cols {
Subroutine cols: not called CC=1 SCAR=6.9
Pod documented
480 0 my $self = shift;
481 0 return $self->{'cols'};
482 }
483  
484  
485 # Return the current number of rows.
486 #
487 0 ▶sub rows {
Subroutine rows: not called CC=1 SCAR=6.9
Pod documented
488 0 my $self = shift;
489 0 return $self->{'rows'};
490 }
491  
492  
493 # Return the current terminal size.
494 #
495 79 ▶sub size {
Subroutine size: called CC=1 SCAR=0.0
Pod documented
496 79 my $self = shift;
497 79 return ( $self->{'cols'}, $self->{'rows'} );
498 }
499  
500  
501 # Return the current cursor X co-ordinate.
502 #
503 0 ▶sub x {
Subroutine x: not called CC=1 SCAR=6.9
Pod documented
504 0 my $self = shift;
505 0 return $self->{'x'};
506 }
507  
508  
509 # Return the current cursor Y co-ordinate.
510 #
511 0 ▶sub y {
Subroutine y: not called CC=1 SCAR=6.9
Pod documented
512 0 my $self = shift;
513 0 return $self->{'y'};
514 }
515  
516  
517 # Return the current cursor state (1=on, 0=off).
518 #
519 0 ▶sub cursor {
Subroutine cursor: not called CC=1 SCAR=6.9
Pod documented
520 0 my $self = shift;
521 0 return $self->{'cursor'};
522 }
523  
524  
525 # Return the current xterm title text.
526 #
527 0 ▶sub xtitle {
Subroutine xtitle: not called CC=1 SCAR=6.9
Pod documented
528 0 my $self = shift;
529 0 return $self->{'ti'};
530 }
531  
532  
533 # Return the current xterm icon text.
534 #
535 0 ▶sub xicon {
Subroutine xicon: not called CC=1 SCAR=6.9
Pod documented
536 0 my $self = shift;
537 0 return $self->{'ic'};
538 }
539  
540  
541 # Return the current terminal status.
542 #
543 0 ▶sub status {
Subroutine status: not called CC=1 SCAR=6.9
Pod documented
544 0 my $self = shift;
545  
546 return (
547 $self->{'x'}, # cursor X position
548 $self->{'y'}, # cursor Y position
549 $self->{'attr'}, # packed attributes
550 $self->{'ti'}, # xterm title text
551 0 $self->{'ic'} # xterm icon text
552 );
553 }
554  
555  
556 # Process the given string, updating the terminal object and calling any
557 # necessary callbacks on the way.
558 #
559 77 ▶sub process {
Subroutine process: called CC=8 SCAR=20.9
Pod documented
560 77 my $self = shift;
561 77 my ($string) = @_;
562  
563 77 ▶ return if (not defined $string);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 77 77
564  
565 77 ▶ while (length $string > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $string > 0) 1914 77 1991
566 1914 ▶ if (defined $self->{'_buf'}) { # in escape sequence
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_buf'}) { } 835 1079 1914
567 835 ▶ if ($string =~ s/^(.)//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^(.)//s) 835 0 835
568 835 my $ch = $1;
569 835 ▶ if ($ch =~ /[\x00-\x1F]/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /[\x00-\x1F]/s) { } 3 832 835
570 3 $self->_process_ctl ($ch);
571 } else {
572 832 $self->{'_buf'} .= $ch;
573 832 $self->_process_escseq ();
574 }
575 }
576 } else { # not in escape sequence
577 1079 ▶ if ($string =~
Branch: 2 branches
BranchTrueFalseTotal
if ($string =~ s/^([^\x00-\x1F\x7F\x9B]+)//s) { } 410 669 1079
elsif ($string =~ s/^(.)//s) { } 669 0 669
578 s/^([^\x00-\x1F\x7F\x9B]+)//s) {
579 410 $self->_process_text ($1);
580 } elsif ($string =~ s/^(.)//s) {
581 669 $self->_process_ctl ($1);
582 }
583 }
584 }
585 }
586  
587  
588 # Return the current value of the given option, or undef if it doesn't exist.
589 #
590 0 ▶sub option_read {
Subroutine option_read: not called CC=2 SCAR=17.9
Pod documented
591 0 my $self = shift;
592 0 my ($option) = @_;
593  
594 0 ▶ return undef if (not defined $option);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $option 0 0 0
595 0 return $self->{'opts'}->{$option};
596 }
597  
598  
599 # Set the value of the given option to the given value, returning the old
600 # value or undef if an invalid option was given.
601 #
602 4 ▶sub option_set {
Subroutine option_set: called CC=4 SCAR=14.2
Pod documented
603 4 my $self = shift;
604 4 my ($option, $value) = @_;
605 4 my $prev;
606  
607 4 ▶ return undef if (not defined $option);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $option 0 4 4
608 4 ▶ return undef if (not defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 4 4
609 4 ▶ return undef if (not defined $self->{'opts'}->{$option});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"opts"}{$option} 0 4 4
610  
611 4 $prev = $self->{'opts'}->{$option};
612 4 $self->{'opts'}->{$option} = $value;
613 4 return $prev;
614 }
615  
616  
617 # Return the attributes of the given row, or undef if out of range.
618 #
619 15 ▶sub row_attr {
Subroutine row_attr: called CC=5 SCAR=17.8
Pod documented
620 15 my $self = shift;
621 15 my ($row, $startcol, $endcol) = @_;
622 15 my ($data);
623  
624 15 ▶ return undef if ($row < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $row < 1 0 15 15
625 15 ▶ return undef if ($row > $self->{'rows'});
Branch: 1 branch
BranchTrueFalseTotal
if $row > $self->{"rows"} 0 15 15
626  
627 15 $data = $self->{'scra'}->[$row];
628  
629 15 ▶ if (defined $startcol && defined $endcol) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $startcol and defined $endcol) 0 15 15
Condition33%1/3
defined $startcol and defined $endcol
!ll&&!rl&&r
1500
MC/DC0%0/2
defined $startcol and defined $endcol
defined $startcol defined $endcol
Truth table33%1/3
A and B
A= defined $startcolB= defined $endcol
ABresult
0X0
100
111
630 0 $data = substr (
631 $data,
632 ($startcol - 1) * 2,
633 (($endcol - $startcol) + 1) * 2
634 );
635 }
636  
637 15 return $data;
638 }
639  
640  
641 # Return the textual contents of the given row, or undef if out of range.
642 #
643 212 ▶sub row_text {
Subroutine row_text: called CC=5 SCAR=17.8
Pod documented
644 212 my $self = shift;
645 212 my ($row, $startcol, $endcol) = @_;
646 212 my $text;
647  
648 212 ▶ return undef if ($row < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $row < 1 0 212 212
649 212 ▶ return undef if ($row > $self->{'rows'});
Branch: 1 branch
BranchTrueFalseTotal
if $row > $self->{"rows"} 0 212 212
650  
651 212 $text = $self->{'scrt'}->[$row];
652  
653 212 ▶ if (defined $startcol && defined $endcol) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $startcol and defined $endcol) 0 212 212
Condition33%1/3
defined $startcol and defined $endcol
!ll&&!rl&&r
21200
MC/DC0%0/2
defined $startcol and defined $endcol
defined $startcol defined $endcol
Truth table33%1/3
A and B
A= defined $startcolB= defined $endcol
ABresult
0X0
100
111
654 0 $text = substr (
655 $text,
656 $startcol - 1,
657 ($endcol - $startcol) + 1
658 );
659 }
660  
661 212 return $text;
662 }
663  
664  
665 # Return the textual contents of the given row, or undef if out of range,
666 # with unused characters represented as a space instead of \0.
667 #
668 0 ▶sub row_plaintext {
Subroutine row_plaintext: not called CC=5 SCAR=34.0
Pod documented
669 0 my $self = shift;
670 0 my ($row, $startcol, $endcol) = @_;
671 0 my $text;
672  
673 0 ▶ return undef if ($row < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $row < 1 0 0 0
674 0 ▶ return undef if ($row > $self->{'rows'});
Branch: 1 branch
BranchTrueFalseTotal
if $row > $self->{"rows"} 0 0 0
675  
676 0 $text = $self->{'scrt'}->[$row];
677 0 $text =~ s/\0/ /g;
678  
679 0 ▶ if (defined $startcol && defined $endcol) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $startcol and defined $endcol) 0 0 0
Condition0%0/3
defined $startcol and defined $endcol
!ll&&!rl&&r
000
MC/DC0%0/2
defined $startcol and defined $endcol
defined $startcol defined $endcol
Truth table0%0/3
A and B
A= defined $startcolB= defined $endcol
ABresult
0X0
100
111
680 0 $text = substr (
681 $text,
682 $startcol - 1,
683 ($endcol - $startcol) + 1
684 );
685 }
686  
687 0 return $text;
688 }
689  
690  
691 # Return a set of SGR escape sequences that will change colours and
692 # attributes from "source" to "dest" (packed attributes).
693 #
694 0 ▶sub sgr_change {
Subroutine sgr_change: not called CC=22 SCAR=62.3
Pod documented
695 0 ▶ shift if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
696 0 my ($source, $dest) = @_;
697 0 my ($out, %off, %on) = ('', (), ());
698  
699 0 ▶ $source = DEFAULT_ATTR_PACKED if (not defined $source);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $source 0 0 0
700 0 ▶ $dest = DEFAULT_ATTR_PACKED if (not defined $dest);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dest 0 0 0
701  
702 0 ▶ return '' if ($source eq $dest);
Branch: 1 branch
BranchTrueFalseTotal
if $source eq $dest 0 0 0
703 0 ▶ return "\e[m" if ($dest eq DEFAULT_ATTR_PACKED);
Branch: 1 branch
BranchTrueFalseTotal
if $dest eq "\a\0" 0 0 0
704  
705 0 my ($sfg, $sbg, $sbo, $sfa, $sst, $sul, $sbl, $srv) = attr_unpack ($source);
706 0 my ($dfg, $dbg, $dbo, $dfa, $dst, $dul, $dbl, $drv) = attr_unpack ($dest);
707  
708 0 ▶ if (($sfg != $dfg) || ($sbg != $dbg)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sfg != $dfg or $sbg != $dbg) 0 0 0
Condition0%0/3
$sfg != $dfg or $sbg != $dbg
l!l&&r!l&&!r
000
MC/DC0%0/2
$sfg != $dfg or $sbg != $dbg
$sfg != $dfg $sbg != $dbg
Truth table0%0/3
A or B
A= $sfg != $dfgB= $sbg != $dbg
ABresult
1X1
011
000
709 0 $out .= sprintf ("\e[m\e[3%d;4%dm", $dfg, $dbg);
710 0 ($sbo, $sfa, $sst, $sul, $sbl, $srv) = (0, 0, 0, 0, 0, 0);
711 }
712  
713 0 ▶ if (($sbo > $dbo) || ($sfa > $dfa)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sbo > $dbo or $sfa > $dfa) 0 0 0
Condition0%0/3
$sbo > $dbo or $sfa > $dfa
l!l&&r!l&&!r
000
MC/DC0%0/2
$sbo > $dbo or $sfa > $dfa
$sbo > $dbo $sfa > $dfa
Truth table0%0/3
A or B
A= $sbo > $dboB= $sfa > $dfa
ABresult
1X1
011
000
714 0 $off{'22'} = 1;
715 0 ($sbo, $sfa) = (0, 0);
716 }
717 0 ▶ $off{'24'} = 1 if ($sul > $dul);
Branch: 1 branch
BranchTrueFalseTotal
if $sul > $dul 0 0 0
718 0 ▶ $off{'25'} = 1 if ($sbl > $dbl);
Branch: 1 branch
BranchTrueFalseTotal
if $sbl > $dbl 0 0 0
719 0 ▶ $off{'27'} = 1 if ($srv > $drv);
Branch: 1 branch
BranchTrueFalseTotal
if $srv > $drv 0 0 0
720  
721 0 ▶ if (scalar keys %off > 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar keys %off > 2) { } 0 0 0
elsif (scalar keys %off > 0) { } 0 0 0
722 0 $out .= "\e[m";
723 0 ($sbo, $sfa, $sst, $sul, $sbl, $srv) = (0, 0, 0, 0, 0, 0);
724 } elsif (scalar keys %off > 0) {
725 0 $out .= "\e[" . join (';', keys %off) . "m";
726 }
727  
728 0 ▶ $on{'1'} = 1 if ($dbo > $sbo);
Branch: 1 branch
BranchTrueFalseTotal
if $dbo > $sbo 0 0 0
729 0 ▶ $on{'2'} = 1 if (($dfa > $sfa) && !($dbo > $sbo));
Branch: 1 branch
BranchTrueFalseTotal
if $dfa > $sfa and not $dbo > $sbo 0 0 0
Condition0%0/3
$dfa > $sfa and not $dbo > $sbo
!ll&&!rl&&r
000
MC/DC0%0/2
$dfa > $sfa and not $dbo > $sbo
$dfa > $sfa not $dbo > $sbo
Truth table0%0/3
A and not(B)
A= $dfa > $sfaB= not $dbo > $sbo
ABresult
0X0
100
111
730 0 ▶ $on{'4'} = 1 if ($dul > $sul);
Branch: 1 branch
BranchTrueFalseTotal
if $dul > $sul 0 0 0
731 0 ▶ $on{'5'} = 1 if ($dbl > $sbl);
Branch: 1 branch
BranchTrueFalseTotal
if $dbl > $sbl 0 0 0
732 0 ▶ $on{'7'} = 1 if ($drv > $srv);
Branch: 1 branch
BranchTrueFalseTotal
if $drv > $srv 0 0 0
733  
734 0 ▶ $out .= "\e[" . join (';', keys %on) . "m" if (scalar keys %on > 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %on > 0 0 0 0
735  
736 0 return $out;
737 }
738  
739  
740 # Return the textual contents of the given row, or undef if out of range,
741 # with unused characters represented as a space instead of \0, and any
742 # colour or attribute changes expressed by the relevant SGR escape
743 # sequences.
744 #
745 0 ▶sub row_sgrtext {
Subroutine row_sgrtext: not called CC=12 SCAR=50.5
Pod documented
746 0 my ($self, $row, $startcol, $endcol) = @_;
747 0 my ($row_text, $row_attr, $text, $char, $attr_cur, $attr_next);
748  
749 0 ▶ return undef if ($row < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $row < 1 0 0 0
750 0 ▶ return undef if ($row > $self->{'rows'});
Branch: 1 branch
BranchTrueFalseTotal
if $row > $self->{"rows"} 0 0 0
751  
752 0 ▶ $startcol = 1 if (not defined $startcol);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $startcol 0 0 0
753 0 ▶ $endcol = $self->{'cols'} if (not defined $endcol);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $endcol 0 0 0
754  
755 0 ▶ return undef if (($startcol < 1) || ($startcol > $self->{'cols'}));
Branch: 1 branch
BranchTrueFalseTotal
if $startcol < 1 or $startcol > $self->{"cols"} 0 0 0
Condition0%0/3
$startcol < 1 or $startcol > $self->{"cols"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$startcol < 1 or $startcol > $self->{"cols"}
$startcol < 1 $startcol > $self->{"cols"}
Truth table0%0/3
A or B
A= $startcol < 1B= $startcol > $self->{"cols"}
ABresult
1X1
011
000
756 0 ▶ return undef if (($endcol < 1) || ($endcol > $self->{'cols'}));
Branch: 1 branch
BranchTrueFalseTotal
if $endcol < 1 or $endcol > $self->{"cols"} 0 0 0
Condition0%0/3
$endcol < 1 or $endcol > $self->{"cols"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$endcol < 1 or $endcol > $self->{"cols"}
$endcol < 1 $endcol > $self->{"cols"}
Truth table0%0/3
A or B
A= $endcol < 1B= $endcol > $self->{"cols"}
ABresult
1X1
011
000
757 0 ▶ return undef if ($endcol < $startcol);
Branch: 1 branch
BranchTrueFalseTotal
if $endcol < $startcol 0 0 0
758  
759 0 $row_text = $self->{'scrt'}->[$row];
760 0 $row_attr = $self->{'scra'}->[$row];
761  
762 0 $text = '';
763 0 $attr_cur = DEFAULT_ATTR_PACKED;
764  
765 0 ▶ for (; $startcol <= $endcol; $startcol++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($startcol <= $endcol) 0 0 0
766 0 $char = substr ($row_text, $startcol - 1, 1);
767 0 $char =~ s/\0/ /g;
768 0 ▶ $char = ' ' if ($char !~ /./);
Branch: 1 branch
BranchTrueFalseTotal
unless $char =~ /./ 0 0 0
769 0 $attr_next = substr ($row_attr, ($startcol - 1) * 2, 2);
770 0 $text .= $self->sgr_change ($attr_cur, $attr_next) . $char;
771 0 $attr_cur = $attr_next;
772 }
773  
774 0 $attr_next = DEFAULT_ATTR_PACKED;
775 0 $text .= $self->sgr_change ($attr_cur, $attr_next);
776  
777 0 return $text;
778 }
779  
780  
781 # Process a string of plain text, with no special characters in it.
782 #
783 410 ▶sub _process_text {
Subroutine _process_text: called CC=8 SCAR=20.8
784 410 my $self = shift;
785 410 my ($text) = @_;
786 410 my ($width, $segment);
787  
788 410 ▶ return if ($self->{'_xon'} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_xon"} == 0 2 408 410
789  
790 408 $width = ($self->{'cols'} + 1) - $self->{'x'};
791  
792 408 ▶ if ($self->{'opts'}->{'LINEWRAP'} == 0) { # no line wrap - truncate
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"opts"}{"LINEWRAP"} == 0) 407 1 408
793 407 ▶ return if ($width < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $width < 1 0 407 407
794 407 $text = substr ($text, 0, $width);
795 substr (
796 407 $self->{'scrt'}->[$self->{'y'}], $self->{'x'} - 1,
797 length $text
798 ) = $text;
799 substr (
800 $self->{'scra'}->[$self->{'y'}], 2 * ($self->{'x'} - 1),
801 2 * (length $text)
802 407 ) = $self->{'attr'} x (length $text);
803 407 $self->{'x'} += length $text;
804 $self->{'x'} = $self->{'cols'}
805 407 ▶ if ($self->{'x'} > $self->{'cols'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} > $self->{"cols"} 234 173 407
806 407 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
807 407 return;
808 }
809  
810 1 ▶ while (length $text > 0) { # line wrapping enabled
Branch: 1 branch
BranchTrueFalseTotal
if (length $text > 0) 5 1 6
811 5 ▶ if ($width > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($width > 0) { } 3 2 5
812 3 $segment = substr ($text, 0, $width, '');
813 substr (
814 3 $self->{'scrt'}->[$self->{'y'}], $self->{'x'} - 1,
815 length $segment
816 ) = $segment;
817 substr (
818 $self->{'scra'}->[$self->{'y'}],
819 2 * ($self->{'x'} - 1),
820 2 * (length $segment)
821 3 ) = $self->{'attr'} x (length $segment);
822 3 $self->{'x'} += length $segment;
823 } else {
824 2 ▶ if ($self->{'x'} > $self->{'cols'}) { # wrap to next line
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"x"} > $self->{"cols"}) 2 0 2
825 2 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
826 2 $self->callback_call ('LINEFEED', $self->{'y'}, 0);
827 2 $self->{'x'} = 1;
828 2 $self->_move_down;
829 }
830 }
831 5 $width = ($self->{'cols'} + 1) - $self->{'x'};
832 }
833  
834 1 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
835 }
836  
837  
838 # Process a control character.
839 #
840 672 ▶sub _process_ctl {
Subroutine _process_ctl: called CC=5 SCAR=16.3
841 672 my $self = shift;
842 672 my $ctl = shift;
843 672 my ($name, $func);
844  
845 672 $name = $self->{'_ctlseq'}->{$ctl};
846 672 ▶ return if (not defined $name); # ignore unknown characters
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 672 672
847  
848 # If we're in XOFF mode, ignore anything other than XON
849 #
850 672 ▶ if ($self->{'_xon'} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_xon"} == 0) 2 670 672
851 2 ▶ return if ($name ne 'XON');
Branch: 1 branch
BranchTrueFalseTotal
if $name ne "XON" 1 1 2
852 }
853  
854 671 $func = $self->{'_funcs'}->{$name};
855 671 ▶ if (not defined $func) { # do nothing if unsupported
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $func) { } 0 671 671
856 0 $self->callback_call ('UNKNOWN', $name, $ctl);
857 } else { # call handler function
858 671 &{$func} ($self, $name);
859 }
860 }
861  
862  
863 # Check the escape-sequence buffer, and process it if necessary.
864 #
865 835 ▶sub _process_escseq {
Subroutine _process_escseq: called CC=23 SCAR=38.2
866 835 my $self = shift;
867 835 my ($prefix, $suffix, $func, $name, $dat);
868 835 my @params;
869  
870 835 ▶ return if (not defined $self->{'_buf'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_buf"} 0 835 835
871 835 ▶ return if (length $self->{'_buf'} < 1);
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"_buf"} < 1 0 835 835
872 835 ▶ return if ($self->{'_xon'} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_xon"} == 0 0 835 835
873  
874 835 ▶ if ($self->{'_inesc'} eq 'OSC') { # in OSC sequence
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'_inesc'} eq 'OSC') { } 32 803 835
elsif ($self->{'_inesc'} eq 'CSI') { } 534 269 803
elsif ($self->{'_inesc'} =~ /_ST$/) { } 13 256 269
875 32 ▶ if (
Branch: 5 branches
BranchTrueFalseTotal
if ($self->{'_buf'} =~ /^0;([^\007]*)(?:\007|\033\\)/) { } 0 32 32
elsif ($self->{'_buf'} =~ /^1;([^\007]*)(?:\007|\033\\)/) { } 1 31 32
elsif ($self->{'_buf'} =~ /^2;([^\007]*)(?:\007|\033\\)/) { } 1 30 31
elsif ($self->{'_buf'} =~ /^\d+;([^\007]*)(?:\007|\033\\)/) { } 0 30 30
elsif (length $self->{'_buf'} > 1024) { } 0 30 30
876 $self->{'_buf'} =~ /^0;([^\007]*)(?:\007|\033\\)/
877 ) { # icon & window
878 0 $dat = $1;
879 0 $self->callback_call ('XWINTITLE', $dat, 0);
880 0 $self->callback_call ('XICONNAME', $dat, 0);
881 0 $self->{'ic'} = $dat;
882 0 $self->{'ti'} = $dat;
883 0 $self->{'_buf'} = undef;
884 0 $self->{'_inesc'} = '';
885 } elsif (
886 $self->{'_buf'} =~ /^1;([^\007]*)(?:\007|\033\\)/
887 ) { # set icon name
888 1 $dat = $1;
889 1 $self->callback_call ('XICONNAME', $dat, 0);
890 1 $self->{'ic'} = $dat;
891 1 $self->{'_buf'} = undef;
892 1 $self->{'_inesc'} = '';
893 } elsif (
894 $self->{'_buf'} =~ /^2;([^\007]*)(?:\007|\033\\)/
895 ) { # set window title
896 1 $dat = $1;
897 1 $self->callback_call ('XWINTITLE', $dat, 0);
898 1 $self->{'ti'} = $dat;
899 1 $self->{'_buf'} = undef;
900 1 $self->{'_inesc'} = '';
901 } elsif (
902 $self->{'_buf'} =~ /^\d+;([^\007]*)(?:\007|\033\\)/
903 ) { # unknown OSC
904 $self->callback_call (
905 0 'UNKNOWN', 'OSC', "\033]" . $self->{'_buf'}
906 );
907 0 $self->{'_buf'} = undef;
908 0 $self->{'_inesc'} = '';
909 } elsif (
910 length $self->{'_buf'} > 1024
911 ) { # OSC too long
912 $self->callback_call (
913 0 'UNKNOWN', 'OSC', "\033]" . $self->{'_buf'}
914 );
915 0 $self->{'_buf'} = undef;
916 0 $self->{'_inesc'} = '';
917 }
918 } elsif ($self->{'_inesc'} eq 'CSI') { # in CSI sequence
919 534 foreach $suffix (keys %{$self->{'_csiseq'}}) {
920 13126 ▶ next if (length $self->{'_buf'} < length $suffix);
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"_buf"} < length $suffix 0 13126 13126
921 next if (
922 substr (
923 $self->{'_buf'},
924 13126 ▶ (length $self->{'_buf'}) - (length $suffix),
Branch: 1 branch
BranchTrueFalseTotal
if substr($self->{"_buf"}, length($self->{"_buf"}) - length($suffix), length $suffix) ne $suffix 12899 227 13126
925 length $suffix
926 ) ne $suffix
927 );
928 $self->{'_buf'} = substr (
929 $self->{'_buf'},
930 0,
931 227 (length $self->{'_buf'}) - (length $suffix)
932 );
933 227 $name = $self->{'_csiseq'}->{$suffix};
934 227 $func = $self->{'_funcs'}->{$name};
935 227 ▶ if (not defined $func) { # unsupported sequence
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $func) 0 227 227
936 $self->callback_call (
937 'UNKNOWN',
938 $name,
939 0 "\033[" . $self->{'_buf'} . $suffix
940 );
941 0 $self->{'_buf'} = undef;
942 0 $self->{'_inesc'} = '';
943 0 return;
944 }
945 227 @params = split (';', $self->{'_buf'});
946 227 $self->{'_buf'} = undef;
947 227 $self->{'_inesc'} = '';
948 227 &{$func} ($self, @params);
949 227 return;
950 }
951 307 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"_buf"} > 64) 0 307 307
952 length $self->{'_buf'} > 64
953 ) { # abort CSI sequence if too long
954 $self->callback_call (
955 0 'UNKNOWN', 'CSI', "\033[" . $self->{'_buf'}
956 );
957 0 $self->{'_buf'} = undef;
958 0 $self->{'_inesc'} = '';
959 }
960 } elsif ($self->{'_inesc'} =~ /_ST$/) {
961 13 ▶ if ($self->{'_buf'} =~ s/\033\\$//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'_buf'} =~ s/\033\\$//) { } 1 12 13
elsif (length $self->{'_buf'} > 1024) { } 0 12 12
962 1 $self->{'_inesc'} =~ s/_ST$//;
963 $self->callback_call (
964 1 'STRING', $self->{'_inesc'}, $self->{'_buf'}
965 );
966 1 $self->{'_buf'} = undef;
967 1 $self->{'_inesc'} = '';
968 1 $self->{'_buf'} = undef;
969 1 $self->{'_inesc'} = '';
970 } elsif (
971 length $self->{'_buf'} > 1024
972 ) { # string too long
973 0 $self->{'_inesc'} =~ s/_ST$//;
974 $self->callback_call (
975 0 'STRING', $self->{'_inesc'}, $self->{'_buf'}
976 );
977 0 $self->{'_buf'} = undef;
978 0 $self->{'_inesc'} = '';
979 }
980 } else { # in ESC sequence
981 256 foreach $prefix (
982 256 keys %{$self->{'_escseq'}}
983 ) {
984 next if (
985 6758 ▶ substr ($self->{'_buf'}, 0, length $prefix)
Branch: 1 branch
BranchTrueFalseTotal
if substr($self->{"_buf"}, 0, length $prefix) ne $prefix 6503 255 6758
986 ne $prefix
987 );
988 255 $name = $self->{'_escseq'}->{$prefix};
989 255 $func = $self->{'_funcs'}->{$name};
990 255 ▶ if (not defined $func) { # unsupported sequence
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $func) 0 255 255
991 $self->callback_call (
992 'UNKNOWN',
993 $name,
994 0 "\033" . $self->{'_buf'}
995 );
996 0 $self->{'_buf'} = undef;
997 0 $self->{'_inesc'} = '';
998 0 return;
999 }
1000 255 $self->{'_buf'} = undef;
1001 255 $self->{'_inesc'} = '';
1002 255 &{$func} ($self);
1003 255 return;
1004 }
1005 1 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"_buf"} > 8) 0 1 1
1006 length $self->{'_buf'} > 8
1007 ) { # abort ESC sequence if too long
1008 $self->callback_call (
1009 'UNKNOWN',
1010 'ESC',
1011 0 "\033" . $self->{'_buf'}
1012 );
1013 0 $self->{'_buf'} = undef;
1014 0 $self->{'_inesc'} = '';
1015 }
1016 }
1017 }
1018  
1019  
1020 # Scroll the scrolling region up such that the text in the scrolling region
1021 # moves down, by the given number of lines.
1022 #
1023 7 ▶sub _scroll_up {
Subroutine _scroll_up: called CC=5 SCAR=16.1
1024 7 my $self = shift;
1025 7 my $lines = shift;
1026 7 my ($attr, $a, $b, $i);
1027  
1028 7 ▶ return if ($lines < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $lines < 1 0 7 7
1029  
1030 7 $self->callback_call ('SCROLL_UP', $self->{'srb'}, $lines);
1031  
1032 7 ▶ for ($i = $self->{'srb'}; $i >= ($self->{'srt'} + $lines); $i --) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $self->{"srt"} + $lines) 8 7 15
1033 8 $self->{'scrt'}->[$i] = $self->{'scrt'}->[$i - $lines];
1034 8 $self->{'scra'}->[$i] = $self->{'scra'}->[$i - $lines];
1035 }
1036  
1037 7 $a = "\000" x $self->{'cols'}; # set text to NUL
1038 7 $attr = DEFAULT_ATTR_PACKED;
1039 7 $b = $attr x $self->{'cols'}; # set attributes to default
1040  
1041 7 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $self->{"srb"} and $i < $self->{"srt"} + $lines) 14 7 21
Condition100%3/3
$i <= $self->{"srb"} and $i < $self->{"srt"} + $lines
!ll&&!rl&&r
3414
MC/DC100%2/2
$i <= $self->{"srb"} and $i < $self->{"srt"} + $lines
$i <= $self->{"srb"} $i < $self->{"srt"} + $lines
Truth table100%3/3
A and B
A= $i <= $self->{"srb"}B= $i < $self->{"srt"} + $lines
ABresult
0X0
100
111
1042 $i = $self->{'srt'};
1043 ($i <= $self->{'srb'}) && ($i < ($self->{'srt'} + $lines));
1044 $i ++
1045 ) {
1046 14 $self->{'scrt'}->[$i] = $a; # blank new lines
1047 14 $self->{'scra'}->[$i] = $b; # wipe attributes of new lines
1048 }
1049 }
1050  
1051  
1052 # Scroll the scrolling region down such that the text in the scrolling region
1053 # moves up, by the given number of lines.
1054 #
1055 9 ▶sub _scroll_down {
Subroutine _scroll_down: called CC=4 SCAR=13.9
1056 9 my $self = shift;
1057 9 my $lines = shift;
1058 9 my ($a, $b, $i, $attr);
1059  
1060 9 $self->callback_call ('SCROLL_DOWN', $self->{'srt'}, $lines);
1061  
1062 9 ▶ for ($i = $self->{'srt'}; $i <= ($self->{'srb'} - $lines); $i ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $self->{"srb"} - $lines) 14 9 23
1063 14 $self->{'scrt'}->[$i] = $self->{'scrt'}->[$i + $lines];
1064 14 $self->{'scra'}->[$i] = $self->{'scra'}->[$i + $lines];
1065 }
1066  
1067 9 $a = "\000" x $self->{'cols'}; # set text to NUL
1068 9 $attr = DEFAULT_ATTR_PACKED;
1069 9 $b = $attr x $self->{'cols'}; # set attributes to default
1070  
1071 9 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $self->{"srt"} and $i > $self->{"srb"} - $lines) 16 9 25
Condition100%3/3
$i >= $self->{"srt"} and $i > $self->{"srb"} - $lines
!ll&&!rl&&r
3616
MC/DC100%2/2
$i >= $self->{"srt"} and $i > $self->{"srb"} - $lines
$i >= $self->{"srt"} $i > $self->{"srb"} - $lines
Truth table100%3/3
A and B
A= $i >= $self->{"srt"}B= $i > $self->{"srb"} - $lines
ABresult
0X0
100
111
1072 $i = $self->{'srb'};
1073 ($i >= $self->{'srt'}) && ($i > ($self->{'srb'} - $lines));
1074 $i --
1075 ) {
1076 16 $self->{'scrt'}->[$i] = $a; # blank new lines
1077 16 $self->{'scra'}->[$i] = $b; # wipe attributes of new lines
1078 }
1079 }
1080  
1081  
1082 # Move the cursor up the given number of lines, without triggering a GOTO callback, taking scrolling into account.
1083 #
1084 11 ▶sub _move_up {
Subroutine _move_up: called CC=4 SCAR=13.9
1085 11 my $self = shift;
1086 11 my $num = shift;
1087 11 ▶ $num = 1 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 3 8 11
1088 11 ▶ $num = 1 if ($num < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $num < 1 0 11 11
1089 11 $self->{'y'} -= $num;
1090 11 ▶ return if ($self->{'y'} >= $self->{'srt'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"y"} >= $self->{"srt"} 4 7 11
1091 7 $self->_scroll_up ($self->{'srt'} - $self->{'y'}); # scroll
1092 7 $self->{'y'} = $self->{'srt'};
1093 }
1094  
1095  
1096 # Move the cursor down the given number of lines, without triggering a GOTO
1097 # callback, taking scrolling into account.
1098 #
1099 195 ▶sub _move_down {
Subroutine _move_down: called CC=4 SCAR=13.9
1100 195 my $self = shift;
1101 195 my $num = shift;
1102 195 ▶ $num = 1 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 186 9 195
1103 195 ▶ $num = 1 if ($num < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $num < 1 0 195 195
1104 195 $self->{'y'} += $num;
1105 195 ▶ return if ($self->{'y'} <= $self->{'srb'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"y"} <= $self->{"srb"} 186 9 195
1106 9 $self->_scroll_down ($self->{'y'} - $self->{'srb'}); # scroll
1107 9 $self->{'y'} = $self->{'srb'};
1108 }
1109  
1110  
1111 0 ▶sub _code_BEL { # beep
Subroutine _code_BEL: not called CC=3 SCAR=24.8
1112 0 my $self = shift;
1113 0 ▶ if ((defined $self->{'_buf'}) && ($self->{'_inesc'} eq 'OSC')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_buf'} and $self->{'_inesc'} eq 'OSC') { } 0 0 0
Condition0%0/3
defined $self->{"_buf"} and $self->{"_inesc"} eq "OSC"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"_buf"} and $self->{"_inesc"} eq "OSC"
defined $self->{"_buf"} $self->{"_inesc"} eq "OSC"
Truth table0%0/3
A and B
A= defined $self->{"_buf"}B= $self->{"_inesc"} eq "OSC"
ABresult
0X0
100
111
1114 # CSI OSC can be terminated with a BEL
1115 0 $self->{'_buf'} .= "\007";
1116 0 $self->_process_escseq ();
1117 } else {
1118 0 $self->callback_call ('BELL', 0, 0);
1119 }
1120 }
1121  
1122 0 ▶sub _code_BS { # move left 1 character
Subroutine _code_BS: not called CC=2 SCAR=17.9
1123 0 my $self = shift;
1124 0 $self->{'x'} --;
1125 0 ▶ $self->{'x'} = 1 if ($self->{'x'} < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} < 1 0 0 0
1126 }
1127  
1128 0 ▶sub _code_CAN { # cancel escape sequence
Subroutine _code_CAN: not called CC=1 SCAR=6.9
1129 0 my $self = shift;
1130 0 $self->{'_inesc'} = '';
1131 0 $self->{'_buf'} = undef;
1132 }
1133  
1134 4 ▶sub _code_TBC { # clear tab stop (CSI 3 g = clear all stops)
Subroutine _code_TBC: called CC=3 SCAR=11.0
1135 4 my $self = shift;
1136 4 my $num = shift;
1137 4 ▶ if ((defined $num) && ($num eq '3')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $num and $num eq '3') { } 3 1 4
Condition66%2/3
defined $num and $num eq 3
!ll&&!rl&&r
103
MC/DC50%1/2
defined $num and $num eq 3
defined $num $num eq 3
Truth table66%2/3
A and B
A= defined $numB= $num eq 3
ABresult
0X0
100
111
1138 3 $self->{'_tabstops'} = [];
1139 } else {
1140 1 $self->{'_tabstops'}->[$self->{'x'}] = undef;
1141 }
1142 }
1143  
1144 18 ▶sub _code_CHA { # move to column in current row
Subroutine _code_CHA: called CC=5 SCAR=16.2
1145 18 my $self = shift;
1146 18 my $col = shift;
1147 18 ▶ $col = 1 if (not defined $col);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $col 1 17 18
1148 18 ▶ return if ($self->{'x'} == $col);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} == $col 0 18 18
1149 18 $self->callback_call ('GOTO', $col, $self->{'y'});
1150 18 $self->{'x'} = $col;
1151 18 ▶ $self->{'x'} = 1 if ($self->{'x'} < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} < 1 0 18 18
1152 18 ▶ $self->{'x'} = $self->{'cols'} if ($self->{'x'} > $self->{'cols'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} > $self->{"cols"} 1 17 18
1153 }
1154  
1155 6 ▶sub _code_CNL { # move cursor down and to column 1
Subroutine _code_CNL: called CC=2 SCAR=6.9
1156 6 my $self = shift;
1157 6 my $num = shift;
1158 6 ▶ $num = 1 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 1 5 6
1159 6 $self->callback_call ('GOTO', 1, $self->{'y'} + $num);
1160 6 $self->{'x'} = 1;
1161 6 $self->_move_down ($num);
1162 }
1163  
1164 5 ▶sub _code_CPL { # move cursor up and to column 1
Subroutine _code_CPL: called CC=2 SCAR=6.9
1165 5 my $self = shift;
1166 5 my $num = shift;
1167 5 ▶ $num = 1 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 1 4 5
1168 5 $self->callback_call ('GOTO', $self->{'x'}, $self->{'y'} - $num);
1169 5 $self->{'x'} = 1;
1170 5 $self->_move_up ($num);
1171 }
1172  
1173 181 ▶sub _code_CR { # carriage return
Subroutine _code_CR: called CC=1 SCAR=0.0
1174 181 my $self = shift;
1175 181 $self->{'x'} = 1;
1176 }
1177  
1178 227 ▶sub _code_CSI { # ESC [
Subroutine _code_CSI: called CC=1 SCAR=0.0
1179 227 my $self = shift;
1180 227 $self->{'_buf'} = ''; # restart ESC buffering
1181 227 $self->{'_inesc'} = 'CSI'; # ...for a CSI, not an ESC
1182 }
1183  
1184 1 ▶sub _code_CUB { # move cursor left
Subroutine _code_CUB: called CC=4 SCAR=14.3
1185 1 my $self = shift;
1186 1 my $num = shift;
1187 1 ▶ $num = 1 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 0 1 1
1188 1 ▶ $num = 1 if ($num < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $num < 1 0 1 1
1189 1 $self->callback_call ('GOTO', $self->{'x'} - $num, $self->{'y'});
1190 1 $self->{'x'} -= $num;
1191 1 ▶ $self->{'x'} = 1 if ($self->{'x'} < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} < 1 0 1 1
1192 }
1193  
1194 3 ▶sub _code_CUD { # move cursor down
Subroutine _code_CUD: called CC=3 SCAR=11.0
1195 3 my $self = shift;
1196 3 my $num = shift;
1197 3 ▶ $num = 1 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 1 2 3
1198 3 ▶ $num = 1 if ($num < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $num < 1 0 3 3
1199 3 $self->callback_call ('GOTO', $self->{'x'}, $self->{'y'} + $num);
1200 3 $self->_move_down ($num);
1201 }
1202  
1203 4 ▶sub _code_CUF { # move cursor right
Subroutine _code_CUF: called CC=4 SCAR=14.0
1204 4 my $self = shift;
1205 4 my $num = shift;
1206 4 ▶ $num = 1 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 2 2 4
1207 4 ▶ $num = 1 if ($num < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $num < 1 0 4 4
1208 4 $self->callback_call ('GOTO', $self->{'x'} + $num, $self->{'y'});
1209 4 $self->{'x'} += $num;
1210 4 ▶ $self->{'x'} = $self->{'cols'} if ($self->{'x'} > $self->{'cols'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} > $self->{"cols"} 0 4 4
1211 }
1212  
1213 102 ▶sub _code_CUP { # move cursor to row, column
Subroutine _code_CUP: called CC=7 SCAR=19.5
1214 102 my $self = shift;
1215 102 my ($row, $col) = (@_);
1216 102 ▶ $row = 1 if (not defined $row);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $row 45 57 102
1217 102 ▶ $col = 1 if (not defined $col);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $col 68 34 102
1218 102 ▶ $row = 1 if ($row < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $row < 1 0 102 102
1219 102 ▶ $col = 1 if ($col < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $col < 1 0 102 102
1220 102 ▶ $row = $self->{'rows'} if ($row > $self->{'rows'});
Branch: 1 branch
BranchTrueFalseTotal
if $row > $self->{"rows"} 1 101 102
1221 102 ▶ $col = $self->{'cols'} if ($col > $self->{'cols'});
Branch: 1 branch
BranchTrueFalseTotal
if $col > $self->{"cols"} 1 101 102
1222 102 $self->callback_call ('GOTO', $col, $row);
1223 102 $self->{'x'} = $col;
1224 102 $self->{'y'} = $row;
1225 }
1226  
1227 3 ▶sub _code_RI { # reverse line feed
Subroutine _code_RI: called CC=1 SCAR=0.0
1228 3 my $self = shift;
1229 3 $self->callback_call ('GOTO', $self->{'x'}, $self->{'y'} - 1);
1230 3 $self->_move_up;
1231 }
1232  
1233 3 ▶sub _code_CUU { # move cursor up
Subroutine _code_CUU: called CC=3 SCAR=11.0
1234 3 my $self = shift;
1235 3 my $num = shift;
1236 3 ▶ $num = 1 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 1 2 3
1237 3 ▶ $num = 1 if ($num < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $num < 1 0 3 3
1238 3 $self->callback_call ('GOTO', $self->{'x'}, $self->{'y'} - $num);
1239 3 $self->_move_up ($num);
1240 }
1241  
1242 0 ▶sub _code_DA { # return ESC [ ? 6 c (VT102)
Subroutine _code_DA: not called CC=1 SCAR=6.9
1243 0 my $self = shift;
1244 0 $self->callback_call ('OUTPUT', "\033[?6c", 0);
1245 }
1246  
1247 3 ▶sub _code_DCH { # delete characters on current line
Subroutine _code_DCH: called CC=6 SCAR=17.9
1248 3 my $self = shift;
1249 3 my $num = shift;
1250 3 my ($width, $todel, $line, $lsub, $rsub, $attr);
1251  
1252 3 ▶ $num = 1 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 1 2 3
1253 3 ▶ $num = 1 if ($num < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $num < 1 0 3 3
1254  
1255 3 $width = $self->{'cols'} + 1 - $self->{'x'};
1256 3 $todel = $num;
1257 3 ▶ $todel = $width if ($todel > $width);
Branch: 1 branch
BranchTrueFalseTotal
if $todel > $width 1 2 3
1258  
1259 3 $line = $self->{'scrt'}->[$self->{'y'}];
1260 3 ($lsub, $rsub) = ("", "");
1261 3 ▶ $lsub = substr ($line, 0, $self->{'x'} - 1) if ($self->{'x'} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} > 1 2 1 3
1262 3 $rsub = substr ($line, $self->{'x'} - 1 + $todel);
1263 3 $self->{'scrt'}->[$self->{'y'}] = $lsub . $rsub . ("\0" x $todel);
1264  
1265 3 $attr = DEFAULT_ATTR_PACKED;
1266 3 $line = $self->{'scra'}->[$self->{'y'}];
1267 3 ($lsub, $rsub) = ("", "");
1268 3 ▶ $lsub = substr ($line, 0, 2 * ($self->{'x'} - 1)) if ($self->{'x'} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} > 1 2 1 3
1269 3 $rsub = substr ($line, 2 * ($self->{'x'} - 1 + $todel));
1270 3 $self->{'scra'}->[$self->{'y'}] = $lsub . $rsub . ($attr x $todel);
1271  
1272 3 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
1273 }
1274  
1275 0 ▶sub _code_DCS { # device control string (ignored)
Subroutine _code_DCS: not called CC=1 SCAR=6.9
1276 0 my $self = shift;
1277 0 $self->{'_buf'} = '';
1278 0 $self->{'_inesc'} = 'DCS_ST';
1279 }
1280  
1281 15 ▶sub _code_DECSTBM { # set scrolling region
Subroutine _code_DECSTBM: called CC=8 SCAR=23.9
1282 15 my $self = shift;
1283 15 my ($top, $bottom) = (@_);
1284 15 ▶ $top = 1 if (not defined $top);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $top 0 15 15
1285 15 ▶ $bottom = $self->{'rows'} if (not defined $bottom);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bottom 0 15 15
1286 15 ▶ $top = 1 if ($top < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $top < 1 0 15 15
1287 15 ▶ $bottom = 1 if ($bottom < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $bottom < 1 0 15 15
1288 15 ▶ $top = $self->{'rows'} if ($top > $self->{'rows'});
Branch: 1 branch
BranchTrueFalseTotal
if $top > $self->{"rows"} 0 15 15
1289 15 ▶ $bottom = $self->{'rows'} if ($bottom > $self->{'rows'});
Branch: 1 branch
BranchTrueFalseTotal
if $bottom > $self->{"rows"} 0 15 15
1290 15 ▶ if ($bottom < $top) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bottom < $top) 0 15 15
1291 0 my $a = $bottom;
1292 0 $bottom = $top;
1293 0 $top = $a;
1294 }
1295 15 $self->{'srt'} = $top;
1296 15 $self->{'srb'} = $bottom;
1297 }
1298  
1299 0 ▶sub _code_DECTCEM { # Cursor on (set); Cursor off (reset)
Subroutine _code_DECTCEM: not called CC=1 SCAR=6.9
1300 0 my $self = shift;
1301 0 $self->{'cursor'} = shift;
1302 }
1303  
1304 0 ▶sub _code_IGN { # ignored control sequence
Subroutine _code_IGN: not called CC=1 SCAR=0.0
1305 }
1306  
1307 8 ▶sub _code_DL { # delete lines
Subroutine _code_DL: called CC=8 SCAR=20.8
1308 8 my $self = shift;
1309 8 my $lines = shift;
1310 8 my ($attr, $scrb, $row);
1311  
1312 8 ▶ $lines = 1 if (not defined $lines);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lines 2 6 8
1313 8 ▶ $lines = 1 if ($lines < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $lines < 1 0 8 8
1314  
1315 8 $attr = DEFAULT_ATTR_PACKED;
1316  
1317 8 $scrb = $self->{'srb'};
1318 8 ▶ $scrb = $self->{'rows'} if ($self->{'y'} > $self->{'srb'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"y"} > $self->{"srb"} 0 8 8
1319 8 ▶ $scrb = $self->{'srt'} - 1 if ($self->{'y'} < $self->{'srt'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"y"} < $self->{"srt"} 1 7 8
1320  
1321 8 ▶ for ($row = $self->{'y'}; $row <= ($scrb - $lines); $row ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row <= $scrb - $lines) 6 8 14
1322 6 $self->{'scrt'}->[$row] = $self->{'scrt'}->[$row + $lines];
1323 6 $self->{'scra'}->[$row] = $self->{'scra'}->[$row + $lines];
1324 6 $self->callback_call ('ROWCHANGE', $row, 0);
1325 }
1326  
1327 8 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($row > $scrb - $lines and $row >= $self->{"y"}) 14 8 22
Condition100%3/3
$row > $scrb - $lines and $row >= $self->{"y"}
!ll&&!rl&&r
5314
MC/DC100%2/2
$row > $scrb - $lines and $row >= $self->{"y"}
$row > $scrb - $lines $row >= $self->{"y"}
Truth table100%3/3
A and B
A= $row > $scrb - $linesB= $row >= $self->{"y"}
ABresult
0X0
100
111
1328 $row = $scrb;
1329 ($row > ($scrb - $lines)) && ($row >= ($self->{'y'}));
1330 $row --
1331 ) {
1332 14 $self->{'scrt'}->[$row] = "\000" x $self->{'cols'};
1333 14 $self->{'scra'}->[$row] = $attr x $self->{'cols'};
1334 14 $self->callback_call ('ROWCHANGE', $row, 0);
1335 }
1336 }
1337  
1338 0 ▶sub _code_DSR { # device status report
Subroutine _code_DSR: not called CC=4 SCAR=30.0
1339 0 my $self = shift;
1340 0 my $num = shift;
1341 0 ▶ $num = 5 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 0 0 0
1342 0 ▶ if ($num == 6) { # CPR - cursor position report
Branch: 2 branches
BranchTrueFalseTotal
if ($num == 6) { } 0 0 0
elsif ($num == 5) { } 0 0 0
1343 $self->callback_call (
1344 0 'OUTPUT', "\e[" . $self->{'y'} . ";" . $self->{'x'} . "R", 0
1345 );
1346 } elsif ($num == 5) { # DSR - reply ESC [ 0 n
1347 0 $self->callback_call ('OUTPUT', "\e[0n", 0);
1348 }
1349 }
1350  
1351 3 ▶sub _code_ECH { # erase characters on current line
Subroutine _code_ECH: called CC=6 SCAR=17.9
1352 3 my $self = shift;
1353 3 my $num = shift;
1354 3 my ($width, $todel, $line, $lsub, $rsub, $attr);
1355  
1356 3 ▶ $num = 1 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 1 2 3
1357 3 ▶ $num = 1 if ($num < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $num < 1 0 3 3
1358  
1359 3 $width = $self->{'cols'} + 1 - $self->{'x'};
1360 3 $todel = $num;
1361 3 ▶ $todel = $width if ($todel > $width);
Branch: 1 branch
BranchTrueFalseTotal
if $todel > $width 1 2 3
1362  
1363 3 $line = $self->{'scrt'}->[$self->{'y'}];
1364 3 ($lsub, $rsub) = ("", "");
1365 3 ▶ $lsub = substr ($line, 0, $self->{'x'} - 1) if ($self->{'x'} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} > 1 2 1 3
1366 3 $rsub = substr ($line, $self->{'x'} - 1 + $todel);
1367 3 $self->{'scrt'}->[$self->{'y'}] = $lsub . ("\0" x $todel) . $rsub;
1368  
1369 3 $attr = DEFAULT_ATTR_PACKED;
1370  
1371  
1372 3 $line = $self->{'scra'}->[$self->{'y'}];
1373 3 ($lsub, $rsub) = ("", "");
1374 3 ▶ $lsub = substr ($line, 0, 2 * ($self->{'x'} - 1)) if ($self->{'x'} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} > 1 2 1 3
1375 3 $rsub = substr ($line, 2 * ($self->{'x'} - 1 + $todel));
1376 3 $self->{'scra'}->[$self->{'y'}] = $lsub . ($attr x $todel) . $rsub;
1377  
1378 3 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
1379 }
1380  
1381 3 ▶sub _code_ED { # erase display
Subroutine _code_ED: called CC=10 SCAR=23.1
1382 3 my $self = shift;
1383 3 my $num = shift;
1384 3 my ($row, $attr);
1385  
1386 3 ▶ $num = 0 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 1 2 3
1387  
1388 3 $attr = DEFAULT_ATTR_PACKED;
1389  
1390 # Wipe-cursor-to-end is the same as clear-whole-screen if cursor at top left
1391 #
1392 3 ▶ $num = 2 if (($num == 0) && ($self->{'x'} == 1) && ($self->{'y'} == 1));
Branch: 1 branch
BranchTrueFalseTotal
if $num == 0 and $self->{"x"} == 1 and $self->{"y"} == 1 0 3 3
Condition50%3/6
$num == 0 and $self->{"x"} == 1 and $self->{"y"} == 1
!ll&&!rl&&r
300
$num == 0 and $self->{"x"} == 1
!ll&&!rl&&r
210
MC/DC0%0/3
$num == 0 and $self->{"x"} == 1 and $self->{"y"} == 1
$num == 0 $self->{"x"} == 1 $self->{"y"} == 1
Truth table50%2/4
A and B and C
A= $num == 0B= $self->{"x"} == 1C= $self->{"y"} == 1
ABCresult
0XX0
10X0
1100
1111
1393  
1394 3 ▶ if ($num == 0) { # 0 = cursor to end
Branch: 2 branches
BranchTrueFalseTotal
if ($num == 0) { } 1 2 3
elsif ($num == 1) { } 1 1 2
1395 $self->{'scrt'}->[$self->{'y'}] =
1396 substr (
1397 $self->{'scrt'}->[$self->{'y'}],
1398 0,
1399 $self->{'x'} - 1
1400 1 ) . ("\0" x ($self->{'cols'} + 1 - $self->{'x'}));
1401 $self->{'scra'}->[$self->{'y'}] =
1402 substr (
1403 $self->{'scra'}->[$self->{'y'}],
1404 0,
1405 2 * ($self->{'x'} - 1)
1406 1 ) . ($attr x ($self->{'cols'} + 1 - $self->{'x'}));
1407 1 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
1408 1 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($row <= $self->{"rows"}) 2 1 3
1409 $row = $self->{'y'} + 1;
1410 $row <= $self->{'rows'};
1411 $row ++
1412 ) {
1413 2 $self->{'scrt'}->[$row] = "\0" x $self->{'cols'};
1414 2 $self->{'scra'}->[$row] = $attr x $self->{'cols'};
1415 2 $self->callback_call ('ROWCHANGE', $row, 0);
1416 }
1417 } elsif ($num == 1) { # 1 = start to cursor
1418 1 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($row < $self->{"y"}) 1 1 2
1419 $row = 1;
1420 $row < $self->{'y'};
1421 $row ++
1422 ) {
1423 1 $self->{'scrt'}->[$row] = "\0" x $self->{'cols'};
1424 1 $self->{'scra'}->[$row] = $attr x $self->{'cols'};
1425 1 $self->callback_call ('ROWCHANGE', $row, 0);
1426 }
1427 $self->{'scrt'}->[$self->{'y'}] =
1428 ("\0" x $self->{'x'}) .
1429 1 substr ($self->{'scrt'}->[$self->{'y'}], $self->{'x'});
1430 $self->{'scra'}->[$self->{'y'}] =
1431 ($attr x $self->{'x'}) .
1432 1 substr ($self->{'scra'}->[$self->{'y'}], 2 * $self->{'x'});
1433 1 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
1434 } else { # 2 = whole display
1435 1 $self->callback_call ('CLEAR', 0, 0);
1436 1 ▶ for ($row = 1; $row <= $self->{'rows'}; $row ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row <= $self->{"rows"}) 4 1 5
1437 4 $self->{'scrt'}->[$row] = "\0" x $self->{'cols'};
1438 4 $self->{'scra'}->[$row] = $attr x $self->{'cols'};
1439 }
1440 }
1441 }
1442  
1443 3 ▶sub _code_EL { # erase line
Subroutine _code_EL: called CC=4 SCAR=13.9
1444 3 my $self = shift;
1445 3 my $num = shift;
1446 3 my $attr;
1447  
1448 3 ▶ $num = 0 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 1 2 3
1449  
1450 3 $attr = DEFAULT_ATTR_PACKED;
1451  
1452 3 ▶ if ($num == 0) { # 0 = cursor to end of line
Branch: 2 branches
BranchTrueFalseTotal
if ($num == 0) { } 1 2 3
elsif ($num == 1) { } 1 1 2
1453 $self->{'scrt'}->[$self->{'y'}] =
1454 substr (
1455 $self->{'scrt'}->[$self->{'y'}],
1456 0,
1457 $self->{'x'} - 1
1458 1 ) . ("\0" x ($self->{'cols'} + 1 - $self->{'x'}));
1459 $self->{'scra'}->[$self->{'y'}] =
1460 substr (
1461 $self->{'scra'}->[$self->{'y'}],
1462 0,
1463 2 * ($self->{'x'} - 1)
1464 1 ) . ($attr x ($self->{'cols'} + 1 - $self->{'x'}));
1465 1 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
1466 } elsif ($num == 1) { # 1 = start of line to cursor
1467 $self->{'scrt'}->[$self->{'y'}] =
1468 ("\0" x $self->{'x'}) .
1469 1 substr ($self->{'scrt'}->[$self->{'y'}], $self->{'x'});
1470 $self->{'scra'}->[$self->{'y'}] =
1471 ($attr x $self->{'x'}) .
1472 1 substr ($self->{'scra'}->[$self->{'y'}], 2 * $self->{'x'});
1473 1 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
1474 } else { # 2 = whole line
1475 1 $self->{'scrt'}->[$self->{'y'}] = "\0" x $self->{'cols'};
1476 1 $self->{'scra'}->[$self->{'y'}] = $attr x $self->{'cols'};
1477 1 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
1478 }
1479 }
1480  
1481 258 ▶sub _code_ESC { # start escape sequence
Subroutine _code_ESC: called CC=3 SCAR=11.0
1482 258 my $self = shift;
1483 258 ▶ if ((defined $self->{'_buf'}) && ($self->{'_inesc'} =~ /OSC|_ST/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_buf"} and $self->{"_inesc"} =~ /OSC|_ST/) 3 255 258
Condition66%2/3
defined $self->{"_buf"} and $self->{"_inesc"} =~ /OSC|_ST/
!ll&&!rl&&r
25503
MC/DC50%1/2
defined $self->{"_buf"} and $self->{"_inesc"} =~ /OSC|_ST/
defined $self->{"_buf"} $self->{"_inesc"} =~ /OSC|_ST/
Truth table66%2/3
A and B
A= defined $self->{"_buf"}B= $self->{"_inesc"} =~ /OSC|_ST/
ABresult
0X0
100
111
1484 # Some sequences are terminated with an ST
1485 3 $self->{'_buf'} .= "\033";
1486 3 $self->_process_escseq ();
1487 3 return;
1488 }
1489 255 $self->{'_buf'} = ''; # set ESC buffer
1490 255 $self->{'_inesc'} = 'ESC'; # ...for ESC, not CSI
1491 }
1492  
1493 184 ▶sub _code_LF { # line feed
Subroutine _code_LF: called CC=2 SCAR=6.9
1494 184 my $self = shift;
1495 $self->_code_CR () # cursor to start of line
1496 184 ▶ if ($self->{'opts'}->{'LFTOCRLF'} != 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"opts"}{"LFTOCRLF"} != 0 3 181 184
1497 184 $self->callback_call ('LINEFEED', $self->{'y'}, 0);
1498 184 $self->_move_down ();
1499 }
1500  
1501 2 ▶sub _code_NEL { # newline
Subroutine _code_NEL: called CC=1 SCAR=0.0
1502 2 my $self = shift;
1503 2 $self->_code_CR (); # cursor always to start
1504 2 $self->_code_LF (); # standard line feed
1505 }
1506  
1507 53 ▶sub _code_HT { # horizontal tab to next tab stop
Subroutine _code_HT: called CC=8 SCAR=22.1
1508 53 my $self = shift;
1509 53 my ($newx, $spaces, $width);
1510  
1511 53 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"opts"}{"LINEWRAP"} != 0 and $self->{"x"} >= $self->{"cols"}) 0 53 53
Condition33%1/3
$self->{"opts"}{"LINEWRAP"} != 0 and $self->{"x"} >= $self->{"cols"}
!ll&&!rl&&r
5300
MC/DC0%0/2
$self->{"opts"}{"LINEWRAP"} != 0 and $self->{"x"} >= $self->{"cols"}
$self->{"opts"}{"LINEWRAP"} != 0 $self->{"x"} >= $self->{"cols"}
Truth table33%1/3
A and B
A= $self->{"opts"}{"LINEWRAP"} != 0B= $self->{"x"} >= $self->{"cols"}
ABresult
0X0
100
111
1512 ($self->{'opts'}->{'LINEWRAP'} != 0)
1513 && ($self->{'x'} >= $self->{'cols'})
1514 ) {
1515 0 $self->callback_call ('LINEFEED', $self->{'y'}, 0);
1516 0 $self->{'x'} = 1;
1517 0 $self->_move_down;
1518 }
1519  
1520 53 $newx = $self->{'x'} + 1;
1521 53 ▶ while ($newx < $self->{'cols'} && not $self->{'_tabstops'}->[$newx]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newx < $self->{"cols"} and not $self->{"_tabstops"}[$newx]) 335 53 388
Condition100%3/3
$newx < $self->{"cols"} and not $self->{"_tabstops"}[$newx]
!ll&&!rl&&r
2033335
MC/DC100%2/2
$newx < $self->{"cols"} and not $self->{"_tabstops"}[$newx]
$newx < $self->{"cols"} not $self->{"_tabstops"}[$newx]
Truth table100%3/3
A and not(B)
A= $newx < $self->{"cols"}B= not $self->{"_tabstops"}[$newx]
ABresult
0X0
100
111
1522 335 $newx++;
1523 }
1524  
1525 53 $width = ($self->{'cols'} + 1) - $self->{'x'};
1526 53 $spaces = $newx - $self->{'x'};
1527 53 ▶ $spaces = $width + 1 if ($spaces > $width);
Branch: 1 branch
BranchTrueFalseTotal
if $spaces > $width 0 53 53
1528  
1529 53 ▶ if ($spaces > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spaces > 0) 53 0 53
1530 53 $self->{'x'} += $spaces;
1531 53 ▶ $self->{'x'} = $self->{'cols'} if ($self->{'x'} > $self->{'cols'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} > $self->{"cols"} 15 38 53
1532 }
1533 }
1534  
1535 13 ▶sub _code_HTS { # set tab stop at current column
Subroutine _code_HTS: called CC=1 SCAR=0.0
1536 13 my $self = shift;
1537 13 $self->{'_tabstops'}->[$self->{'x'}] = 1;
1538 }
1539  
1540 3 ▶sub _code_ICH { # insert blank characters
Subroutine _code_ICH: called CC=6 SCAR=17.9
1541 3 my $self = shift;
1542 3 my $num = shift;
1543 3 my ($width, $toins, $line, $lsub, $rsub, $attr);
1544  
1545 3 ▶ $num = 1 if (not defined $num);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 1 2 3
1546 3 ▶ $num = 1 if ($num < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $num < 1 0 3 3
1547  
1548 3 $width = $self->{'cols'} + 1 - $self->{'x'};
1549 3 $toins = $num;
1550 3 ▶ $toins = $width if ($toins > $width);
Branch: 1 branch
BranchTrueFalseTotal
if $toins > $width 1 2 3
1551  
1552 3 $line = $self->{'scrt'}->[$self->{'y'}];
1553 3 ($lsub, $rsub) = ("", "");
1554 3 ▶ $lsub = substr ($line, 0, $self->{'x'} - 1) if ($self->{'x'} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} > 1 2 1 3
1555 3 $rsub = substr ($line, $self->{'x'} - 1, $width - $toins);
1556 3 $self->{'scrt'}->[$self->{'y'}] = $lsub . ("\0" x $toins) . $rsub;
1557  
1558 3 $attr = DEFAULT_ATTR_PACKED;
1559 3 $line = $self->{'scra'}->[$self->{'y'}];
1560 3 ($lsub, $rsub) = ("", "");
1561 3 ▶ $lsub = substr ($line, 0, 2 * ($self->{'x'} - 1)) if ($self->{'x'} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"x"} > 1 2 1 3
1562 3 $rsub = substr ($line, 2 * ($self->{'x'} - 1), 2 * ($width - $toins));
1563 3 $self->{'scra'}->[$self->{'y'}] = $lsub . ($attr x $toins) . $rsub;
1564  
1565 3 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
1566 }
1567  
1568 8 ▶sub _code_IL { # insert blank lines
Subroutine _code_IL: called CC=8 SCAR=20.8
1569 8 my $self = shift;
1570 8 my $lines = shift;
1571 8 my ($attr, $scrb, $row);
1572  
1573 8 ▶ $lines = 1 if (not defined $lines);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lines 2 6 8
1574 8 ▶ $lines = 1 if ($lines < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $lines < 1 0 8 8
1575  
1576 8 $attr = DEFAULT_ATTR_PACKED;
1577  
1578 8 $scrb = $self->{'srb'};
1579 8 ▶ $scrb = $self->{'rows'} if ($self->{'y'} > $self->{'srb'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"y"} > $self->{"srb"} 0 8 8
1580 8 ▶ $scrb = $self->{'srt'} - 1 if ($self->{'y'} < $self->{'srt'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"y"} < $self->{"srt"} 1 7 8
1581  
1582 8 ▶ for ($row = $scrb; $row >= ($self->{'y'} + $lines); $row --) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row >= $self->{"y"} + $lines) 6 8 14
1583 6 $self->{'scrt'}->[$row] = $self->{'scrt'}->[$row - $lines];
1584 6 $self->{'scra'}->[$row] = $self->{'scra'}->[$row - $lines];
1585 6 $self->callback_call ('ROWCHANGE', $row, 0);
1586 }
1587  
1588 8 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($row <= $scrb and $row < $self->{"y"} + $lines) 14 8 22
Condition100%3/3
$row <= $scrb and $row < $self->{"y"} + $lines
!ll&&!rl&&r
4414
MC/DC100%2/2
$row <= $scrb and $row < $self->{"y"} + $lines
$row <= $scrb $row < $self->{"y"} + $lines
Truth table100%3/3
A and B
A= $row <= $scrbB= $row < $self->{"y"} + $lines
ABresult
0X0
100
111
1589 $row = $self->{'y'};
1590 ($row <= $scrb) && ($row < ($self->{'y'} + $lines));
1591 $row ++
1592 ) {
1593 14 $self->{'scrt'}->[$row] = "\000" x $self->{'cols'};
1594 14 $self->{'scra'}->[$row] = $attr x $self->{'cols'};
1595 14 $self->callback_call ('ROWCHANGE', $row, 0);
1596 }
1597 }
1598  
1599 0 ▶sub _code_PM { # privacy message (ignored)
Subroutine _code_PM: not called CC=1 SCAR=6.9
1600 0 my $self = shift;
1601 0 $self->{'_buf'} = '';
1602 0 $self->{'_inesc'} = 'PM_ST';
1603 }
1604  
1605 1 ▶sub _code_APC { # application program command (ignored)
Subroutine _code_APC: called CC=1 SCAR=0.0
1606 1 my $self = shift;
1607 1 $self->{'_buf'} = '';
1608 1 $self->{'_inesc'} = 'APC_ST';
1609 }
1610  
1611 2 ▶sub _code_OSC { # operating system command
Subroutine _code_OSC: called CC=1 SCAR=0.0
1612 2 my $self = shift;
1613 2 $self->{'_buf'} = ''; # restart buffering
1614 2 $self->{'_inesc'} = 'OSC'; # ...for OSC, not ESC or CSI
1615 }
1616  
1617 0 ▶sub _code_RIS { # reset
Subroutine _code_RIS: not called CC=1 SCAR=6.9
1618 0 my $self = shift;
1619 0 $self->reset ();
1620 }
1621  
1622 0 ▶sub _toggle_mode { # set/reset modes
Subroutine _toggle_mode: not called CC=5 SCAR=34.0
1623 0 my $self = shift;
1624 0 my ($flag, @modes) = @_;
1625  
1626 0 foreach my $mode (@modes) {
1627 0 my $name = $self->{'_modeseq'}->{$mode};
1628 0 my $func = undef;
1629 0 ▶ $func = $self->{'_funcs'}->{$name} if (defined $name);
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
1630 0 ▶ if (not defined $func) { # unsupported seq.
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $func) 0 0 0
1631 0 ▶ $self->callback_call (
Branch: 1 branch
BranchTrueFalseTotal
$flag ? : 0 0 0
1632 'UNKNOWN',
1633 $name,
1634 "\033[${mode}" . ($flag ? "h" : "l")
1635 );
1636 0 $self->{'_buf'} = undef;
1637 0 $self->{'_inesc'} = '';
1638 0 return;
1639 }
1640 0 $self->{'_buf'} = undef;
1641 0 $self->{'_inesc'} = '';
1642 0 &{$func} ($self, $flag);
1643 0 return;
1644 }
1645 }
1646  
1647 0 ▶sub _code_RM { # reset mode
Subroutine _code_RM: not called CC=1 SCAR=6.9
1648 0 my $self = shift;
1649 0 $self->_toggle_mode(0, @_);
1650 }
1651  
1652 0 ▶sub _code_SM { # set mode
Subroutine _code_SM: not called CC=1 SCAR=6.9
1653 0 my $self = shift;
1654 0 $self->_toggle_mode(1, @_);
1655 }
1656  
1657 30 ▶sub _code_SGR { # set graphic rendition
Subroutine _code_SGR: called CC=21 SCAR=31.0
1658 30 my $self = shift;
1659 30 my (@parms) = (@_);
1660 30 my ($val, $fg, $bg, $bo, $fa, $st, $ul, $bl, $rv);
1661  
1662 ($fg, $bg, $bo, $fa, $st, $ul, $bl, $rv) =
1663 30 $self->attr_unpack ($self->{'attr'});
1664  
1665 30 ▶ @parms = (0) if ($#parms < 0); # ESC [ m = ESC [ 0 m
Branch: 1 branch
BranchTrueFalseTotal
if $#parms < 0 5 25 30
1666  
1667 30 ▶ while (defined ($val = shift @parms)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($val = shift @parms)) 37 30 67
1668 37 ▶ if ($val == 0) { # reset all attributes
Branch: 16 branches
BranchTrueFalseTotal
if ($val == 0) { } 5 32 37
elsif ($val == 1) { } 4 28 32
elsif ($val == 2) { } 3 25 28
elsif ($val == 4) { } 2 23 25
elsif ($val == 5) { } 2 21 23
elsif ($val == 7) { } 2 19 21
elsif ($val == 21) { } 1 18 19
elsif ($val == 22) { } 1 17 18
elsif ($val == 24) { } 0 17 17
elsif ($val == 25) { } 0 17 17
elsif ($val == 27) { } 0 17 17
elsif ($val >= 30 and $val <= 37) { } 7 10 17
elsif ($val == 38) { } 1 9 10
elsif ($val == 39) { } 1 8 9
elsif ($val >= 40 and $val <= 47) { } 7 1 8
elsif ($val == 49) { } 1 0 1
1669 5 ($fg, $bg, $bo, $fa, $st, $ul, $bl, $rv) = DEFAULT_ATTR;
1670 } elsif ($val == 1) { # bold ON
1671 4 ($bo, $fa) = (1, 0);
1672 } elsif ($val == 2) { # faint ON
1673 3 ($bo, $fa) = (0, 1);
1674 } elsif ($val == 4) { # underline ON
1675 2 $ul = 1;
1676 } elsif ($val == 5) { # blink ON
1677 2 $bl = 1;
1678 } elsif ($val == 7) { # reverse video ON
1679 2 $rv = 1;
1680 } elsif ($val == 21) { # normal intensity
1681 1 ($bo, $fa) = (0, 0);
1682 } elsif ($val == 22) { # normal intensity
1683 1 ($bo, $fa) = (0, 0);
1684 } elsif ($val == 24) { # underline OFF
1685 0 $ul = 0;
1686 } elsif ($val == 25) { # blink OFF
1687 0 $bl = 0;
1688 } elsif ($val == 27) { # reverse video OFF
1689 0 $rv = 0;
1690 ▶ } elsif (($val >= 30) && ($val <= 37)) {# set foreground colour
Condition66%2/3
$val >= 30 and $val <= 37
!ll&&!rl&&r
0107
MC/DC50%1/2
$val >= 30 and $val <= 37
$val >= 30 $val <= 37
Truth table66%2/3
A and B
A= $val >= 30B= $val <= 37
ABresult
0X0
100
111
1691 7 $fg = $val - 30;
1692 } elsif ($val == 38) { # underline on, default fg
1693 1 ($ul, $fg) = (1, 7);
1694 } elsif ($val == 39) { # underline off, default fg
1695 1 ($ul, $fg) = (0, 7);
1696 ▶ } elsif (($val >= 40) && ($val <= 47)) {# set background colour
Condition66%2/3
$val >= 40 and $val <= 47
!ll&&!rl&&r
017
MC/DC50%1/2
$val >= 40 and $val <= 47
$val >= 40 $val <= 47
Truth table66%2/3
A and B
A= $val >= 40B= $val <= 47
ABresult
0X0
100
111
1697 7 $bg = $val - 40;
1698 } elsif ($val == 49) { # default background
1699 1 $bg = 0;
1700 }
1701 }
1702  
1703 30 $self->{'attr'} = $self->attr_pack ($fg, $bg, $bo, $fa, $st, $ul, $bl, $rv);
1704 }
1705  
1706 1 ▶sub _code_VPA { # move to row (current column)
Subroutine _code_VPA: called CC=5 SCAR=17.0
1707 1 my $self = shift;
1708 1 my $row = shift;
1709 1 ▶ $row = 1 if (not defined $row);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $row 0 1 1
1710 1 ▶ return if ($self->{'y'} == $row);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"y"} == $row 0 1 1
1711 1 $self->{'y'} = $row;
1712 1 ▶ $self->{'y'} = 1 if ($self->{'y'} < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"y"} < 1 0 1 1
1713 1 ▶ $self->{'y'} = $self->{'rows'} if ($self->{'y'} > $self->{'rows'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"y"} > $self->{"rows"} 0 1 1
1714 }
1715  
1716 1 ▶sub _code_DECALN { # fill screen with E's
Subroutine _code_DECALN: called CC=2 SCAR=6.9
1717 1 my $self = shift;
1718 1 my ($row, $attr);
1719  
1720 1 $attr = DEFAULT_ATTR_PACKED;
1721  
1722 1 ▶ for ($row = 1; $row <= $self->{'rows'}; $row ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row <= $self->{"rows"}) 3 1 4
1723 3 $self->{'scrt'}->[$row] = 'E' x $self->{'cols'};
1724 3 $self->{'scra'}->[$row] = $attr x $self->{'cols'};
1725 3 $self->callback_call ('ROWCHANGE', $self->{'y'}, 0);
1726 }
1727  
1728 1 $self->{'x'} = 1;
1729 1 $self->{'y'} = 1;
1730 }
1731  
1732 2 ▶sub _code_DECSC { # save state
Subroutine _code_DECSC: called CC=1 SCAR=0.0
1733 2 my $self = shift;
1734 2 my @state;
1735  
1736 2 @state = @{$self->{'_decsc'}};
1737 push (
1738 @state,
1739 [
1740 $self->{'x'},
1741 $self->{'y'},
1742 $self->{'attr'},
1743 $self->{'ti'},
1744 $self->{'ic'},
1745 2 $self->{'cursor'}
1746 ]
1747 );
1748 2 $self->{'_decsc'} = [ @state ];
1749 }
1750  
1751 2 ▶sub _code_DECRC { # restore most recently saved state
Subroutine _code_DECRC: called CC=2 SCAR=7.0
1752 2 my $self = shift;
1753 2 my @state;
1754 my $ref;
1755  
1756 2 @state = @{$self->{'_decsc'}};
1757 2 ▶ return if ($#state < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $#state < 0 0 2 2
1758  
1759 2 $ref = pop @state;
1760  
1761 (
1762 $self->{'x'},
1763 $self->{'y'},
1764 $self->{'attr'},
1765 $self->{'ti'},
1766 $self->{'ic'},
1767 2 $self->{'cursor'}
1768 ) = @$ref;
1769  
1770 2 $self->{'_decsc'} = [ @state ];
1771 }
1772  
1773 2 ▶sub _code_CUPSV { # save cursor position
Subroutine _code_CUPSV: called CC=1 SCAR=0.0
1774 2 my $self = shift;
1775 2 my @state;
1776  
1777 2 @state = @{$self->{'_cupsv'}};
1778 push (
1779 @state,
1780 [
1781 $self->{'x'},
1782 2 $self->{'y'}
1783 ]
1784 );
1785 2 $self->{'_cupsv'} = [ @state ];
1786 }
1787  
1788 2 ▶sub _code_CUPRS { # restore cursor position
Subroutine _code_CUPRS: called CC=2 SCAR=7.0
1789 2 my $self = shift;
1790 2 my @state;
1791 my $ref;
1792  
1793 2 @state = @{$self->{'_cupsv'}};
1794 2 ▶ return if ($#state < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $#state < 0 0 2 2
1795  
1796 2 $ref = pop @state;
1797  
1798 (
1799 $self->{'x'},
1800 2 $self->{'y'}
1801 ) = @$ref;
1802  
1803 2 $self->{'_cupsv'} = [ @state ];
1804 }
1805  
1806 2 ▶sub _code_XON { # resume character processing
Subroutine _code_XON: called CC=1 SCAR=0.0
1807 2 my $self = shift;
1808 2 $self->{'_xon'} = 1;
1809 }
1810  
1811 2 ▶sub _code_XOFF { # stop character processing
Subroutine _code_XOFF: called CC=2 SCAR=6.9
1812 2 my $self = shift;
1813 2 ▶ return if ($self->{'opts'}->{'IGNOREXOFF'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"opts"}{"IGNOREXOFF"} 1 1 2
1814 1 $self->{'_xon'} = 0;
1815 }
1816  
1817 14 1;
1818 __END__
↑ Summary VT102/examples/sanitize-dump.pl »