VT102/examples/sanitize-dump.pl untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 66 CC 6 SCAR 34.7
CC
6
Cov
0%
vt_callback
42.0
BEGIN
2.0
BEGIN
2.0
CRAP 32.0
1 ;#!/usr/bin/perl
2 #
3 # Example script that sanitizes a log file, such as that created by
4 # screen(1) or script(1) (or even one of Term::VT102's other example
5 # scripts).
6 #
7 # Any cursor positioning and other control codes are removed, leaving only
8 # complete lines of text, optionally including ANSI/ECMA-48 colour and
9 # attribute change sequences.
10 #
11 # Arguments are <width> <height> [colour|plain] - if nothing is provided,
12 # the default is to assume an 80x24 terminal with colour output.
13 #
14 # Data is read from standard input and written to standard output.
15 #
16  
17 use Term::VT102;
18 use strict;
19  
20 my ($width, $height, $colour) = @ARGV;
21 $width = 80 if ((not defined $width) || ($width !~ /^\d+$/));
22 $height = 24 if ((not defined $height) || ($height !~ /^\d+$/));
23 $colour = (defined $colour && $colour !~ /^(colour|color)$/) ? 0 : 1;
24  
25 my $vt = Term::VT102->new ('cols' => $width, 'rows' => $height);
26 $vt->option_set ('LFTOCRLF', 1);
27 $vt->option_set ('LINEWRAP', 1);
28  
29 $vt->callback_set ('GOTO', \&vt_callback, $colour);
30 $vt->callback_set ('LINEFEED', \&vt_callback, $colour);
31  
32 while (<STDIN>) {
33 $vt->process ($_);
34 }
35  
36  
37 sub vt_callback {
38 my ($vtobject, $type, $arg1, $arg2, $private) = @_;
39  
40 if ($type eq 'GOTO') {
41 $arg2 = $vtobject->rows if ($arg2 > $vtobject->rows);
42 return if ($arg2 <= $vtobject->y);
43 for (my $y = $vtobject->y; $y < $arg2; $y++) {
44 print "\n";
45 }
46 } elsif ($type eq 'LINEFEED') {
47 my $line = $private ? $vtobject->row_sgrtext ($arg1) : $vtobject->row_plaintext ($arg1);
48 $line =~ s/\s+$//;
49 print '' . $line . "\n";
50 }
51 }
52  
53 # EOF