Skip to main content

Column

Struct Column 

Source
pub struct Column { /* private fields */ }
Expand description

A column definition that bundles the header text with default styling.

Use this when you already know your schema and want the table to inherit width, truncation, and color defaults from the column definition.

§Examples

use tiny_table::{Column, Color, Trunc};

let column = Column::new("Status")
    .color(Color::BrightGreen)
    .width(12)
    .truncate(Trunc::End);

Implementations§

Source§

impl Column

Source

pub fn new(header: impl Into<Cell>) -> Self

Create a new column definition from a header value.

Examples found in repository?
examples/simple.rs (line 5)
3fn main() {
4    let mut table = Table::with_columns(vec![
5        Column::new("Name").width(15),
6        Column::new("Role").width(20),
7        Column::new("Status").width(10),
8    ]);
9
10    table.add_row(vec![
11        Cell::new("Ada Lovelace"),
12        Cell::new("Engineer"),
13        Cell::new("Active"),
14    ]);
15
16    table.add_row(vec![
17        Cell::new("Bob"),
18        Cell::new("Support"),
19        Cell::new("Away"),
20    ]);
21
22    println!("{}", table);
23}
More examples
Hide additional examples
examples/styled.rs (line 5)
3fn main() {
4    let mut table = Table::with_columns(vec![
5        Column::new("Name").bright_cyan().bold().width(0.3),
6        Column::new("Role").width(0.4).truncate(Trunc::Middle),
7        Column::new("Status").bright_yellow().bold().width(0.3),
8    ])
9    .with_section_style(SectionStyle {
10        horiz: "═",
11        mid_left: "╞",
12        mid_right: "╡",
13        mid_joint: "╪",
14    })
15    .with_separator_style(SectionStyle {
16        horiz: "╌",
17        mid_joint: "│",
18        ..SectionStyle::unicode()
19    });
20
21    table.add_section("Team").align(Align::Center);
22    table.add_row(vec![
23        Cell::new("Ada Lovelace"),
24        Cell::new("Principal Engineer"),
25        Cell::new("Active").bright_green(),
26    ]);
27
28    table.add_separator();
29    table.add_row(vec![
30        Cell::new("Bob"),
31        Cell::new("Support"),
32        Cell::new("Away"),
33    ]);
34
35    println!("{}", table);
36}
Source

pub fn width(self, width: impl Into<ColumnWidth>) -> Self

Set the preferred width for this column.

Examples found in repository?
examples/simple.rs (line 5)
3fn main() {
4    let mut table = Table::with_columns(vec![
5        Column::new("Name").width(15),
6        Column::new("Role").width(20),
7        Column::new("Status").width(10),
8    ]);
9
10    table.add_row(vec![
11        Cell::new("Ada Lovelace"),
12        Cell::new("Engineer"),
13        Cell::new("Active"),
14    ]);
15
16    table.add_row(vec![
17        Cell::new("Bob"),
18        Cell::new("Support"),
19        Cell::new("Away"),
20    ]);
21
22    println!("{}", table);
23}
More examples
Hide additional examples
examples/styled.rs (line 5)
3fn main() {
4    let mut table = Table::with_columns(vec![
5        Column::new("Name").bright_cyan().bold().width(0.3),
6        Column::new("Role").width(0.4).truncate(Trunc::Middle),
7        Column::new("Status").bright_yellow().bold().width(0.3),
8    ])
9    .with_section_style(SectionStyle {
10        horiz: "═",
11        mid_left: "╞",
12        mid_right: "╡",
13        mid_joint: "╪",
14    })
15    .with_separator_style(SectionStyle {
16        horiz: "╌",
17        mid_joint: "│",
18        ..SectionStyle::unicode()
19    });
20
21    table.add_section("Team").align(Align::Center);
22    table.add_row(vec![
23        Cell::new("Ada Lovelace"),
24        Cell::new("Principal Engineer"),
25        Cell::new("Active").bright_green(),
26    ]);
27
28    table.add_separator();
29    table.add_row(vec![
30        Cell::new("Bob"),
31        Cell::new("Support"),
32        Cell::new("Away"),
33    ]);
34
35    println!("{}", table);
36}
Source

pub fn max_width(self, width: impl Into<ColumnWidth>) -> Self

Alias for Column::width.

Source

pub fn truncate(self, truncation: Trunc) -> Self

Set the default truncation strategy used by this column.

