tabled

Module alignment

Source
Expand description

This module contains an Alignment setting for cells on the Table.

An alignment strategy can be set by AlignmentStrategy.

§Example

use tabled::{
    formatting::AlignmentStrategy,
    object::Segment,
    Alignment, Modify, Style, Table,
};

let data = [
    ["1", "2", "3"],
    ["Some\nMulti\nLine\nText", "and a line", "here"],
    ["4", "5", "6"],
];

let mut table = Table::new(&data);
table.with(Style::modern())
     .with(
        Modify::new(Segment::all())
            .with(Alignment::right())
            .with(Alignment::center())
            .with(AlignmentStrategy::PerCell)
    );

assert_eq!(
    table.to_string(),
    concat!(
        "┌───────┬────────────┬──────┐\n",
        "│   0   │     1      │  2   │\n",
        "├───────┼────────────┼──────┤\n",
        "│   1   │     2      │  3   │\n",
        "├───────┼────────────┼──────┤\n",
        "│ Some  │ and a line │ here │\n",
        "│ Multi │            │      │\n",
        "│ Line  │            │      │\n",
        "│ Text  │            │      │\n",
        "├───────┼────────────┼──────┤\n",
        "│   4   │     5      │  6   │\n",
        "└───────┴────────────┴──────┘",
    ),
)

Enums§