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
impl Column
Sourcepub fn new(header: impl Into<Cell>) -> Self
pub fn new(header: impl Into<Cell>) -> Self
Create a new column definition from a header value.
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}Sourcepub fn width(self, width: impl Into<ColumnWidth>) -> Self
pub fn width(self, width: impl Into<ColumnWidth>) -> Self
Set the preferred width for this column.
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}Sourcepub fn max_width(self, width: impl Into<ColumnWidth>) -> Self
pub fn max_width(self, width: impl Into<ColumnWidth>) -> Self
Alias for Column::width.
Sourcepub fn truncate(self, truncation: Trunc) -> Self
pub fn truncate(self, truncation: Trunc) -> Self
Set the default truncation strategy used by this column.
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}Source§impl Column
impl Column
Sourcepub fn bold(self) -> Self
pub fn bold(self) -> Self
Make the text bold.
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}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.
Sourcepub fn bright_yellow(self) -> Self
pub fn bright_yellow(self) -> Self
Use a bright yellow 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_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.
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_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.