exodist / Term-Table

Format a header and rows into a table
Other
6 stars 9 forks source link

NAME

Term::Table - Format a header and rows into a table

DESCRIPTION

This is used by some failing tests to provide diagnostics about what has gone wrong. This module is able to format rows of data into tables.

SYNOPSIS

use Term::Table;

my $table = Term::Table->new(
    max_width      => 80,    # Defaults to terminal size
    pad            => 4,     # Extra padding between table and max-width (defaults to 4)
    allow_overflow => 0,     # Default is 0, when off an exception will be thrown if the table is too big
    collapse       => 1,     # Do not show empty columns

    header => ['name', 'age', 'hair color'],
    rows   => [
        ['Fred Flintstone',  2000000, 'black'],
        ['Wilma Flintstone', 1999995, 'red'],
        ...
    ],
);

say $_ for $table->render;

This prints a table like this:

+------------------+---------+------------+
| name             | age     | hair color |
+------------------+---------+------------+
| Fred Flintstone  | 2000000 | black      |
| Wilma Flintstone | 1999995 | red        |
| ...              | ...     | ...        |
+------------------+---------+------------+

INTERFACE

use Term::Table;
my $table = Term::Table->new(...);

OPTIONS

NOTE ON UNICODE/WIDE CHARACTERS

Some unicode characters, such as (U+5A67) are wider than others. These will render just fine if you use utf8; as necessary, and Unicode::GCString is installed, however if the module is not installed there will be anomalies in the table:

+-----+-----+---+
| a   | b   | c |
+-----+-----+---+
| 婧 | x   | y |
| x   | y   | z |
| x   | 婧 | z |
+-----+-----+---+

SOURCE

The source code repository for Term-Table can be found at https://github.com/exodist/Term-Table/.

MAINTAINERS

AUTHORS

COPYRIGHT

Copyright 2016 Chad Granum exodist@cpan.org.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See https://dev.perl.org/licenses/