- ASCII Table Versions
- ASCII Tabel Version 2 Overview
- Version 2 Examples
- A table with four columns
- Text alignment in columns - left, right, center
- Text alignment in columns - justified
- Conditional Line Breaks (CRLF, CR, LF, <br> and <br/>
- Using Conditional Line Breaks to create lists
- Column padding
- Column spanning
- Rule styles
- Width with table width and evenly distributed column witdh
- Width with fixed width per column
- Width using longest word per column, with 0, standard, and individual padding
- Width using longest word per column with minimum column width and different options
- Width using longest word per column with maximum column width and different options
- Width using longest line per column
- Width using longest line per column with minimum column width (column 1)
- Width using longest line per column with maximum column width (column 5)
- Padding Characters
- Table Theme
- Table Theme with no Borders for Paragraph Formatting
- AsciiList lists in a table with and without column padding
- URI, URL and URN content
The tables allows for various degrees of flexibility for number of columns, column width, automated line wrapping, column spanning and themes for tables and table rows.
Current release is 0.2.5. All releases are on Maven Central.
This blog post explains how to get UTF-8 support in the whole tool chain blog on UTF-8. Updates will be at here SKB Wiki on UTF-8.
The following table versions are in the project:
-
V1 - first generation table implementation with limited features and theme support. The code for this version is frozen and only bug fixes fill apply.
-
V2 - second generation table implementation. This code is under active development and will progress.
This table implementation provides the following features:
-
flexible columns - the number of columns in the first content row determine the columns the table supports
-
various methods to define column width - overall table width with evenly distributed columns, fixed column width, others can be added if required
-
text alignment in columns - left, right, center and two version of justified, configurable per column
-
automated text wrapping in columns with automated adjustment of adjacent columns
-
padding of columns - number of padding characters before and after text in columns
-
spanning columns - a column spanning multiple columns
-
renders to render - a table is rendered by a separate object, called the renderer, with a standard renderer provided
-
table row themes - allow to define a theme for a table for for content rows and several rule types, large set of standard themes are defined
-
table themes - allow to define a theme for a complete table, some standard themes are provided
-
one content row - a standard row for content with alignment and padding
-
rule rows with 2 different types - rules are horizontal delimiters, e.g. lines. Rules can be top (first in the table), mid (anywhere in the middle) or bottom (last in the table). Rules can be normal or strong (e.g. extra thick line).
The main concepts are: table, row, renderer, theme, and rendered table.
A table is a collection of rows.
The package provides a single implementation of the table V2_AsciiTable
.
The implementation allows to add rows and set some general configuration, such as default padding.
A row is either a rule (horizontal delimiter) or a content row (then with columns of content). The terminology used here is rule for a rule row and row for a content row.
The row package defines an interface for a row V2_Row
.
It also provides two implementations: ContentRow
for content rows
and RuleRow
for rules.
Both of those row classes are supported by the provided renderer.
Other row classes can be added if required, but then special renderers need to provided as well.
A renderer is taking a finalized (filled) table producing a rendered version of it.
The render package defines a general interface V2_TableRenderer
and a default implementation V2_AsciiTableRenderer
.
Other renderers can be created by implementing the interface.
A renderer is taking a V2_Width
object for calculating the width of columns.
This object is defined as an interface with several implementations provided for different ways of defining column width.
More of those width object can be defined as required.
A table can be rendered multiple times by any render object, i.e. the underlying original table will not be changed by the renderer.
The renderer is building a list of so called processed rows ProcessedRow
, which old all render-specific settings.
This feature, render a table any time with any renderer and re-render a table with the same renderer, allows to change settings such as width, themes, padding character. It also allows to render a table for different output, such as HTML or LaTeX, of such renderers where provided.
A theme is either a table theme or a row theme used by the renderer to generate the output.
The theme package defines both as interfaces: V2_TableTheme
and V2_RowTheme
.
It also provides builders to generate theme objects: V2_TableThemeBuilder
and V2_RowThemeBuilder
.
The builders allow for an easy creation of new themes as required.
The themes are supported by underlying abstract implementation of their respective interfaces: AbstractTableTheme
and AbstractRowTheme
.
A large number of row themes are defined in V2_E_RowThemes
, ready to be used.
A number of table themes are defined in V2_E_TableThemes
, ready to be used.
These two enumerates also demonstrate how to define a theme.
The standard usage is: * create a table * add rules and rows * create a renderer and configure it * render the table * use the finally rendered table, e.g. print it to a console or write it to a file
We add a combination of rows and rules and a final rule.
at.addRule(); at.addRow("first row (col1)", "with some information (col2)"); at.addRule(); at.addRow("second row (col1)", "with some information (col2)"); at.addRule();
We create the standard renderer and configure it to use the provided table theme V2_E_TableThemes.UTF_LIGHT
.
The we add a width to the renderer using WidthAbsoluteEven
for a table width of 76 characters.
V2_AsciiTableRenderer rend = new V2_AsciiTableRenderer(); rend.setTheme(V2_E_TableThemes.UTF_LIGHT.get()); rend.setWidth(new WidthAbsoluteEven(76));
Simply print it to standard out.
System.out.println(rt);
The will result in the following table being printed to the console:
┌─────────────────────────────────────┬────────────────────────────────────┐ │ first row (col1) │ with some information (col2) │ ├─────────────────────────────────────┼────────────────────────────────────┤ │ second row (col1) │ with some information (col2) │ └─────────────────────────────────────┴────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────┐ │ Table Heading │ ├──────────────────┬──────────────────┬──────────────────┬─────────────────┤ │ first row (col1) │ with some │ and more │ even more │ │ │ information │ information │ │ ├──────────────────┼──────────────────┼──────────────────┼─────────────────┤ │ second row │ with some │ and more │ even more │ │ (col1) │ information │ information │ │ │ │ (col2) │ (col3) │ │ └──────────────────┴──────────────────┴──────────────────┴─────────────────┘
┌────────────────────────┬────────────────────────┬────────────────────────┐ │ left │ right │ center │ └────────────────────────┴────────────────────────┴────────────────────────┘
┌──────────────────────────────────────────────────────────┐ │ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, │ │ sed diam nonumy eirmod tempor invidunt ut labore et │ │ dolore magna aliquyam erat, sed diam voluptua. At vero │ │ eos et accusam et justo duo dolores et ea rebum. Stet │ │ clita kasd gubergren, no sea takimata sanctus est Lorem │ │ ipsum dolor sit amet. │ ├──────────────────────────────────────────────────────────┤ │ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, │ │ sed diam nonumy eirmod tempor invidunt ut labore et │ │ dolore magna aliquyam erat, sed diam voluptua. At vero │ │ eos et accusam et justo duo dolores et ea rebum. Stet │ │ clita kasd gubergren, no sea takimata sanctus est Lorem │ │ ipsum dolor sit amet. │ └──────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────┐ │ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, │ │ sed diam nonumy eirmod tempor invidunt ut labore et dolore │ │ magna aliquyam erat, sed diam voluptua. At vero eos et │ │ accusam et justo duo dolores et ea rebum. Stet clita kasd │ │ gubergren, no sea takimata sanctus est Lorem ipsum dolor │ │ sit amet. │ │ │ │ │ │ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, │ │ sed diam nonumy eirmod tempor invidunt ut labore et dolore │ │ magna aliquyam erat, sed diam voluptua. At vero eos et │ │ accusam et justo duo dolores et ea rebum. Stet clita kasd │ │ gubergren, no sea takimata sanctus est Lorem ipsum dolor │ │ sit amet. │ └────────────────────────────────────────────────────────────┘
┌─────────────────────────┬────────────────────────────────────────┐ │ column with a list │ * list item one │ │ using line breaks │ * list item two │ │ │ * list item three │ └─────────────────────────┴────────────────────────────────────────┘
┌──────────────┬──────────────┬──────────────┬──────────────┬──────────────┐ │padding 0 │ padding 1 │ padding 2 │ padding │ paddin │ │ │ │ │ 3 │ g 4 │ └──────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
┌───────────────────────────────────────────────────────────────────────────────┐ │ span all 5 columns │ ├───────────────────────────────────────────────────────────────┬───────────────┤ │ span 4 columns │ just 1 column │ ├───────────────────────────────────────────────┬───────────────┴───────────────┤ │ span 3 columns │ span 2 columns │ ├───────────────────────────────┬───────────────┴───────────────────────────────┤ │ span 2 columns │ span 3 columns │ ├───────────────┬───────────────┴───────────────────────────────────────────────┤ │ just 1 column │ span 4 columns │ ├───────────────┼───────────────┬───────────────┬───────────────┬───────────────┤ │ just 1 column │ just 1 column │ just 1 column │ just 1 column │ just 1 column │ └───────────────┴───────────────┴───────────────┴───────────────┴───────────────┘
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ col1 col2 col3 ════════════════════════════════════════════════════════════════════════════ col1 col2 col3 ──────────────────────────────────────────────────────────────────────────── col1 col2 col3 ════════════════════════════════════════════════════════════════════════════ col1 col2 col3 ──────────────────────────────────────────────────────────────────────────── col1 col2 col3 ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ col1 col2 col3 ════════════════════════════════════════════════════════════════════════════ col1 col2 col3 ──────────────────────────────────────────────────────────────────────────── col1 col2 col3 ════════════════════════════════════════════════════════════════════════════ col1 col2 col3 ──────────────────────────────────────────────────────────────────────────── col1 col2 col3 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
┌────────────────┬───────────────┬───────────────┐ │ col1 │ col2 │ col3 │ └────────────────┴───────────────┴───────────────┘ ┌─────────┬─────────┬────────┐ │ col1 │ col2 │ col3 │ └─────────┴─────────┴────────┘ ┌──────┬─────┬─────┐ │ col1 │ col │ col │ │ │ 2 │ 3 │ └──────┴─────┴─────┘
┌──────────┬────────────────────┬──────────────────────────────┐ │ col1 │ col2 │ col3 │ └──────────┴────────────────────┴──────────────────────────────┘ ┌─────┬──────────┬───────────────┐ │ col │ col2 │ col3 │ │ 1 │ │ │ └─────┴──────────┴───────────────┘ ┌───┬─────┬───────┐ │ c │ col │ col3 │ │ o │ 2 │ │ │ l │ │ │ │ 1 │ │ │ └───┴─────┴───────┘
┌──────┬───────────┐ │first │information│ ├──────┼───────────┤ │second│info │ └──────┴───────────┘ ┌────────┬─────────────┐ │ first │ information │ ├────────┼─────────────┤ │ second │ info │ └────────┴─────────────┘ ┌────────────┬─────────────────┐ │ first │ information │ ├────────────┼─────────────────┤ │ second │ info │ └────────────┴─────────────────┘
┌───────────┬─────────────┐ │ first │ information │ ├───────────┼─────────────┤ │ second │ info │ └───────────┴─────────────┘ ┌────────┬──────────────────────────────────────────────────┐ │ first │ information │ ├────────┼──────────────────────────────────────────────────┤ │ second │ info │ └────────┴──────────────────────────────────────────────────┘
┌────────┬──────────┐ │ first │ informat │ │ │ ion │ ├────────┼──────────┤ │ second │ info │ └────────┴──────────┘ ┌─────┬─────────────┐ │ fir │ information │ │ st │ │ ├─────┼─────────────┤ │ sec │ info │ │ ond │ │ └─────┴─────────────┘
┌──┬───┬────┬─────┬──────┐ │ │ 1 │ 22 │ 333 │ 4444 │ └──┴───┴────┴─────┴──────┘
┌────┬────┬────┬──────┬────┐ │ │ 1 │ 22 │ 333 │ 44 │ │ │ │ │ │ 44 │ ├────┼────┼────┼──────┼────┤ │ │ 1 │ 22 │ 333 │ 44 │ │ │ │ │ 4444 │ 44 │ └────┴────┴────┴──────┴────┘
┌────┬───┬────┬─────┬──────┐ │ │ 1 │ 22 │ 333 │ 4444 │ └────┴───┴────┴─────┴──────┘
┌────┬────┬────┬─────┬────┐ │ │ 1 │ 22 │ 333 │ 44 │ │ │ │ │ │ 44 │ └────┴────┴────┴─────┴────┘
+--------------------------------------------------------------------------+ | some text with padding | +--------------------------------------------------------------------------+ +--------------------------------------------------------------------------+ | some text with padding***************************************************| +--------------------------------------------------------------------------+ +--------------------------------------------------------------------------+ | some text with padding---------------------------------------------------| +--------------------------------------------------------------------------+ +--------------------------------------------------------------------------+ | some text with padding␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣| +--------------------------------------------------------------------------+
+--------------------------------------------------------------------------+ | some column text | +--------------------------------------------------------------------------+ ┌──────────────────────────────────────────────────────────────────────────┐ │ some column text │ └──────────────────────────────────────────────────────────────────────────┘ ╓──────────────────────────────────────────────────────────────────────────╖ ║ some column text ║ ╙──────────────────────────────────────────────────────────────────────────╜ ╔══════════════════════════════════════════════════════════════════════════╗ ║ some column text ║ ╚══════════════════════════════════════════════════════════════════════════╝
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
┌─────────────────────────┬─────────────────────────┬───────────────────────────┐ │ * il 1 item 1 some text │ a el 1 item 1 some text │ [ ] cl 1 item 1 some text │ │ * il 1 item 2 some text │ b el 1 item 2 some text │ [X] cl 1 item 2 some text │ │ ** il 2 item 1 text │ b.a el 2 item 1 text │ │ │ ** il 2 item 2 text │ b.b el 2 item 2 text │ │ ├─────────────────────────┼─────────────────────────┼───────────────────────────┤ │ * il 1 item 1 some │ a el 1 item 1 some │ [ ] cl 1 item 1 some │ │ text │ text │ text │ │ * il 1 item 2 some │ b el 1 item 2 some │ [X] cl 1 item 2 some │ │ text │ text │ text │ │ ** il 2 item 1 │ b.a el 2 item 1 │ │ │ text │ text │ │ │ ** il 2 item 2 │ b.b el 2 item 2 │ │ │ text │ text │ │ └─────────────────────────┴─────────────────────────┴───────────────────────────┘
┌───────────────────────────────────┬───────────────────────────────────┐ │ scheme:[//[user:password@]host[:p │ scheme:[//[user:password@]host[:p │ │ ort]][/]path[?query][#fragment] │ ort]][/]path[?query][#fragment] │ ├───────────────────────────────────┴───────────────────────────────────┤ │ scheme:[//[user:password@]host[:port]][/]path[?query][#fragment] │ ├───────────────────────────────────┬───────────────────────────────────┤ │ abc://username:[email protected] │ abc://username:[email protected] │ │ om:123/path/data?key=value#fragid │ om:123/path/data?key=value#fragid │ │ 1 │ 1 │ ├───────────────────────────────────┴───────────────────────────────────┤ │ abc://username:[email protected]:123/path/data?key=value#fragid1 │ ├───────────────────────────────────┬───────────────────────────────────┤ │ urn:example:mammal:monotreme:echi │ urn:example:mammal:monotreme:echi │ │ dna │ dna │ ├───────────────────────────────────┴───────────────────────────────────┤ │ urn:example:mammal:monotreme:echidna │ ├───────────────────────────────────┬───────────────────────────────────┤ │ http://www.example.com/test1/test │ http://www.example.com/test1/test │ │ 2 │ 2 │ ├───────────────────────────────────┴───────────────────────────────────┤ │ http://www.example.com/test1/test2 │ ├───────────────────────────────────┬───────────────────────────────────┤ │ mailto:[email protected] │ mailto:firstname.lastname@example │ │ │ .com │ ├───────────────────────────────────┴───────────────────────────────────┤ │ mailto:[email protected] │ └───────────────────────────────────────────────────────────────────────┘