Examples found in repository?
examples/styled.rs (line 6)
3fn main() {
4    let mut table = Table::with_columns(vec![
5        Column::new("Name").bright_cyan().bold().width(0.3),
6        Column::new("Role").width(0.4).truncate(Trunc::Middle),
7        Column::new("Status").bright_yellow().bold().width(0.3),
8    ])
9    .with_section_style(SectionStyle {
10        horiz: "═",
11        mid_left: "╞",
12        mid_right: "╡",
13        mid_joint: "╪",
14    })
15    .with_separator_style(SectionStyle {
16        horiz: "╌",
17        mid_joint: "│",
18        ..SectionStyle::unicode()
19    });
20
21    table.add_section("Team").align(Align::Center);
22    table.add_row(vec![
23        Cell::new("Ada Lovelace"),
24        Cell::new("Principal Engineer"),
25        Cell::new("Active").bright_green(),
26    ]);
27
28    table.add_separator();
29    table.add_row(vec![
30        Cell::new("Bob"),
31        Cell::new("Support"),
32        Cell::new("Away"),
33    ]);
34
35    println!("{}", table);
36}
Source

pub fn align(self, align: Align) -> Self

Set the default text alignment for this column.

Source§

impl Column

Source

pub fn color(self, color: Color) -> Self

Apply a foreground color.

Source

pub fn on_color(self, color: Color) -> Self

Apply a background color.

Source

pub fn clear(self) -> Self

Clear all formatting.

Source

pub fn normal(self) -> Self

Reset formatting back to normal.

Source

pub fn bold(self) -> Self

Make the text bold.

Examples found in repository?
examples/styled.rs (line 5)
3fn main() {
4    let mut table = Table::with_columns(vec![
5        Column::new("Name").bright_cyan().bold().width(0.3),
6        Column::new("Role").width(0.4).truncate(Trunc::Middle),
7        Column::new("Status").bright_yellow().bold().width(0.3),
8    ])
9    .with_section_style(SectionStyle {
10        horiz: "═",
11        mid_left: "╞",
12        mid_right: "╡",
13        mid_joint: "╪",
14    })
15    .with_separator_style(SectionStyle {
16        horiz: "╌",
17        mid_joint: "│",
18        ..SectionStyle::unicode()
19    });
20
21    table.add_section("Team").align(Align::Center);
22    table.add_row(vec![
23        Cell::new("Ada Lovelace"),
24        Cell::new("Principal Engineer"),
25        Cell::new("Active").bright_green(),
26    ]);
27
28    table.add_separator();
29    table.add_row(vec![
30        Cell::new("Bob"),
31        Cell::new("Support"),
32        Cell::new("Away"),
33    ]);
34
35    println!("{}", table);
36}
Source

pub fn dimmed(self) -> Self

Make the text dimmed.

Source

pub fn italic(self) -> Self

Make the text italic.

Source

pub fn underline(self) -> Self

Underline the text.

Blink the text.

Source

pub fn reversed(self) -> Self

Reverse foreground and background colors.

Source

pub fn hidden(self) -> Self

Hide the text.

Source

pub fn strikethrough(self) -> Self

Strike the text through.

Source

pub fn black(self) -> Self

Use a black foreground color.

Source

pub fn red(self) -> Self

Use a red foreground color.

Source

pub fn green(self) -> Self

Use a green foreground color.

Source

pub fn yellow(self) -> Self

Use a yellow foreground color.

Source

pub fn blue(self) -> Self

Use a blue foreground color.

Source

pub fn magenta(self) -> Self

Use a magenta foreground color.

Source

pub fn cyan(self) -> Self

Use a cyan foreground color.

Source

pub fn white(self) -> Self

Use a white foreground color.

Source

pub fn bright_black(self) -> Self

Use a bright black foreground color.

Source

pub fn bright_red(self) -> Self

Use a bright red foreground color.

Source

pub fn bright_green(self) -> Self

Use a bright green foreground color.

Source

pub fn bright_yellow(self) -> Self

Use a bright yellow foreground color.

