line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::ANSI::Fold::Util; |
2
|
|
|
|
|
|
|
our $VERSION = "0.06"; |
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
211093
|
use v5.14; |
|
4
|
|
|
|
|
38
|
|
5
|
4
|
|
|
4
|
|
1275
|
use utf8; |
|
4
|
|
|
|
|
34
|
|
|
4
|
|
|
|
|
19
|
|
6
|
4
|
|
|
4
|
|
195
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
103
|
|
7
|
4
|
|
|
4
|
|
2484
|
use Data::Dumper; |
|
4
|
|
|
|
|
27963
|
|
|
4
|
|
|
|
|
276
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
28
|
use Exporter qw(import); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
298
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK; |
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
29
|
use List::Util qw(max); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
446
|
|
14
|
4
|
|
|
4
|
|
2169
|
use Text::ANSI::Fold qw(ansi_fold); |
|
4
|
|
|
|
|
245663
|
|
|
4
|
|
|
|
|
400
|
|
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.06 |
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
|
|
332
|
BEGIN { push @EXPORT_OK, qw(&ansi_width) } |
65
|
6
|
|
|
6
|
1
|
17651
|
sub ansi_width { goto &width } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub width { |
68
|
6
|
|
|
6
|
1
|
31
|
(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
|
|
564
|
BEGIN { push @EXPORT_OK, qw(&ansi_substr) } |
89
|
1
|
|
|
1
|
1
|
95
|
sub ansi_substr { goto &substr } |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub substr { |
92
|
12
|
|
|
12
|
1
|
6250
|
my($text, $offset, $length, $replacement) = @_; |
93
|
12
|
100
|
|
|
|
48
|
if ($offset < 0) { |
94
|
4
|
|
|
|
|
12
|
$offset = max(0, $offset + ansi_width($text)); |
95
|
|
|
|
|
|
|
} |
96
|
12
|
|
100
|
|
|
697
|
my @s = Text::ANSI::Fold |
97
|
|
|
|
|
|
|
->new(text => $text, width => [ $offset, $length // -1, -1 ]) |
98
|
|
|
|
|
|
|
->chops; |
99
|
12
|
100
|
|
|
|
23959
|
if (defined $replacement) { |
100
|
2
|
|
50
|
|
|
12
|
$s[0] . $replacement . ($s[2] // ''); |
101
|
|
|
|
|
|
|
} else { |
102
|
10
|
|
|
|
|
36
|
$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
|
|
1921
|
use Text::ANSI::Tabs qw(ansi_expand); |
|
4
|
|
|
|
|
4111
|
|
|
4
|
|
|
|
|
305
|
|
118
|
4
|
|
|
4
|
|
298
|
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__ |