line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::ANSITable; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13375
|
use 5.14.0; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
399
|
use Term::Size 'chars'; |
|
1
|
|
|
|
|
2185
|
|
|
1
|
|
|
|
|
442
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Term::ANSITable - Tool for drawing and redrawing tables on term! |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.010100 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.010100'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 new |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Constructor |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
30
|
0
|
|
|
|
|
|
require Text::ANSITable; |
31
|
0
|
|
|
|
|
|
require Term::Cap; |
32
|
0
|
|
|
|
|
|
my $self = { |
33
|
|
|
|
|
|
|
_table => Text::ANSITable->new(@_), |
34
|
|
|
|
|
|
|
_terminal => Tgetent Term::Cap { TERM => 'cygwin', OSPEED => 9600 }, |
35
|
|
|
|
|
|
|
}; |
36
|
0
|
|
|
|
|
|
$self->{_terminal}->Trequire("up"); # move cursor up |
37
|
0
|
|
|
|
|
|
$self->{_sig_up} = $self->{_terminal}->Tputs("up"); |
38
|
0
|
|
|
|
|
|
$self->{_drawer} = Term::ANSITable::Draw->new; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
bless $self, $class; |
41
|
0
|
|
|
|
|
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 table |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Getter/Setter for internal hash key _table. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub table { |
51
|
0
|
0
|
|
0
|
1
|
|
return $_[0]->{_table} unless $_[1]; |
52
|
0
|
|
|
|
|
|
$_[0]->{_table} = $_[1]; |
53
|
0
|
|
|
|
|
|
return $_[0]->{_table}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 rows |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Get or set rows from Text::ANSITable object. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub rows { |
63
|
0
|
0
|
|
0
|
1
|
|
return $_[0]->table->{rows} unless $_[1]; |
64
|
0
|
|
|
|
|
|
$_[0]->table->{rows} = $_[1]; |
65
|
0
|
|
|
|
|
|
return $_[0]->table->{rows}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 drawer |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Get or set a custom drawer instead of print. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub drawer { |
75
|
0
|
0
|
|
0
|
1
|
|
return $_[0]->{_drawer} unless $_[1]; |
76
|
0
|
|
|
|
|
|
$_[0]->{_drawer} = $_[1]; |
77
|
0
|
|
|
|
|
|
return $_[0]->{_drawer}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 add_row |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Add row to Text::ANSITable object. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub add_row { |
87
|
0
|
|
|
0
|
1
|
|
my ( $self, $row ) = @_; |
88
|
0
|
|
|
|
|
|
$self->table->add_row($row); |
89
|
0
|
|
|
|
|
|
return $self; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 draw($prepare2refresh) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Draw table on term and go back to first line of row for redrawing |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=over 4 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
prepare2refresh: if is set term will go back to the first line |
101
|
|
|
|
|
|
|
and it will be overwritten on any print afer that. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub draw { |
106
|
0
|
|
|
0
|
1
|
|
my ( $self, $prepare4refresh ) = @_; |
107
|
0
|
|
|
|
|
|
my @lines = split "\n", $self->table->draw; |
108
|
0
|
|
|
|
|
|
my $chars = chars * STDOUT { IO }; |
109
|
0
|
|
|
|
|
|
foreach (@lines) { |
110
|
0
|
|
|
|
|
|
my $length = length($_); |
111
|
0
|
0
|
|
|
|
|
$self->drawer->print( $_, ( $chars > $length ) ? '' x ( $chars - $length ) : '', $/ ); |
112
|
|
|
|
|
|
|
} |
113
|
0
|
0
|
|
|
|
|
return if ( !$prepare4refresh ); |
114
|
0
|
|
|
|
|
|
$self->drawer->print( $self->{_sig_up} ) foreach ( 1 .. scalar @lines ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=back |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 refresh_table |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Grep all empty rows from table. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub refresh_table { |
126
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
127
|
0
|
|
|
|
|
|
$self->rows( [ grep { @$_ } @{ $self->rows } ] ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return $self; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 Term::ANSITable::Draw |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Internal drawing package |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
package Term::ANSITable::Draw; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 new |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Constructor |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub new { |
146
|
0
|
|
|
0
|
|
|
my $class = shift; |
147
|
0
|
|
|
|
|
|
return bless {}, $class; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 new |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Simple print to stdout. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub print { |
157
|
0
|
|
|
0
|
|
|
my $self = shift; |
158
|
0
|
|
|
|
|
|
print @_; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; # End of Term::ANSITable |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
__END__ |