Super-table
Super-table is designed as a library for building beautiful terminal tables, while being easy to use. It includes some features that are not provided by other CLI tables, such as cell spanning across columns and rows.
Table of Contents
State of the Project
Super-table is actively maintained and open to new features and improvements.
Features
- Dynamic arrangement of content depending on a given width.
- ANSI content styling for terminals (Colors, Bold, Blinking, etc.).
- Styling Presets and preset modifiers to get you started.
- Pretty much every part of the table is customizable (borders, lines, padding, alignment).
- Constraints on columns that allow some additional control over how to arrange content.
- Cell spanning (colspan and rowspan) for complex table layouts.
- Cross platform (Linux, macOS, Windows).
- It's fast enough.
- Benchmarks show that a pretty big table with complex constraints is build in
470μsor~0.5ms. - The table seen at the top of the readme takes
~30μs. - These numbers are from a overclocked
i7-8700Kwith a max single-core performance of 4.9GHz. - To run the benchmarks yourselves, install criterion via
cargo install cargo-criterionand runcargo criterionafterwards.
- Benchmarks show that a pretty big table with complex constraints is build in
Super-table is written for the current stable Rust version.
Older Rust versions may work but aren't officially supported.
Examples
use Table;
Create a very basic table.
This table will become as wide as your content. Nothing fancy happening here.
+----------------------+----------------------+------------------------+
| Header1 | Header2 | Header3 |
+======================================================================+
| This is a text | This is another text | This is the third text |
|----------------------+----------------------+------------------------|
| This is another text | Now | This is awesome |
| | add some | |
| | multi line stuff | |
+----------------------+----------------------+------------------------+
More Features
use UTF8_ROUND_CORNERS;
use UTF8_FULL;
use *;
Create a table with UTF8 styling, and apply a modifier that gives the table round corners.
Additionally, the content will dynamically wrap to maintain a given table width.
If the table width isn't explicitly set and the program runs in a terminal, the terminal size will be used.
On top of this, we set the default alignment for the right column to Right and the alignment of the left top cell to Center.
╭────────────┬────────────┬────────────╮
│ Header1 ┆ Header2 ┆ Header3 │
╞════════════╪════════════╪════════════╡
│ This is a ┆ This is ┆ This is │
│ text ┆ another ┆ the third │
│ ┆ text ┆ text │
├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ This is ┆ Now ┆ This is │
│ another ┆ add some ┆ awesome │
│ text ┆ multi line ┆ │
│ ┆ stuff ┆ │
╰────────────┴────────────┴────────────╯
Styling
use UTF8_FULL;
use *;
This code generates the table that can be seen at the top of this document.
Cell Spanning
Super-table supports cell spanning, allowing cells to span multiple columns (colspan) and/or rows (rowspan). This enables more complex table layouts.
Basic Colspan Example
use ;
+----------+----------+-------------+
| Header1 | Header3 |
+===================================+
| Spans 2 cols | Normal cell |
+----------+----------+-------------+
Basic Rowspan Example
use ;
+--------------+----------------+----------------+
| Header1 | Header2 | Header3 |
+================================================+
| Spans 2 rows | Cell 2 | Cell 3 |
| +----------------+----------------|
| | Cell 2 (row 2) | Cell 3 (row 2) |
+--------------+----------------+----------------+
Combined Colspan and Rowspan Example
use ;
+---------+---------+----------------+----------------+
| Header1 | Header2 | Header3 | Header4 |
+=====================================================+
| Spans 2x2 | Cell 3 | Cell 4 |
| +----------------+----------------|
| | Cell 3 (row 2) | Cell 4 (row 2) |
+---------+---------+----------------+----------------+
Notes:
- When using
colspan, add fewer cells to the row than the number of columns. The spanned cell counts as multiple columns. - When using
rowspan, subsequent rows should have fewer cells, as the rowspan cell occupies space in those rows. - You can combine
colspanandrowspanto create cells that span both multiple rows and columns. - Cell spanning works with all table features including styling, alignment, and dynamic width arrangement.
Code Examples
A few examples can be found in the example folder.
To test an example, run cargo run --example $name. E.g.:
If you're looking for more information, take a look at the tests folder. There are tests for almost every feature including a visual view for each resulting table.
Feature Flags
tty (enabled)
This flag enables support for terminals. In detail this means:
- Automatic detection whether we're in a terminal environment.
Only used when no explicit
Table::set_widthis provided. - Support for ANSI Escape Code styling for terminals.
custom_styling (disabled)
This flag enables support for custom styling of text inside of cells.
- Text formatting still works, even if you roll your own ANSI escape sequences.
- Rainbow text
- Makes super-table 30-50% slower
reexport_crossterm (disabled)
With this flag, super-table re-exposes crossterm's Attribute and Color enum.
By default, a mirrored type is exposed, which internally maps to the crossterm type.
This feature is very convenient if you use both super-table and crossterm in your code and want to use crossterm's types for everything interchangeably.
BUT if you enable this feature, you opt-in for breaking changes on minor/patch versions. Meaning, you have to update crossterm whenever you update super-table and you cannot update crossterm until super-table released a new version with that crossterm version.
Contributing
Super-table's main focus is on being reliable and feature-rich. Core features include:
- Normal tables (columns, rows, one cell per column/row).
- Cell spanning (colspan and rowspan) for complex layouts.
- Dynamic arrangement of content to a given width.
- Some kind of manual intervention in the arrangement process.
If you come up with an idea or an improvement, feel free to create an issue!
Attribution
Super-table is a fork of comfy-table by Arne Beer. Super-table maintains the same core functionality while allowing for independent development and feature additions, most notably cell spanning over rows and columns.