Debian Codegraph @

README

raw
1 NAME
2
3 Term::Table - Format a header and rows into a table
4
5 DESCRIPTION
6
7 This is used by some failing tests to provide diagnostics about what
8 has gone wrong. This module is able to format rows of data into tables.
9
10 SYNOPSIS
11
12 use Term::Table;
13
14 my $table = Term::Table->new(
15 max_width => 80, # Defaults to terminal size
16 pad => 4, # Extra padding between table and max-width (defaults to 4)
17 allow_overflow => 0, # Default is 0, when off an exception will be thrown if the table is too big
18 collapse => 1, # Do not show empty columns
19
20 header => ['name', 'age', 'hair color'],
21 rows => [
22 ['Fred Flintstone', 2000000, 'black'],
23 ['Wilma Flintstone', 1999995, 'red'],
24 ...
25 ],
26 );
27
28 say $_ for $table->render;
29
30 This prints a table like this:
31
32 +------------------+---------+------------+
33 | name | age | hair color |
34 +------------------+---------+------------+
35 | Fred Flintstone | 2000000 | black |
36 | Wilma Flintstone | 1999995 | red |
37 | ... | ... | ... |
38 +------------------+---------+------------+
39
40 INTERFACE
41
42 use Term::Table;
43 my $table = Term::Table->new(...);
44
45 OPTIONS
46
47 header => [ ... ]
48
49 If you want a header specify it here. This takes an arrayref with
50 each columns heading.
51
52 rows => [ [...], [...], ... ]
53
54 This should be an arrayref containing an arrayref per row.
55
56 collapse => $bool
57
58 Use this if you want to hide empty columns, that is any column that
59 has no data in any row. Having a header for the column will not
60 effect collapse.
61
62 max_width => $num
63
64 Set the maximum width of the table, the table may not be this big,
65 but it will be no bigger. If none is specified it will attempt to
66 find the width of your terminal and use that, otherwise it falls back
67 to the terminal width or 80.
68
69 pad => $num
70
71 Defaults to 4, extra padding for row width calculations. Default is
72 for legacy support. Set this to 0 to turn padding off.
73
74 allow_overflow => $bool
75
76 Defaults to 0. If this is off then an exception will be thrown if the
77 table cannot be made to fit inside the max-width. If this is set to 1
78 then the table will be rendered anyway, larger than max-width, if it
79 is not possible to stay within the max-width. In other words this
80 turns max-width from a hard-limit to a soft recommendation.
81
82 sanitize => $bool
83
84 This will sanitize all the data in the table such that newlines,
85 control characters, and all whitespace except for ASCII 20 ' ' are
86 replaced with escape sequences. This prevents newlines, tabs, and
87 similar whitespace from disrupting the table.
88
89 Note: newlines are marked as \n, but a newline is also inserted into
90 the data so that it typically displays in a way that is useful to
91 humans.
92
93 Example:
94
95 my $field = "foo\nbar\nbaz\n";
96
97 print join "\n" => table(
98 sanitize => 1,
99 rows => [
100 [$field, 'col2' ],
101 ['row2 col1', 'row2 col2']
102 ]
103 );
104
105 Prints:
106
107 +-----------------+-----------+
108 | foo\n | col2 |
109 | bar\n | |
110 | baz\n | |
111 | | |
112 | row2 col1 | row2 col2 |
113 +-----------------+-----------+
114
115 So it marks the newlines by inserting the escape sequence, but it
116 also shows the data across as many lines as it would normally
117 display.
118
119 mark_tail => $bool
120
121 This will replace the last whitespace character of any trailing
122 whitespace with its escape sequence. This makes it easier to notice
123 trailing whitespace when comparing values.
124
125 show_header => $bool
126
127 Set this to false to hide the header. This defaults to true if the
128 header is set, false if no header is provided.
129
130 auto_columns => $bool
131
132 Set this to true to automatically add columns that are not named in
133 the header. This defaults to false if a header is provided, and
134 defaults to true when there is no header.
135
136 no_collapse => [ $col_num_a, $col_num_b, ... ]
137
138 no_collapse => [ $col_name_a, $col_name_b, ... ]
139
140 no_collapse => { $col_num_a => 1, $col_num_b => 1, ... }
141
142 no_collapse => { $col_name_a => 1, $col_name_b => 1, ... }
143
144 Specify (by number and/or name) columns that should not be removed
145 when empty. The 'name' form only works when a header is specified.
146 There is currently no protection to insure that names you specify are
147 actually in the header, invalid names are ignored, patches to fix
148 this will be happily accepted.
149
150 NOTE ON UNICODE/WIDE CHARACTERS
151
152 Some unicode characters, such as 婧 (U+5A67) are wider than others.
153 These will render just fine if you use utf8; as necessary, and
154 Unicode::GCString is installed, however if the module is not installed
155 there will be anomalies in the table:
156
157 +-----+-----+---+
158 | a | b | c |
159 +-----+-----+---+
160 | 婧 | x | y |
161 | x | y | z |
162 | x | 婧 | z |
163 +-----+-----+---+
164
165 SOURCE
166
167 The source code repository for Term-Table can be found at
168 https://github.com/exodist/Term-Table/.
169
170 MAINTAINERS
171
172 Chad Granum <[email protected]>
173
174 AUTHORS
175
176 Chad Granum <[email protected]>
177
178 COPYRIGHT
179
180 Copyright 2016 Chad Granum <[email protected]>.
181
182 This program is free software; you can redistribute it and/or modify it
183 under the same terms as Perl itself.
184
185 See https://dev.perl.org/licenses/
186