Examples found in repository?
examples/styled.rs (line 7)
3fn main() {
4    let mut table = Table::with_columns(vec![
5        Column::new("Name").bright_cyan().bold().width(0.3),
6        Column::new("Role").width(0.4).truncate(Trunc::Middle),
7        Column::new("Status").bright_yellow().bold().width(0.3),
8    ])
9    .with_section_style(SectionStyle {
10        horiz: "═",
11        mid_left: "╞",
12        mid_right: "╡",
13        mid_joint: "╪",
14    })
15    .with_separator_style(SectionStyle {
16        horiz: "╌",
17        mid_joint: "│",
18        ..SectionStyle::unicode()
19    });
20
21    table.add_section("Team").align(Align::Center);
22    table.add_row(vec![
23        Cell::new("Ada Lovelace"),
24        Cell::new("Principal Engineer"),
25        Cell::new("Active").bright_green(),
26    ]);
27
28    table.add_separator();
29    table.add_row(vec![
30        Cell::new("Bob"),
31        Cell::new("Support"),
32        Cell::new("Away"),
33    ]);
34
35    println!("{}", table);
36}
Source

pub fn bright_blue(self) -> Self

Use a bright blue foreground color.

Source

pub fn bright_magenta(self) -> Self

Use a bright magenta foreground color.

Source

pub fn bright_cyan(self) -> Self

Use a bright cyan foreground color.

Examples found in repository?
examples/styled.rs (line 5)
3fn main() {
4    let mut table = Table::with_columns(vec![
5        Column::new("Name").bright_cyan().bold().width(0.3),
6        Column::new("Role").width(0.4).truncate(Trunc::Middle),
7        Column::new("Status").bright_yellow().bold().width(0.3),
8    ])
9    .with_section_style(SectionStyle {
10        horiz: "═",
11        mid_left: "╞",
12        mid_right: "╡",
13        mid_joint: "╪",
14    })
15    .with_separator_style(SectionStyle {
16        horiz: "╌",
17        mid_joint: "│",
18        ..SectionStyle::unicode()
19    });
20
21    table.add_section("Team").align(Align::Center);
22    table.add_row(vec![
23        Cell::new("Ada Lovelace"),
24        Cell::new("Principal Engineer"),
25        Cell::new("Active").bright_green(),
26    ]);
27
28    table.add_separator();
29    table.add_row(vec![
30        Cell::new("Bob"),
31        Cell::new("Support"),
32        Cell::new("Away"),
33    ]);
34
35    println!("{}", table);
36}
Source

pub fn bright_white(self) -> Self

Use a bright white foreground color.

Source

pub fn purple(self) -> Self

Use a purple foreground color.

Source

pub fn bright_purple(self) -> Self

Use a bright purple foreground color.

Source

pub fn ansi_color(self, color: impl Into<u8>) -> Self

Use an ANSI 8-bit foreground color.

Source

pub fn truecolor(self, red: u8, green: u8, blue: u8) -> Self

Use a truecolor foreground color.

Source

pub fn on_black(self) -> Self

Use a black background color.

Source

pub fn on_red(self) -> Self

Use a red background color.

Source

pub fn on_green(self) -> Self

Use a green background color.

Source

pub fn on_yellow(self) -> Self

Use a yellow background color.

Source

pub fn on_blue(self) -> Self

Use a blue background color.

Source

pub fn on_magenta(self) -> Self

Use a magenta background color.

Source

pub fn on_cyan(self) -> Self

Use a cyan background color.

Source

pub fn on_white(self) -> Self

Use a white background color.

Source

pub fn on_bright_black(self) -> Self

Use a bright black background color.

Source

pub fn on_bright_red(self) -> Self

Use a bright red background color.

Source

pub fn on_bright_green(self) -> Self

Use a bright green background color.

Source

pub fn on_bright_yellow(self) -> Self

Use a bright yellow background color.

Source

pub fn on_bright_blue(self) -> Self

Use a bright blue background color.

Source

pub fn on_bright_magenta(self) -> Self

Use a bright magenta background color.

Source

pub fn on_bright_cyan(self) -> Self

Use a bright cyan background color.

Source

pub fn on_bright_white(self) -> Self

Use a bright white background color.

Source

pub fn custom_color(self, color: impl Into<CustomColor>) -> Self

Use an ANSI 8-bit background color.

Source

pub fn on_custom_color(self, color: impl Into<CustomColor>) -> Self

Use a custom truecolor background color.

Source

pub fn on_ansi_color(self, color: impl Into<u8>) -> Self

Use an ANSI 8-bit background color.

Source

pub fn on_truecolor(self, red: u8, green: u8, blue: u8) -> Self

Use a truecolor background color.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.