tabled 0.9.0

An easy to use library for pretty print tables of Rust `struct`s and `enum`s.
mod util;

use tabled::{
    format::Format,
    object::{Columns, Segment},
    Alignment, Height, Modify, Style,
};

#[cfg(feature = "color")]
use owo_colors::OwoColorize;

use util::{create_table, test_table};

test_table!(
    cell_height_increase,
    create_table::<3, 3>()
        .with(Style::markdown())
        .with(
            Modify::new(Columns::first())
                .with(Height::increase(3))
        )
        .with(Modify::new(Segment::all()).with(
            Alignment::center_vertical()
        )),
    "| N |          |          |          |"
    "|   | column 0 | column 1 | column 2 |"
    "|   |          |          |          |"
    "|---|----------|----------|----------|"
    "| 0 |          |          |          |"
    "|   |   0-0    |   0-1    |   0-2    |"
    "|   |          |          |          |"
    "| 1 |          |          |          |"
    "|   |   1-0    |   1-1    |   1-2    |"
    "|   |          |          |          |"
    "| 2 |          |          |          |"
    "|   |   2-0    |   2-1    |   2-2    |"
    "|   |          |          |          |"
);

test_table!(
    table_height_increase,
    create_table::<3, 3>()
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Alignment::center_vertical()))
        .with(Height::increase(10)),
    "|   | column 0 | column 1 | column 2 |"
    "| N |          |          |          |"
    "|   |          |          |          |"
    "|---|----------|----------|----------|"
    "| 0 |   0-0    |   0-1    |   0-2    |"
    "|   |          |          |          |"
    "| 1 |   1-0    |   1-1    |   1-2    |"
    "|   |          |          |          |"
    "| 2 |   2-0    |   2-1    |   2-2    |"
    "|   |          |          |          |"
);

test_table!(
    cell_height_increase_zero,
    create_table::<3, 3>()
        .with(Style::markdown())
        .with(
            Modify::new(Columns::first())
                .with(Height::increase(0))
        )
        .with(Modify::new(Segment::all()).with(
            Alignment::center_vertical()
        )),
    "| N | column 0 | column 1 | column 2 |"
    "|---|----------|----------|----------|"
    "| 0 |   0-0    |   0-1    |   0-2    |"
    "| 1 |   1-0    |   1-1    |   1-2    |"
    "| 2 |   2-0    |   2-1    |   2-2    |"
);

test_table!(
    table_height_increase_zero,
    create_table::<3, 3>()
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Alignment::center_vertical()))
        .with(Height::increase(0)),
    "| N | column 0 | column 1 | column 2 |"
    "|---|----------|----------|----------|"
    "| 0 |   0-0    |   0-1    |   0-2    |"
    "| 1 |   1-0    |   1-1    |   1-2    |"
    "| 2 |   2-0    |   2-1    |   2-2    |"
);

test_table!(
    cell_height_limit,
    create_table::<3, 3>()
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::new(|s| format!("xxxx\n{}xxxx\nxxxx\n", s))))
        .with(
            Modify::new(Columns::first())
                .with(Height::limit(1))
        )
        .with(Modify::new(Segment::all()).with(
            Alignment::center_vertical()
        )),
    "| xxxx | column 0 | column 1 | column 2 |"
    "|------|----------|----------|----------|"
    "| xxxx |   0-0    |   0-1    |   0-2    |"
    "| xxxx |   1-0    |   1-1    |   1-2    |"
    "| xxxx |   2-0    |   2-1    |   2-2    |"
);

test_table!(
    table_height_limit,
    create_table::<3, 3>()
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::new(|s| format!("xxxx\n{}xxxx\nxxxx\n", s))))
        .with(Modify::new(Columns::first()).with(Alignment::center_vertical()))
        .with(Height::limit(10)),
    "| xxxx  | column 0 | column 1 | column 2 |"
    "| Nxxxx |          |          |          |"
    "|-------|----------|----------|----------|"
    "| xxxx  |   0-0    |   0-1    |   0-2    |"
    "| 0xxxx |          |          |          |"
    "| xxxx  |   1-0    |   1-1    |   1-2    |"
    "| 1xxxx |          |          |          |"
    "| xxxx  |   2-0    |   2-1    |   2-2    |"
    "| 2xxxx |          |          |          |"
    "| xxxx  |          |          |          |"
);

