| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::Unixish::wrap; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-10-26'; # DATE |
|
4
|
|
|
|
|
|
|
our $VERSION = '1.572'; # VERSION |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
443
|
use 5.010; |
|
|
1
|
|
|
|
|
5
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
19
|
|
|
8
|
1
|
|
|
1
|
|
349
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
|
1
|
|
|
|
|
19356
|
|
|
|
1
|
|
|
|
|
3
|
|
|
9
|
1
|
|
|
1
|
|
2801
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
|
|
#use Log::Any '$log'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
354
|
use Data::Unixish::Util qw(%common_args); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
99
|
|
|
13
|
1
|
|
|
1
|
|
429
|
use Text::ANSI::Util qw(ta_wrap); |
|
|
1
|
|
|
|
|
4420
|
|
|
|
1
|
|
|
|
|
53
|
|
|
14
|
1
|
|
|
1
|
|
378
|
use Text::ANSI::WideUtil qw(ta_mbwrap); |
|
|
1
|
|
|
|
|
45754
|
|
|
|
1
|
|
|
|
|
54
|
|
|
15
|
1
|
|
|
1
|
|
7
|
use Text::WideChar::Util qw(mbwrap); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
252
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our %SPEC; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$SPEC{wrap} = { |
|
20
|
|
|
|
|
|
|
v => 1.1, |
|
21
|
|
|
|
|
|
|
summary => 'Wrap text', |
|
22
|
|
|
|
|
|
|
args => { |
|
23
|
|
|
|
|
|
|
%common_args, |
|
24
|
|
|
|
|
|
|
width => { |
|
25
|
|
|
|
|
|
|
summary => 'Target column width', |
|
26
|
|
|
|
|
|
|
schema =>[int => {default=>80, min=>1}], |
|
27
|
|
|
|
|
|
|
cmdline_aliases => { c=>{} }, |
|
28
|
|
|
|
|
|
|
pos => 0, |
|
29
|
|
|
|
|
|
|
}, |
|
30
|
|
|
|
|
|
|
ansi => { |
|
31
|
|
|
|
|
|
|
summary => 'Whether to handle ANSI escape codes', |
|
32
|
|
|
|
|
|
|
schema => ['bool', default => 0], |
|
33
|
|
|
|
|
|
|
}, |
|
34
|
|
|
|
|
|
|
mb => { |
|
35
|
|
|
|
|
|
|
summary => 'Whether to handle wide characters', |
|
36
|
|
|
|
|
|
|
schema => ['bool', default => 0], |
|
37
|
|
|
|
|
|
|
}, |
|
38
|
|
|
|
|
|
|
}, |
|
39
|
|
|
|
|
|
|
tags => [qw/text itemfunc/], |
|
40
|
|
|
|
|
|
|
}; |
|
41
|
|
|
|
|
|
|
sub wrap { |
|
42
|
1
|
|
|
1
|
1
|
3
|
my %args = @_; |
|
43
|
1
|
|
|
|
|
2
|
my ($in, $out) = ($args{in}, $args{out}); |
|
44
|
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
3
|
_wrap_begin(\%args); |
|
46
|
1
|
|
|
|
|
5
|
while (my ($index, $item) = each @$in) { |
|
47
|
1
|
|
|
|
|
2
|
push @$out, _wrap_item($item, \%args); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
4
|
[200, "OK"]; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _wrap_begin { |
|
54
|
2
|
|
|
2
|
|
2
|
my $args = shift; |
|
55
|
2
|
|
50
|
|
|
7
|
$args->{width} //= 80; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _wrap_item { |
|
59
|
2
|
|
|
2
|
|
3
|
my ($item, $args) = @_; |
|
60
|
|
|
|
|
|
|
{ |
|
61
|
2
|
50
|
33
|
|
|
2
|
last if !defined($item) || ref($item); |
|
|
2
|
|
|
|
|
11
|
|
|
62
|
2
|
50
|
|
|
|
6
|
if ($args->{ansi}) { |
|
|
|
50
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
0
|
if ($args->{mb}) { |
|
64
|
0
|
|
|
|
|
0
|
$item = ta_mbwrap($item, $args->{width}); |
|
65
|
|
|
|
|
|
|
} else { |
|
66
|
0
|
|
|
|
|
0
|
$item = ta_wrap ($item, $args->{width}); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
} elsif ($args->{mb}) { |
|
69
|
0
|
|
|
|
|
0
|
$item = mbwrap($item, $args->{width}); |
|
70
|
|
|
|
|
|
|
} else { |
|
71
|
2
|
|
|
|
|
5
|
$item = Text::WideChar::Util::wrap($item, $args->{width}); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
2
|
|
|
|
|
3910
|
return $item; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
|
78
|
|
|
|
|
|
|
# ABSTRACT: Wrap text |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |