Skip to main content

Cell

Struct Cell 

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

A single table cell with optional styling overrides.

Cells are usually created from strings and then used in Table::add_row. Any color or truncation set on the cell takes priority over the owning column’s defaults.

§Examples

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

let cell = Cell::new("warning")
    .color(Color::BrightRed)
    .truncate(Trunc::Middle);

Implementations§

Source§

impl Cell

Source

pub fn new(content: impl ToString) -> Self

Create a new cell from display content.

Examples found in repository?
examples/simple.rs (line 11)
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 23)
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 truncate(self, truncation: Trunc) -> Self

Set a truncation mode for this cell, overriding any column default.

Source

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

Set the text alignment for this cell, overriding any column default.

Source§

impl Cell

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.

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.

Examples found in repository?
examples/styled.rs (line 25)
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_yellow(self) -> Self

Use a bright yellow foreground color.

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.

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.

Trait Implementations§

Source§

impl From<&str> for Cell

Source§

fn from(content: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Cell

Source§

fn from(content: String) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Cell

§

impl RefUnwindSafe for Cell

§

impl Send for Cell

§

impl Sync for Cell

§

impl Unpin for Cell

§

impl UnsafeUnpin for Cell

§

impl UnwindSafe for Cell

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.