line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::optex::xform; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = "1.04"; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=encoding utf-8 |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
xform - data transform filter module for optex |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
optex -Mxform |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
B is a filter module for B command which transform STDIN |
18
|
|
|
|
|
|
|
into different form to make it convenient to manipulate, and recover |
19
|
|
|
|
|
|
|
to the original form after the process. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Transformed data have to be appear in exactly same order as original |
22
|
|
|
|
|
|
|
data. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 OPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=over 7 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=item B<--xform-ansi> |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Transform ANSI terminal sequence into printable string, and recover. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=item B<--xform-utf8> |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Transform multibyte Non-ASCII chracters into single-byte sequene, and |
35
|
|
|
|
|
|
|
recover. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=back |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 EXAMPLE |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$ jot 100 | egrep --color=always .+ | optex column -Mxform --xform-ansi -x |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SEE ALSO |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
L, L, |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
L, L, |
48
|
|
|
|
|
|
|
L |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
L |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 AUTHOR |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Kazumasa Utashiro |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 LICENSE |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Copyright 2020-2022 Kazumasa Utashiro. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
61
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
1
|
|
654
|
use v5.14; |
|
1
|
|
|
|
|
3
|
|
66
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
67
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
68
|
1
|
|
|
1
|
|
563
|
use utf8; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
4
|
|
69
|
1
|
|
|
1
|
|
448
|
use open IO => 'utf8', ':std'; |
|
1
|
|
|
|
|
996
|
|
|
1
|
|
|
|
|
5
|
|
70
|
1
|
|
|
1
|
|
597
|
use Data::Dumper; |
|
1
|
|
|
|
|
5952
|
|
|
1
|
|
|
|
|
73
|
|
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
1
|
|
444
|
use Text::Conceal; |
|
1
|
|
|
|
|
54496
|
|
|
1
|
|
|
|
|
41
|
|
73
|
1
|
|
|
1
|
|
7
|
use Text::VisualWidth::PP qw(vwidth); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
74
|
1
|
|
|
1
|
|
405
|
use Text::ANSI::Fold::Util qw(ansi_width); |
|
1
|
|
|
|
|
2013
|
|
|
1
|
|
|
|
|
108
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my %concealer; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my %param = ( |
79
|
|
|
|
|
|
|
ansi => { |
80
|
|
|
|
|
|
|
length => \&ansi_width, |
81
|
|
|
|
|
|
|
match => qr/\e\[.*?(?:\e\[0*m)+(?:\e\[0*K)*/, |
82
|
|
|
|
|
|
|
visible => 2, |
83
|
|
|
|
|
|
|
}, |
84
|
|
|
|
|
|
|
utf8 => { |
85
|
|
|
|
|
|
|
length => \&vwidth, |
86
|
|
|
|
|
|
|
match => qr/\P{ASCII}+/, |
87
|
|
|
|
|
|
|
visible => 2, |
88
|
|
|
|
|
|
|
}, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub encode { |
92
|
0
|
|
|
0
|
0
|
|
my %arg = @_; |
93
|
0
|
|
|
|
|
|
my $mode = $arg{mode}; |
94
|
0
|
0
|
|
|
|
|
my $param = $param{$mode} or die "$mode: unkown mode\n"; |
95
|
0
|
|
|
|
|
|
my $conceal = Text::Conceal->new(%$param); |
96
|
0
|
0
|
|
|
|
|
$concealer{$mode} and die "$mode: encoding repeated\n"; |
97
|
0
|
|
|
|
|
|
local $_ = do { local $/; <> }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
if ($conceal) { |
99
|
0
|
|
|
|
|
|
$conceal->encode($_); |
100
|
0
|
|
|
|
|
|
$concealer{$mode} = $conceal; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
return $_; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub decode { |
106
|
0
|
|
|
0
|
0
|
|
my %arg = @_; |
107
|
0
|
|
|
|
|
|
my $mode = $arg{mode}; |
108
|
0
|
0
|
|
|
|
|
$param{$mode} or die "$arg{mode}: unkown mode\n"; |
109
|
0
|
|
|
|
|
|
local $_ = do { local $/; <> }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
if (my $conceal = $concealer{$mode}) { |
111
|
0
|
|
|
|
|
|
$conceal->decode($_); |
112
|
|
|
|
|
|
|
} else { |
113
|
0
|
|
|
|
|
|
die "$mode: not encoded\n"; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
print $_; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__DATA__ |