line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Unixish::wrap; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-01-06'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '1.570'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
508
|
use 5.010; |
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
8
|
1
|
|
|
1
|
|
392
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
1
|
|
|
|
|
23795
|
|
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
1
|
|
3389
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
10
|
|
|
|
|
|
|
#use Log::Any '$log'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
439
|
use Data::Unixish::Util qw(%common_args); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
119
|
|
13
|
1
|
|
|
1
|
|
441
|
use Text::ANSI::Util qw(ta_wrap); |
|
1
|
|
|
|
|
5716
|
|
|
1
|
|
|
|
|
70
|
|
14
|
1
|
|
|
1
|
|
459
|
use Text::ANSI::WideUtil qw(ta_mbwrap); |
|
1
|
|
|
|
|
53843
|
|
|
1
|
|
|
|
|
68
|
|
15
|
1
|
|
|
1
|
|
10
|
use Text::WideChar::Util qw(mbwrap); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
310
|
|
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
|
4
|
my %args = @_; |
43
|
1
|
|
|
|
|
2
|
my ($in, $out) = ($args{in}, $args{out}); |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
4
|
_wrap_begin(\%args); |
46
|
1
|
|
|
|
|
7
|
while (my ($index, $item) = each @$in) { |
47
|
1
|
|
|
|
|
3
|
push @$out, _wrap_item($item, \%args); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
7
|
[200, "OK"]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _wrap_begin { |
54
|
2
|
|
|
2
|
|
3
|
my $args = shift; |
55
|
2
|
|
50
|
|
|
9
|
$args->{width} //= 80; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _wrap_item { |
59
|
2
|
|
|
2
|
|
5
|
my ($item, $args) = @_; |
60
|
|
|
|
|
|
|
{ |
61
|
2
|
50
|
33
|
|
|
4
|
last if !defined($item) || ref($item); |
|
2
|
|
|
|
|
13
|
|
62
|
2
|
50
|
|
|
|
8
|
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
|
|
|
|
|
7
|
$item = Text::WideChar::Util::wrap($item, $args->{width}); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
2
|
|
|
|
|
4219
|
return $item; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
# ABSTRACT: Wrap text |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |