line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::ANSI::Fold::Util; |
2
|
|
|
|
|
|
|
our $VERSION = "0.07"; |
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
172833
|
use v5.14; |
|
4
|
|
|
|
|
40
|
|
5
|
4
|
|
|
4
|
|
997
|
use utf8; |
|
4
|
|
|
|
|
28
|
|
|
4
|
|
|
|
|
17
|
|
6
|
4
|
|
|
4
|
|
91
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
95
|
|
7
|
4
|
|
|
4
|
|
1989
|
use Data::Dumper; |
|
4
|
|
|
|
|
27331
|
|
|
4
|
|
|
|
|
264
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
27
|
use Exporter qw(import); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
253
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK; |
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
26
|
use List::Util qw(max); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
372
|
|
14
|
4
|
|
|
4
|
|
1731
|
use Text::ANSI::Fold qw(ansi_fold); |
|
4
|
|
|
|
|
208455
|
|
|
4
|
|
|
|
|
413
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=encoding utf-8 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Text::ANSI::Fold::Util - Text::ANSI::Fold utilities (width, substr) |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Text::ANSI::Fold::Util qw(:all); |
25
|
|
|
|
|
|
|
use Text::ANSI::Fold::Util qw(ansi_width ansi_substr); |
26
|
|
|
|
|
|
|
ansi_width($text); |
27
|
|
|
|
|
|
|
ansi_substr($text, $offset, $width [, $replacement]); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use Text::ANSI::Fold::Util; |
30
|
|
|
|
|
|
|
Text::ANSI::Fold::Util::width($text); |
31
|
|
|
|
|
|
|
Text::ANSI::Fold::Util::substr($text, ...); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# ansi_expand() was moved to Text::ANSI::Tabs |
34
|
|
|
|
|
|
|
ansi_expand($text); |
35
|
|
|
|
|
|
|
Text::ANSI::Fold::Util::expand($text); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 VERSION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Version 0.07 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
This is a collection of utilities using Text::ANSI::Fold module. All |
44
|
|
|
|
|
|
|
functions are aware of ANSI terminal sequence. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 FUNCTION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
There are exportable functions start with B prefix, and |
49
|
|
|
|
|
|
|
unexportable functions without them. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=over 7 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item B(I) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item B(I) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns visual width of given text. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
|
4
|
|
392
|
BEGIN { push @EXPORT_OK, qw(&ansi_width) } |
65
|
6
|
|
|
6
|
1
|
19508
|
sub ansi_width { goto &width } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub width { |
68
|
6
|
|
|
6
|
1
|
27
|
(ansi_fold($_[0], -1))[2]; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item B(I, I, I [, I]) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item B(I, I, I [, I]) |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Returns substring just like Perl's B function, but string |
77
|
|
|
|
|
|
|
position is calculated by the visible width on the screen instead of |
78
|
|
|
|
|
|
|
number of characters. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
If an optional I parameter is given, replace the substring |
81
|
|
|
|
|
|
|
by the replacement and return the entire string. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
It does not cut the text in the middle of multi-byte character, of |
84
|
|
|
|
|
|
|
course. Its behavior depends on the implementation of lower module. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
4
|
|
|
4
|
|
513
|
BEGIN { push @EXPORT_OK, qw(&ansi_substr) } |
89
|
1
|
|
|
1
|
1
|
70
|
sub ansi_substr { goto &substr } |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub substr { |
92
|
12
|
|
|
12
|
1
|
4893
|
my($text, $offset, $length, $replacement) = @_; |
93
|
12
|
100
|
|
|
|
38
|
if ($offset < 0) { |
94
|
4
|
|
|
|
|
10
|
$offset = max(0, $offset + ansi_width($text)); |
95
|
|
|
|
|
|
|
} |
96
|
12
|
|
100
|
|
|
549
|
my @s = Text::ANSI::Fold |
97
|
|
|
|
|
|
|
->new(text => $text, width => [ $offset, $length // -1, -1 ]) |
98
|
|
|
|
|
|
|
->chops; |
99
|
12
|
100
|
|
|
|
19174
|
if (defined $replacement) { |
100
|
2
|
|
50
|
|
|
10
|
$s[0] . $replacement . ($s[2] // ''); |
101
|
|
|
|
|
|
|
} else { |
102
|
10
|
|
|
|
|
32
|
$s[1]; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item B(I, ...) |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item B(I, ...) |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This function is now moved to L module. Interface |
112
|
|
|
|
|
|
|
remains only for backward compatibility, and may be deprecated in the |
113
|
|
|
|
|
|
|
future. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
4
|
|
|
4
|
|
1493
|
use Text::ANSI::Tabs qw(ansi_expand); |
|
4
|
|
|
|
|
3903
|
|
|
4
|
|
|
|
|
271
|
|
118
|
4
|
|
|
4
|
|
227
|
BEGIN { push @EXPORT_OK, qw(&ansi_expand) } |
119
|
|
|
|
|
|
|
*tabstop = \$Text::ANSI::Tabs::tabstop; |
120
|
|
|
|
|
|
|
*expand = \&Text::ANSI::Tabs::expand; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=back |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |