14 May 2022 13:29:45 UTC
- Distribution: Term-TablePrint
- Module version: 0.151
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (632 / 0 / 1)
- KwaliteeBus factor: 1
- 9.31% Coverage
- License: perl_5
- Perl: v5.10.0
- Activity24 month
- Download (23.87KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
- ERROR HANDLING
- SEE ALSO
- LICENSE AND COPYRIGHT
Term::TablePrint - Print a table to the terminal and browse it interactively.
my $table = [ [ 'id', 'name' ], [ 1, 'Ruth' ], [ 2, 'John' ], [ 3, 'Mark' ], [ 4, 'Nena' ], ]; use Term::TablePrint qw( print_table ); print_table( $table ); # or OO style: use Term::TablePrint; my $pt = Term::TablePrint->new(); $pt->print_table( $table );
print_tableshows a table and lets the user interactively browse it. It provides a cursor which highlights the row on which it is located. The user can scroll through the table with the different cursor keys - see "KEYS".
If the table has more rows than the terminal, the table is divided up on as many pages as needed automatically. If the cursor reaches the end of a page, the next page is shown automatically until the last page is reached. Also if the cursor reaches the topmost line, the previous page is shown automatically if it is not already the first one.
If the terminal is too narrow to print the table, the columns are adjusted to the available width automatically.
If the option "table_expand" is enabled and a row is selected with
Return, each column of that row is output in its own line preceded by the column name.
Keys to move around:
ArrowDownkey (or the
jkey) to move down and the
ArrowUpkey (or the
kkey) to move up.
Ctrl-P) to go to the previous page, the
Ctrl-N) to go to the next page.
Insertkey to go back 10 pages, the
Deletekey to go forward 10 pages.
Ctrl-A) to jump to the first row of the table, the
Ctrl-E) to jump to the last row of the table.
If table_expand is set to
Returnkey closes the table if the cursor is on the first row.
If table_expand is enabled and the cursor is on the first row, pressing
Returnthree times in succession closes the table. If the cursor is auto-jumped to the first row, it is required only one
Returnto close the table.
If the cursor is not on the first row:
with the option table_expand disabled the cursor jumps to the table head if
with the option table_expand enabled each column of the selected row is output in its own line preceded by the column name if
Returnis pressed. Another
Returncloses this output and goes back to the table output. If a row is selected twice in succession, the pointer jumps to the first row.
If the size of the window has changed, the screen is rewritten as soon as the user presses a key.
Ctrl-Fopens a prompt. A regular expression is expected as input. This enables one to only display rows where at least one column matches the entered pattern. See option "search".
For the output on the screen the table elements are modified. All the modifications are made on a copy of the original table data.
If an element is not defined the value from the option undef is assigned to that element.
Each character tabulation (
\t) is replaces with a space.
Vertical tabulations (
\v+) are squashed to two spaces.
Code points from the ranges of
If the option squash_spaces is enabled leading and trailing spaces are removed and multiple consecutive spaces are squashed to a single space.
If an element looks like a number it is left-justified, else it is right-justified.
If the terminal width is not wide enough to display all columns:
First, if the option trunc_fract_first is enabled and if there are numbers that have a fraction, the fraction is truncated up to two decimal places.
Then columns wider than min_col_width are trimmed. See option "min_col_width".
If it is still required to lower the row width all columns are trimmed until they fit into the terminal.
newmethod returns a
Term::TablePrintobject. As an argument it can be passed a reference to a hash which holds the options - the available options are listed in "OPTIONS".
my $tp = Term::TablePrint->new( \%options );
print_tablemethod prints the table passed with the first argument.
$tp->print_table( $array_ref, \%options );
The first argument is a reference to an array of arrays. The first array of these arrays holds the column names. The following arrays are the table rows where the elements are the field values.
As a second and optional argument a hash reference can be passed which holds the options - the available options are listed in "OPTIONS".
print_tablesubroutine prints the table passed with the first argument.
print_table( $array_ref, \%options );
print_tabletakes the same arguments as the method "print_table".
If binary_filter is set to 1, "BNRY" is printed instead of arbitrary binary data.
If the data matches the repexp
/[\x00-\x08\x0B-\x0C\x0E-\x1F]/, it is considered arbitrary binary data.
Printing arbitrary binary data could break the output.
This option has only meaning if the operating system is MSWin32.
If the OS is MSWin32, Win32::Console::ANSI is used. By default
Win32::Console::ANSIconverts the characters from Windows code page to DOS code page (the so-called ANSI to OEM conversion). This conversation is disabled by default in
Term::Choosebut one can enable it by setting this option.
Setting this option to
1enables the codepage mapping offered by Win32::Console::ANSI.
0 - disable automatic codepage mapping
1 - keep automatic codepage mapping
Setting color to
1enables the support for color and text formatting escape sequences except for the current selected element. If set to
2, also for the current selected element the color support is enabled (inverted colors).
Set the decimal separator. Numbers with a decimal separator are formatted as number if this option is set to the right value.
Allowed values: a character with a print width of
1. If an invalid values is passed, decimal_separator falls back to the default value.
Default: . (dot)
If set (string), footer is added in the bottom line to the page number. It is up to the user to add leading and trailing separators.
If a footer string is passed with this option, the option page is automatically set to
Expects as its value a string. The info text is printed above the prompt string.
Set the maximum number of used table rows. The used table rows are kept in memory.
To disable the automatic limit set max_rows to 0.
If the number of table rows is equal to or higher than max_rows, the last row of the output tells that the limit has been reached.
The columns with a width below or equal min_col_width are only trimmed, if it is still required to lower the row width despite all columns wider than min_col_width have been trimmed to min_col_width.
Set the mouse mode (see option
mousein "OPTIONS" in Term::Choose).
Set the progress bar threshold. If the number of fields (rows x columns) is higher than the threshold, a progress bar is shown while preparing the data for the output.
String displayed above the table.
Set the behavior of
0 - off
1 - case-insensitive search
2 - case-sensitive search
Ctrl-Fis pressed and a regexp is entered, the regexp is appended to the end of the footer.
If squash_spaces is enabled, consecutive spaces are squashed to one space and leading and trailing spaces are removed.
Set the number of spaces between columns.
If the option table_expand is enabled and
Returnis pressed, the selected table row is printed with each column in its own line. Exception: if the cursor auto-jumped to the first row, the first row will not be expanded.
If table_expand is set to 0, the cursor jumps to the to first row (if not already there) when
0 - off
1 - on
If the terminal width is not wide enough and this option is enabled, the first step to reduce the width of the columns is to truncate the fraction part of numbers to 2 decimal places.
Set the string that will be shown on the screen instead of an undefined field.
Default: "" (empty string)
if an invalid number of arguments is passed.
if an invalid argument is passed.
if an unknown option name is passed.
if an invalid option value is passed.
Requires Perl version 5.10.0 or greater.
print_tableexpects decoded strings.
For a correct output it is required to set an encoding layer for
STDOUTmatching the terminal's character set.
It is required a terminal that uses a monospaced font which supports the printed characters.
You can find documentation for this module with the perldoc command.
Matthäus Kiem <firstname.lastname@example.org>
Copyright 2013-2022 Matthäus Kiem.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For details, see the full text of the licenses in the file LICENSE.
Module Install Instructions
To install Term::TablePrint, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Term::TablePrint
For more information on module installation, please visit the detailed CPAN module installation guide.