[][src]Crate cli_table

Rust crate for printing tables on command line.

Usage

Add cli-table in your Cargo.toms's dependencies section

[dependencies]
cli-table = "0.3"

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 = CellFormat::builder().justify(Justify::Right).build();

// Makes contents of a cell bold
let bold = CellFormat::builder().bold(true).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 TableFormats:

To create a table, you can use Table::new() like this:

let table = Table::new(
    vec![
        Row::new(vec![
            Cell::new(&format!("Name"), bold),
            Cell::new("Age (in years)", bold),
        ]),
        Row::new(vec![
            Cell::new("Tom", Default::default()),
            Cell::new("10", justify_right),
        ]),
        Row::new(vec![
            Cell::new("Jerry", Default::default()),
            Cell::new("15", justify_right),
        ]),
        Row::new(vec![
            Cell::new("Scooby Doo", Default::default()),
            Cell::new("25", justify_right),
        ]),
    ],
    Default::default(),
)
.unwrap();

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 |
+------------+----------------+

Modules

format

Utilities for formatting of a Table

Structs

Cell

A Cell in a Table

Row

A Row in a Table

Table

Struct for building a Table on command line

Enums

Error

Errors returned by functions in this crate