Acme-CPANModules-TextTable
view release on metacpan or search on metacpan
lib/Acme/CPANModules/TextTable.pm view on Meta::CPAN
package Acme::CPANModules::TextTable;
use 5.010001;
use strict;
use warnings;
use utf8;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2023-10-31'; # DATE
our $DIST = 'Acme-CPANModules-TextTable'; # DIST
our $VERSION = '0.016'; # VERSION
sub _make_table {
my ($cols, $rows, $celltext) = @_;
my $res = [];
push @$res, [];
for (0..$cols-1) { $res->[0][$_] = "col" . ($_+1) }
for my $row (1..$rows) {
push @$res, [ map { $celltext // "row$row.$_" } 1..$cols ];
}
$res;
}
our $LIST = {
summary => 'List of modules that generate text tables',
description => <<'_',
Currently excluded from this list are:
- <pm:Text::SimpleTable::AutoWidth> (wrapper to <pm:Text::SimpleTable>);
- <pm:Text::ASCIITable::EasyTable> (wrapper to <pm:Text::ASCIITable>);
_
entry_features => {
wide_char => {summary => 'Whether the use of wide characters (e.g. Kanji) in cells does not cause the table to be misaligned'},
color_data => {summary => 'Whether module supports ANSI colors (i.e. text with ANSI color codes can still be aligned properly)'},
multiline_data => {summary => 'Whether module supports aligning data cells that contain newlines'},
box_char => {summary => 'Whether module can utilize box-drawing characters'},
custom_border => {summary => 'Whether module allows customizing border in some way'},
align_row => {summary => "Whether module supports aligning text horizontally in a row (left/right/middle)"},
align_column => {summary => "Whether module supports aligning text horizontally in a column (left/right/middle)"},
align_cell => {summary => "Whether module supports aligning text horizontally in individual cells (left/right/middle)"},
valign_row => {summary => "Whether module supports aligning text vertically in a row (top/bottom/middle)"},
valign_column => {summary => "Whether module supports aligning text vertically in a column (top/bottom/middle)"},
valign_cell => {summary => "Whether module supports aligning text vertically in individual cells (top/bottom/middle)"},
rowspan => {summary => "Whether module supports row spans"},
colspan => {summary => "Whether module supports column spans"},
custom_color => {summary => 'Whether the module produces colored table and supports customizing color in some way'},
color_theme => {summary => 'Whether the module supports color theme/scheme'},
speed => {summary => "Rendering speed", schema=>'str*'},
column_width => {summary => 'Whether module allows setting the width of columns'},
per_column_width => {summary => 'Whether module allows setting column width on a per-column basis'},
row_height => {summary => 'Whether module allows setting the height of rows'},
per_row_height => {summary => 'Whether module allows setting row height on a per-row basis'},
pad => {summary => 'Whether module allows customizing cell horizontal padding'},
vpad => {summary => 'Whether module allows customizing cell vertical padding'},
},
entries => [
lib/Acme/CPANModules/TextTable.pm view on Meta::CPAN
rowspan => 0,
wide_char_data => 1,
speed => "slow",
},
},
{
module => 'Text::Table::Manifold',
description => <<'_',
Two main features of this module is per-column aligning and wide character
support. This module, aside from doing its rendering, can also be told to pass
rendering to HTML, CSV, or other text table module like
<pm:Text::UnicodeBox::Table>); so in this way it is similar to
<pm:Text::Table::Any>.
_
bench_code => sub {
my ($table) = @_;
my $t = Text::Table::Manifold->new;
$t->headers($table->[0]);
$t->data([ @{$table}[1 .. $#{$table}] ]);
join("\n", @{$t->render(padding => 1)}) . "\n";
},
features => {
align_cell => 0,
align_column => 1,
box_char => undef, # ?
color_data => 1,
color_theme => 0,
colspan => 0,
custom_border => {value=>0, summary=>"But this module can pass rendering to other module like Text::UnicodeBox::Table"},
custom_color => 0,
multiline_data => 0,
rowspan => 0,
wide_char_data => 1,
},
},
{
module => 'Text::ANSITable',
description => <<'_',
This 2013 project was my take in creating a text table module that can handle
color, multiline text, wide characters. I also threw in various formatting
options, e.g. per-column/row/cell align/valign/pad/vpad, conditional formatting,
and so on. I even added a couple of features I never used: hiding rows and
specifying columns to display which can be in different order from the original
specified columns or can contain the same original columns multiple times. I
think this module offers the most formatting options on CPAN.
In early 2021, I needed colspan/rowspan and I implemented this in a new module:
<pm:Text::Table::Span> (later renamed to <pm:Text::Table::More>). I plan to add
this feature too to Text::ANSITable, but in the meantime I'm also adding more
formatting options which I need to Text::Table::More.
_
bench_code => sub {
my ($table) = @_;
my $t = Text::ANSITable->new(
use_utf8 => 0,
use_box_chars => 0,
use_color => 0,
columns => $table->[0],
border_style => 'ASCII::SingleLine',
);
$t->add_row($table->[$_]) for 1..@$table-1;
$t->draw;
},
features => {
align_cell => 1,
align_column => 1,
align_row => 1,
box_char => 1,
color_data => 1,
color_theme => 1,
colspan => 0,
column_width => 1,
custom_border => 1,
custom_color => 1,
multiline_data => 1,
pad => 1,
per_column_width => 1,
per_row_height => 1,
row_height => 1,
rowspan => 0,
speed => "slow",
valign_cell => 1,
valign_column => 1,
valign_row => 1,
vpad => 1,
wide_char_data => 1,
},
},
{
module => 'Text::ASCIITable',
bench_code => sub {
my ($table) = @_;
my $t = Text::ASCIITable->new();
$t->setCols(@{ $table->[0] });
$t->addRow(@{ $table->[$_] }) for 1..@$table-1;
"$t";
},
features => {
wide_char_data => 0,
color_data => 0,
box_char => 0,
multiline_data => 1,
},
},
{
module => 'Text::FormatTable',
bench_code => sub {
my ($table) = @_;
my $t = Text::FormatTable->new(join('|', ('l') x @{ $table->[0] }));
$t->head(@{ $table->[0] });
$t->row(@{ $table->[$_] }) for 1..@$table-1;
$t->render;
},
features => {
( run in 2.546 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )