forked from agapoff/Lumper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.pm
72 lines (60 loc) · 1.6 KB
/
display.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package display;
use strict;
use warnings;
use Data::Dumper;
sub new {
my ($class, %args) = @_;
return bless { %args }, $class;
}
our sub printTitle {
my $self = shift;
my $text = shift;
print generateTitle($text);
}
sub generateTitle {
my $text = shift;
my $textLength = length $text;
return "\n".generateDelimiterPart($textLength).
" $text ".
generateDelimiterPart($textLength + $textLength % 2)."\n";
}
# Returns one half of a delimiter for the title
sub generateDelimiterPart {
my $textLength = shift;
my $halfTitleLength = 76 / 2;
my $delimiter = "--------------------".
"--------------------".
"--------------------";
# Reduce '-' symbols based on title length + 2 spaces
# on the trim only for one side of title.
return substr $delimiter, 0,
$halfTitleLength -
int(($textLength + 2) / 2);
}
our sub printColumnWidth {
my $self = shift;
my $text = shift;
my $w = shift;
my $len = length($text) || 0;
if ($len < ($w * 8)) {
print(($text || "").("\t" x ($w - int($len / 8))));
} else {
print(substr($text, 0, ($w * 8)-4)."...\t");
}
}
our sub printColumnAligned {
my $self = shift;
my $text = shift;
if (length($text) < 8) {
print $text."\t\t\t\t";
} elsif (length($text) < 16) {
print $text."\t\t\t";
} elsif (length($text) < 24) {
print $text."\t\t";
} elsif (length($text) < 32) {
print $text."\t";
} else {
print substr ($text, 0, 32-4)."...\t";
}
}
1;