|
NAMEText::Table::More - Generate text table with simple interface and many options VERSIONThis document describes version 0.025 of Text::Table::More (from Perl distribution Text-Table-More), released on 2022-03-27. SYNOPSIS #!perl
use 5.010001;
use strict;
use warnings;
use Text::Table::More qw/generate_table/;
my $rows = [
# header row
["Year",
"Comedy",
"Drama",
"Variety",
"Lead Comedy Actor",
"Lead Drama Actor",
"Lead Comedy Actress",
"Lead Drama Actress"],
# first data row
[1962,
"The Bob Newhart Show (NBC)",
{text=>"The Defenders (CBS)", rowspan=>3}, # each cell can be hashref to specify text (content) as well as attributes
"The Garry Moore Show (CBS)",
{text=>"E. G. Marshall, The Defenders (CBS)", rowspan=>2, colspan=>2},
{text=>"Shirley Booth, Hazel (NBC)", rowspan=>2, colspan=>2}],
# second data row
[1963,
{text=>"The Dick Van Dyke Show (CBS)", rowspan=>2},
"The Andy Williams Show (NBC)"],
# third data row
[1964,
"The Danny Kaye Show (CBS)",
{text=>"Dick Van Dyke, The Dick Van Dyke Show (CBS)", colspan=>2},
{text=>"Mary Tyler Moore, The Dick Van Dyke Show (CBS)", colspan=>2}],
# fourth data row
[1965,
{text=>"four winners (Outstanding Program Achievements in Entertainment)", colspan=>3},
{text=>"five winners (Outstanding Program Achievements in Entertainment)", colspan=>4}],
# fifth data row
[1966,
"The Dick Van Dyke Show (CBS)",
"The Fugitive (ABC)",
"The Andy Williams Show (NBC)",
"Dick Van Dyke, The Dick Van Dyke Show (CBS)",
"Bill Cosby, I Spy (CBS)",
"Mary Tyler Moore, The Dick Van Dyke Show (CBS)",
"Barbara Stanwyck, The Big Valley (CBS)"],
];
binmode STDOUT, "utf8";
print generate_table(
rows => $rows, # required
header_row => 1, # optional, default 0
separate_rows => 1, # optional, default 0
border_style => $ARGV[0] // 'ASCII::SingleLineDoubleAfterHeader', # optional, this is module name in BorderStyle::* namespace, without the prefix
#align => 'left', # optional, default 'left'. can be left/middle/right.
#valign => 'top', # optional, default 'top'. can be top/middle/bottom.
#color => 1, # optional, default 0. turn on support for cell content that contain ANSI color codes.
#wide_char => 1, # optional, default 0. turn on support for wide Unicode characters.
row_attrs => [ # optional, specify per-row attributes
# rownum (0-based int), attributes (hashref)
[0, {align=>'middle', bottom_border=>1}],
],
col_attrs => [ # optional, per-column attributes
# colnum (0-based int), attributes (hashref)
[2, {valign=>'middle'}],
],
#cell_attrs => [ # optional, per-cell attributes
# # rownum (0-based int), colnum (0-based int), attributes (hashref)
# [1, 2, {rowspan=>3}],
# [1, 4, {rowspan=>2, colspan=>2}],
# [1, 5, {rowspan=>2, colspan=>2}],
# [2, 1, {rowspan=>2}],
# [3, 2, {colspan=>2}],
# [3, 3, {colspan=>2}],
# [4, 1, {colspan=>3}],
# [4, 2, {colspan=>4}],
#],
);
will output something like: .------+------------------------------+----------------------+------------------------------+---------------------------------------------+-------------------------+------------------------------------------------+----------------------------------------. | Year | Comedy | Drama | Variety | Lead Comedy Actor | Lead Drama Actor | Lead Comedy Actress | Lead Drama Actress | +======+==============================+======================+==============================+=============================================+=========================+================================================+========================================+ | 1962 | The Bob Newhart Show (NBC) | | The Garry Moore Show (CBS) | E. G. Marshall, The Defenders (CBS) | Shirley Booth, Hazel (NBC) | +------+------------------------------+ +------------------------------+ | | | 1963 | The Dick Van Dyke Show (CBS) | The Defenders (CBS) | The Andy Williams Show (NBC) | | | +------+ | +------------------------------+---------------------------------------------|-------------------------+------------------------------------------------|----------------------------------------+ | 1964 | | | The Danny Kaye Show (CBS) | Dick Van Dyke, The Dick Van Dyke Show (CBS) | Mary Tyler Moore, The Dick Van Dyke Show (CBS) | +------+------------------------------+----------------------+------------------------------+---------------------------------------------|-------------------------+------------------------------------------------|----------------------------------------+ | 1965 | four winners (Outstanding Program Achievements in Entertainment) | five winners (Outstanding Program Achievements in Entertainment) | +------+------------------------------+----------------------+------------------------------+---------------------------------------------+-------------------------+------------------------------------------------+----------------------------------------+ | 1966 | The Dick Van Dyke Show (CBS) | The Fugitive (ABC) | The Andy Williams Show (NBC) | Dick Van Dyke, The Dick Van Dyke Show (CBS) | Bill Cosby, I Spy (CBS) | Mary Tyler Moore, The Dick Van Dyke Show (CBS) | Barbara Stanwyck, The Big Valley (CBS) | `------+------------------------------+----------------------+------------------------------+---------------------------------------------+-------------------------+------------------------------------------------+----------------------------------------' If you set the "border_style" argument to "UTF8::SingleLineBoldHeader": print generate_table(
rows => $rows,
border_style => "UTF8::SingleLineBoldHeader",
...
);
then the output will be something like: ┏━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Year ┃ Comedy ┃ Drama ┃ Variety ┃ Lead Comedy Actor ┃ Lead Drama Actor ┃ Lead Comedy Actress ┃ Lead Drama Actress ┃ ┡━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ 1962 │ The Bob Newhart Show (NBC) │ │ The Garry Moore Show (CBS) │ E. G. Marshall, The Defenders (CBS) │ Shirley Booth, Hazel (NBC) │ ├──────┼──────────────────────────────┤ ├──────────────────────────────┤ │ │ │ 1963 │ The Dick Van Dyke Show (CBS) │ The Defenders (CBS) │ The Andy Williams Show (NBC) │ │ │ ├──────┤ │ ├──────────────────────────────┼─────────────────────────────────────────────│─────────────────────────┼────────────────────────────────────────────────│────────────────────────────────────────┤ │ 1964 │ │ │ The Danny Kaye Show (CBS) │ Dick Van Dyke, The Dick Van Dyke Show (CBS) │ Mary Tyler Moore, The Dick Van Dyke Show (CBS) │ ├──────┼──────────────────────────────┴──────────────────────┴──────────────────────────────┼─────────────────────────────────────────────│─────────────────────────┴────────────────────────────────────────────────│────────────────────────────────────────┤ │ 1965 │ four winners (Outstanding Program Achievements in Entertainment) │ five winners (Outstanding Program Achievements in Entertainment) │ ├──────┼──────────────────────────────┬──────────────────────┬──────────────────────────────┼─────────────────────────────────────────────┬─────────────────────────┬────────────────────────────────────────────────┬────────────────────────────────────────┤ │ 1966 │ The Dick Van Dyke Show (CBS) │ The Fugitive (ABC) │ The Andy Williams Show (NBC) │ Dick Van Dyke, The Dick Van Dyke Show (CBS) │ Bill Cosby, I Spy (CBS) │ Mary Tyler Moore, The Dick Van Dyke Show (CBS) │ Barbara Stanwyck, The Big Valley (CBS) │ └──────┴──────────────────────────────┴──────────────────────┴──────────────────────────────┴─────────────────────────────────────────────┴─────────────────────────┴────────────────────────────────────────────────┴────────────────────────────────────────┘ DESCRIPTIONText::Table::More is yet another text table rendering module. This module uses the simple interface of Text::Table::Tiny with support for more formatting options like column/row spans, border style, per-row/column/cell align/valign/pad/vpad/hpad, and so on. At the time of this writing, Text::Table::More is the only text table module on CPAN that supports rowspans/colspans. Keywords: rowspan, colspan. DECLARED FEATURESFeatures declared by this module: From feature set PerlTroveFeatures from feature set PerlTrove declared by this module:
From feature set TextTableFeatures from feature set TextTable declared by this module:
For more details on module features, see Module::Features. PER-ROW ATTRIBUTES
PER-COLUMN ATTRIBUTES
PER-CELL ATTRIBUTES
FUNCTIONSgenerate_tableUsage: my $table_str = generate_table(%args); Arguments:
FAQCan I have multiple header rows?Yes, by setting "header_row" option to 2 or whatever number of header rows you have. See example script multirow-header.pl in this distribution. ENVIRONMENTPERL_TEXT_TABLE_MORE_BORDER_STYLEString. Used to set the default for the "border_style" option. Has higher precedence than "BORDER_STYLE". BORDER_STYLEString. Used to set the default for the "border_style" option. Has lower precedence than "PERL_TEXT_TABLE_MORE_BORDER_STYLE". HOMEPAGEPlease visit the project's homepage at <https://metacpan.org/release/Text-Table-More>. SOURCESource repository is at <https://github.com/perlancar/perl-Text-Table-More>. SEE ALSOText::ANSITable also offers lots of formatting options, but currently lacks support for rowspan/colspan. It also uses an OO interface and has features I never use: hiding rows and selecting display columns different from declared columns. I currently plan to actively develop Text::Table::More instead of Text::ANSITable, but we'll see. Acme::CPANModules::TextTable contains a comparison and benchmark for modules that generate text table. HTML <TABLE> element, <https://www.w3.org/TR/2014/REC-html5-20141028/tabular-data.html>, <https://www.w3.org/html/wiki/Elements/table> AUTHORperlancar <perlancar@cpan.org> CONTRIBUTINGTo contribute, you can send patches by email/via RT, or send pull requests on GitHub. Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via: % prove -l If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla plugin and/or Pod::Weaver::Plugin. Any additional steps required beyond that are considered a bug and can be reported to me. COPYRIGHT AND LICENSEThis software is copyright (c) 2022, 2021 by perlancar <perlancar@cpan.org>. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. BUGSPlease report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=Text-Table-More> When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
|