line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Unixish::lpad; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
2925
|
use 5.010; |
|
7
|
|
|
|
|
24
|
|
4
|
7
|
|
|
7
|
|
2524
|
use locale; |
|
7
|
|
|
|
|
3404
|
|
|
7
|
|
|
|
|
34
|
|
5
|
7
|
|
|
7
|
|
209
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
123
|
|
6
|
7
|
|
|
7
|
|
344
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
7
|
|
|
|
|
19613
|
|
|
7
|
|
|
|
|
37
|
|
7
|
7
|
|
|
7
|
|
3771
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
146
|
|
8
|
|
|
|
|
|
|
#use Log::Any '$log'; |
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
2732
|
use Data::Unixish::_pad; |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
243
|
|
11
|
7
|
|
|
7
|
|
415
|
use Data::Unixish::Util qw(%common_args); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
1747
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.570'; # 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
|
47
|
my %args = @_; |
64
|
13
|
|
|
|
|
55
|
Data::Unixish::_pad::_pad("l", %args); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
2
|
|
6
|
sub _lpad_begin { Data::Unixish::_pad::__pad_begin('l', @_) } |
68
|
12
|
|
|
12
|
|
22
|
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__ |