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
impl Cell
Sourcepub fn new(content: impl ToString) -> Self
pub fn new(content: impl ToString) -> Self
Create a new cell from display content.
Examples found in repository?
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
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§impl Cell
impl Cell
Hide the text.
Sourcepub fn strikethrough(self) -> Self
pub fn strikethrough(self) -> Self
Strike the text through.
Sourcepub fn bright_black(self) -> Self
pub fn bright_black(self) -> Self
Use a bright black foreground color.
Sourcepub fn bright_red(self) -> Self
pub fn bright_red(self) -> Self
Use a bright red foreground color.
Sourcepub fn bright_green(self) -> Self
pub fn bright_green(self) -> Self
Use a bright green foreground color.
Examples found in repository?
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}Sourcepub fn bright_yellow(self) -> Self
pub fn bright_yellow(self) -> Self
Use a bright yellow foreground color.
Sourcepub fn bright_blue(self) -> Self
pub fn bright_blue(self) -> Self
Use a bright blue foreground color.
Sourcepub fn bright_magenta(self) -> Self
pub fn bright_magenta(self) -> Self
Use a bright magenta foreground color.
Sourcepub fn bright_cyan(self) -> Self
pub fn bright_cyan(self) -> Self
Use a bright cyan foreground color.
Sourcepub fn bright_white(self) -> Self
pub fn bright_white(self) -> Self
Use a bright white foreground color.
Sourcepub fn bright_purple(self) -> Self
pub fn bright_purple(self) -> Self
Use a bright purple foreground color.
Sourcepub fn ansi_color(self, color: impl Into<u8>) -> Self
pub fn ansi_color(self, color: impl Into<u8>) -> Self
Use an ANSI 8-bit foreground color.
Sourcepub fn on_magenta(self) -> Self
pub fn on_magenta(self) -> Self
Use a magenta background color.
Sourcepub fn on_bright_black(self) -> Self
pub fn on_bright_black(self) -> Self
Use a bright black background color.
Sourcepub fn on_bright_red(self) -> Self
pub fn on_bright_red(self) -> Self
Use a bright red background color.
Sourcepub fn on_bright_green(self) -> Self
pub fn on_bright_green(self) -> Self
Use a bright green background color.
Sourcepub fn on_bright_yellow(self) -> Self
pub fn on_bright_yellow(self) -> Self
Use a bright yellow background color.
Sourcepub fn on_bright_blue(self) -> Self
pub fn on_bright_blue(self) -> Self
Use a bright blue background color.
Sourcepub fn on_bright_magenta(self) -> Self
pub fn on_bright_magenta(self) -> Self
Use a bright magenta background color.
Sourcepub fn on_bright_cyan(self) -> Self
pub fn on_bright_cyan(self) -> Self
Use a bright cyan background color.
Sourcepub fn on_bright_white(self) -> Self
pub fn on_bright_white(self) -> Self
Use a bright white background color.
Sourcepub fn custom_color(self, color: impl Into<CustomColor>) -> Self
pub fn custom_color(self, color: impl Into<CustomColor>) -> Self
Use an ANSI 8-bit background color.
Sourcepub fn on_custom_color(self, color: impl Into<CustomColor>) -> Self
pub fn on_custom_color(self, color: impl Into<CustomColor>) -> Self
Use a custom truecolor background color.
Sourcepub fn on_ansi_color(self, color: impl Into<u8>) -> Self
pub fn on_ansi_color(self, color: impl Into<u8>) -> Self
Use an ANSI 8-bit background color.
Sourcepub fn on_truecolor(self, red: u8, green: u8, blue: u8) -> Self
pub fn on_truecolor(self, red: u8, green: u8, blue: u8) -> Self
Use a truecolor background color.