line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Unixish::lpad; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
3611
|
use 5.010; |
|
7
|
|
|
|
|
28
|
|
4
|
7
|
|
|
7
|
|
3168
|
use locale; |
|
7
|
|
|
|
|
4179
|
|
|
7
|
|
|
|
|
40
|
|
5
|
7
|
|
|
7
|
|
258
|
use strict; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
145
|
|
6
|
7
|
|
|
7
|
|
382
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
7
|
|
|
|
|
19947
|
|
|
7
|
|
|
|
|
34
|
|
7
|
7
|
|
|
7
|
|
4297
|
use warnings; |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
178
|
|
8
|
|
|
|
|
|
|
#use Log::Any '$log'; |
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
3216
|
use Data::Unixish::_pad; |
|
7
|
|
|
|
|
27
|
|
|
7
|
|
|
|
|
294
|
|
11
|
7
|
|
|
7
|
|
439
|
use Data::Unixish::Util qw(%common_args); |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
2029
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.572'; # 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
|
56
|
my %args = @_; |
64
|
13
|
|
|
|
|
67
|
Data::Unixish::_pad::_pad("l", %args); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
2
|
|
6
|
sub _lpad_begin { Data::Unixish::_pad::__pad_begin('l', @_) } |
68
|
12
|
|
|
12
|
|
18
|
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__ |