test_table!(
    table_height_limit_style_change_after,
    create_table::<3, 3>()
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::new(|s| format!("xxxx\n{}xxxx\nxxxx\n", s))))
        .with(Modify::new(Columns::first()).with(Alignment::center_vertical()))
        .with(Height::limit(7)),
    "| xxxx  | column 0 | column 1 | column 2 |"
    "|-------|----------|----------|----------|"
    "| xxxx  |   0-0    |   0-1    |   0-2    |"
    "| xxxx  |   1-0    |   1-1    |   1-2    |"
    "| 1xxxx |          |          |          |"
    "| xxxx  |   2-0    |   2-1    |   2-2    |"
    "| 2xxxx |          |          |          |"
);

test_table!(
    cell_height_limit_zero,
    create_table::<3, 3>()
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::new(|s| format!("xxxx\n{}xxxx\nxxxx\n", s))))
        .with(
            Modify::new(Columns::first())
                .with(Height::limit(0))
        )
        .with(Modify::new(Segment::all()).with(
            Alignment::center_vertical()
        )),
    "|  | column 0 | column 1 | column 2 |"
    "|--|----------|----------|----------|"
    "|  |   0-0    |   0-1    |   0-2    |"
    "|  |   1-0    |   1-1    |   1-2    |"
    "|  |   2-0    |   2-1    |   2-2    |"
);

test_table!(
    table_height_limit_zero,
    create_table::<3, 3>()
        .with(Style::markdown())
        .with(
            Modify::new(Columns::first()).with(Format::new(|s| format!("xxxx\n{}xxxx\nxxxx\n", s)))
        )
        .with(Modify::new(Columns::first()).with(Alignment::center_vertical()))
        .with(Height::limit(0)),
    "|-------|----------|----------|----------|"
);

#[cfg(feature = "color")]
test_table!(
    cell_height_limit_colored,
    create_table::<3, 3>()
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::new(|s| format!("xxxx\n{}xxxx\nxxxx\n", s).red().to_string())))
        .with(
            Modify::new(Columns::first())
                .with(Height::limit(1))
        )
        .with(Modify::new(Segment::all()).with(
            Alignment::center_vertical()
        )),
        "| \u{1b}[31mxxxx\u{1b}[39m | column 0 | column 1 | column 2 |"
        "|------|----------|----------|----------|"
        "| \u{1b}[31mxxxx\u{1b}[39m |   0-0    |   0-1    |   0-2    |"
        "| \u{1b}[31mxxxx\u{1b}[39m |   1-0    |   1-1    |   1-2    |"
        "| \u{1b}[31mxxxx\u{1b}[39m |   2-0    |   2-1    |   2-2    |"
);

#[cfg(feature = "color")]
test_table!(
    table_height_limit_colored,
    create_table::<3, 3>()
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::new(|s| format!("xxxx\n{}xxxx\nxxxx\n", s).blue().on_green().to_string())))
        .with(Modify::new(Columns::first()).with(Alignment::center_vertical()))
        .with(Height::limit(10)),
        "| \u{1b}[34;42mxxxx\u{1b}[39m\u{1b}[49m  | column 0 | column 1 | column 2 |"
        "| \u{1b}[34m\u{1b}[42mNxxxx\u{1b}[39m\u{1b}[49m |          |          |          |"
        "|-------|----------|----------|----------|"
        "| \u{1b}[34;42mxxxx\u{1b}[39m\u{1b}[49m  |   0-0    |   0-1    |   0-2    |"
        "| \u{1b}[34m\u{1b}[42m0xxxx\u{1b}[39m\u{1b}[49m |          |          |          |"
        "| \u{1b}[34;42mxxxx\u{1b}[39m\u{1b}[49m  |   1-0    |   1-1    |   1-2    |"
        "| \u{1b}[34m\u{1b}[42m1xxxx\u{1b}[39m\u{1b}[49m |          |          |          |"
        "| \u{1b}[34;42mxxxx\u{1b}[39m\u{1b}[49m  |   2-0    |   2-1    |   2-2    |"
        "| \u{1b}[34m\u{1b}[42m2xxxx\u{1b}[39m\u{1b}[49m |          |          |          |"
        "| \u{1b}[34m\u{1b}[42mxxxx\u{1b}[39m\u{1b}[49m  |          |          |          |"
);

#[cfg(feature = "macros")]
test_table!(
    cell_height_1x1,
    tabled::row![tabled::col!["SGML"].with(Height::increase(4))],
    "+----------+"
    "| +------+ |"
    "| | SGML | |"
    "| |      | |"
    "| +------+ |"
    "+----------+"
);

#[cfg(feature = "macros")]
test_table!(
    cell_height_1x1_no_top_border,
    tabled::row![tabled::col!["SGML"].with(Style::ascii().off_top()).with(Height::increase(4))],
    "+----------+"
    "| | SGML | |"
    "| |      | |"
    "| |      | |"
    "| +------+ |"
    "+----------+"
);