Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "print_table"

Title:Formats and prints a table on the terminal screen
Rating:Not rated. Create the first rating!
Latest version:0.0.5
SHA1 sum:feb183df501e2e17dcf8323ce396c5f4156fc7be
Author:Jozef Geurts http://joostgeurts.com/
Home page:https://github.com/grsjst/print_table

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
0.0.58a0cb68318ab1d13e6b84835639cd6e9079400241https://github.com/grsjst/print_table.git
feb183df501e2e17dcf8323ce396c5f4156fc7be1https://github.com/grsjst/print_table.git

Formats and prints a table on the terminal screen (print_table)

print_table is a Pack for SWI-Prolog (https://www.swi-prolog.org/) that formats and prints a Table on the terminal sreen .

These are few examples:

?- Data = [_{a:11,b:0.001,c:13},_{a:21,b:2.12,c:23},_{a:31,b:12.1111,c:33}],                                                             print_table(Data,[b,c,a],_{b:_{align:right,format:"~2f"}},"Table",mysql,30).

%       Table (3 records)
%      +-------+----+----+
%      |   b   | c  | a  |
%      +-------+----+----+
%      |  0.00 | 13 | 11 |
%      |  2.12 | 23 | 21 |
%      | 12.11 | 33 | 31 |
%      +-------+----+----+
?- Data = [_{bla:"bla, bla, bla",duh:"duh!",ehm:"ehm..."},_{bla:"bladibla",duh:"di di duh",ehm:"ehmmmm ehhhhmmmm"}],
                        print_table(Data,[ehm,bla,duh],_{},"Table",unicode,40).
%            Table (2 records)
%     ┌───────────┌──────────┌───────┐
%     │    ehm    │   bla    │  duh  │
%     └───────────┼──────────┼───────┘
%     │ ehm...    │ bla,     │ duh!  │
%     │           │ bla, bla │       │
%     └───────────┼──────────┼───────┘
%     │ ehmmmm    │ bladibla │ di di │
%     │ ehhhhmmmm │          │ duh   │
%     └───────────┴──────────┴───────┘

Installation

pack_install(print_table).

Usage

In your SWIPL programme include the directive:

:- use_module(print_table).

Examples

In the file `examples\demo.pl` a number of demos are provided

:- ['./examples/demo.pl']. 	% loads the demo
:- test_table1(a).			% runs demo a
:- test_table1(b).			% runs demo b

Documentation

See the pldoc documentation for additional information

Files

prolog/print_table.pl 		- the print_table module
prolog/wrap_text.pl 		- wraps an arbitrary text into lines that do not exceed the specified length
examples/demo.pl 		- a number of examples
tests/test_wrap.pl 		- unit tests for the wrap_text module

Related and Issues

Similar to print_table, the pack clitable (see https://www.swi-prolog.org/pack/list?p=clitable) allows for pretty printing a Table structure. However, it doesn't format the table within the available space.

The performace is influenced by the number of rows in the table.

Contents of pack "print_table"

Pack contains 8 files holding a total of 43.6K bytes.