CLI Table
Rust crate for printing tables on command line.
Usage
Add cli-table
in your Cargo.toms
's dependencies
section
[]
= "0.2"
Each cell in a Table
can be formatted using CellFormat
. CellFormat
can be easily created like this:
// Justifies contents of a cell to right
let justify_right = builder.justify.build;
// Makes contents of a cell bold
let bold = builder.bold.build;
Table
can be formatted using TableFormat
. It is very easy to create a custom table format, but for simplicity, this
crate provides a few predefined TableFormat
s:
BORDER_COLUMN_TITLE
: Format with borders, column separators and row separators (callingDefault::default()
onTableFormat
also returns this format)BORDER_COLUMN_NO_ROW
: Format with borders and column separators (without row separators)BORDER_COLUMN_TITLE
: Format with borders, column separators and title separator (without row separators)BORDER_NO_COLUMN_ROW
: Format with borders and row separators (without column separators)NO_BORDER_COLUMN_ROW
: Format with no borders, column separators and row separatorsNO_BORDER_COLUMN_TITLE
: Format with no borders, column separators and title separator (without row separators)
To create a table, you can use Table::new()
like this:
let table = new;
To print this table on stdout
, you can call table.print_stdout()
.
Below is the output of the table we created just now:
+------------+----------------+
| Name | Age (in years) | <-- This row will appear in bold
+------------+----------------+
| Tom | 10 |
+------------+----------------+
| Jerry | 15 |
+------------+----------------+
| Scooby Doo | 25 |
+------------+----------------+
License
Licensed under either of
- Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.