line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Unixish::lpad; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
3652
|
use 5.010; |
|
7
|
|
|
|
|
31
|
|
4
|
7
|
|
|
7
|
|
3223
|
use locale; |
|
7
|
|
|
|
|
4163
|
|
|
7
|
|
|
|
|
35
|
|
5
|
7
|
|
|
7
|
|
259
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
146
|
|
6
|
7
|
|
|
7
|
|
469
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
7
|
|
|
|
|
24438
|
|
|
7
|
|
|
|
|
30
|
|
7
|
7
|
|
|
7
|
|
4383
|
use warnings; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
176
|
|
8
|
|
|
|
|
|
|
#use Log::Any '$log'; |
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
3297
|
use Data::Unixish::_pad; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
277
|
|
11
|
7
|
|
|
7
|
|
541
|
use Data::Unixish::Util qw(%common_args); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
2309
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.571'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %SPEC; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$SPEC{lpad} = { |
18
|
|
|
|
|
|
|
v => 1.1, |
19
|
|
|
|
|
|
|
summary => 'Pad text to the left until a certain column width', |
20
|
|
|
|
|
|
|
description => <<'_', |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This function can handle text containing wide characters and ANSI escape codes. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Note: to pad to a certain character length instead of column width (note that |
25
|
|
|
|
|
|
|
wide characters like Chinese can have width of more than 1 column in terminal), |
26
|
|
|
|
|
|
|
you can turn of `mb` option even when your text contains wide characters. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
_ |
29
|
|
|
|
|
|
|
args => { |
30
|
|
|
|
|
|
|
%common_args, |
31
|
|
|
|
|
|
|
width => { |
32
|
|
|
|
|
|
|
schema => ['int*', min => 0], |
33
|
|
|
|
|
|
|
req => 1, |
34
|
|
|
|
|
|
|
pos => 0, |
35
|
|
|
|
|
|
|
cmdline_aliases => { w => {} }, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
ansi => { |
38
|
|
|
|
|
|
|
summary => 'Whether to handle ANSI escape codes', |
39
|
|
|
|
|
|
|
schema => ['bool', default => 0], |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
mb => { |
42
|
|
|
|
|
|
|
summary => 'Whether to handle wide characters', |
43
|
|
|
|
|
|
|
schema => ['bool', default => 0], |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
char => { |
46
|
|
|
|
|
|
|
summary => 'Character to use for padding', |
47
|
|
|
|
|
|
|
schema => ['str*', len=>1, default=>' '], |
48
|
|
|
|
|
|
|
description => <<'_', |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Character should have column width of 1. The default is space (ASCII 32). |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
_ |
53
|
|
|
|
|
|
|
cmdline_aliases => { c => {} }, |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
trunc => { |
56
|
|
|
|
|
|
|
summary => 'Whether to truncate text wider than specified width', |
57
|
|
|
|
|
|
|
schema => ['bool', default => 0], |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
}, |
60
|
|
|
|
|
|
|
tags => [qw/itemfunc text/], |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
sub lpad { |
63
|
13
|
|
|
13
|
1
|
54
|
my %args = @_; |
64
|
13
|
|
|
|
|
72
|
Data::Unixish::_pad::_pad("l", %args); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
2
|
|
7
|
sub _lpad_begin { Data::Unixish::_pad::__pad_begin('l', @_) } |
68
|
12
|
|
|
12
|
|
25
|
sub _lpad_item { Data::Unixish::_pad::__pad_item('l', @_) } |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
# ABSTRACT: Pad text to the left until a certain column width |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |