pub struct NuTable { /* private fields */ }
Expand description
NuTable is a table rendering implementation.
Implementations§
Source§impl NuTable
impl NuTable
Sourcepub fn new(count_rows: usize, count_cols: usize) -> Self
pub fn new(count_rows: usize, count_cols: usize) -> Self
Creates an empty NuTable
instance.
Examples found in repository?
examples/table_demo.rs (line 24)
6fn main() {
7 let args: Vec<_> = std::env::args().collect();
8 let mut width = 0;
9
10 if args.len() > 1 {
11 width = args[1].parse::<usize>().expect("Need a width in columns");
12 }
13
14 if width < 4 {
15 println!("Width must be greater than or equal to 4, setting width to 80");
16 width = 80;
17 }
18
19 let (table_headers, row_data) = make_table_data();
20
21 let headers = to_cell_info_vec(&table_headers);
22 let rows = to_cell_info_vec(&row_data);
23
24 let mut table = NuTable::new(4, 3);
25 table.set_row(0, headers);
26
27 for i in 0..3 {
28 table.set_row(i + 1, rows.clone());
29 }
30
31 table.set_data_style(TextStyle::basic_left());
32 table.set_header_style(TextStyle::basic_center().style(Style::new().on(Color::Blue)));
33 table.set_theme(TableTheme::rounded());
34 table.set_structure(false, true, false);
35
36 let output_table = table
37 .draw(width)
38 .unwrap_or_else(|| format!("Couldn't fit table into {width} columns!"));
39
40 println!("{output_table}")
41}
Sourcepub fn count_rows(&self) -> usize
pub fn count_rows(&self) -> usize
Return amount of rows.
Sourcepub fn count_columns(&self) -> usize
pub fn count_columns(&self) -> usize
Return amount of columns.
pub fn create(text: String) -> NuRecordsValue
pub fn insert_value(&mut self, pos: (usize, usize), value: NuRecordsValue)
pub fn insert(&mut self, pos: (usize, usize), text: String)
Sourcepub fn set_row(&mut self, index: usize, row: Vec<NuRecordsValue>)
pub fn set_row(&mut self, index: usize, row: Vec<NuRecordsValue>)
Examples found in repository?
examples/table_demo.rs (line 25)
6fn main() {
7 let args: Vec<_> = std::env::args().collect();
8 let mut width = 0;
9
10 if args.len() > 1 {
11 width = args[1].parse::<usize>().expect("Need a width in columns");
12 }
13
14 if width < 4 {
15 println!("Width must be greater than or equal to 4, setting width to 80");
16 width = 80;
17 }
18
19 let (table_headers, row_data) = make_table_data();
20
21 let headers = to_cell_info_vec(&table_headers);
22 let rows = to_cell_info_vec(&row_data);
23
24 let mut table = NuTable::new(4, 3);
25 table.set_row(0, headers);
26
27 for i in 0..3 {
28 table.set_row(i + 1, rows.clone());
29 }
30
31 table.set_data_style(TextStyle::basic_left());
32 table.set_header_style(TextStyle::basic_center().style(Style::new().on(Color::Blue)));
33 table.set_theme(TableTheme::rounded());
34 table.set_structure(false, true, false);
35
36 let output_table = table
37 .draw(width)
38 .unwrap_or_else(|| format!("Couldn't fit table into {width} columns!"));
39
40 println!("{output_table}")
41}
pub fn pop_column(&mut self, count: usize)
pub fn push_column(&mut self, text: String)
pub fn insert_style(&mut self, pos: (usize, usize), style: TextStyle)
Sourcepub fn set_header_style(&mut self, style: TextStyle)
pub fn set_header_style(&mut self, style: TextStyle)
Examples found in repository?
examples/table_demo.rs (line 32)
6fn main() {
7 let args: Vec<_> = std::env::args().collect();
8 let mut width = 0;
9
10 if args.len() > 1 {
11 width = args[1].parse::<usize>().expect("Need a width in columns");
12 }
13
14 if width < 4 {
15 println!("Width must be greater than or equal to 4, setting width to 80");
16 width = 80;
17 }
18
19 let (table_headers, row_data) = make_table_data();
20
21 let headers = to_cell_info_vec(&table_headers);
22 let rows = to_cell_info_vec(&row_data);
23
24 let mut table = NuTable::new(4, 3);
25 table.set_row(0, headers);
26
27 for i in 0..3 {
28 table.set_row(i + 1, rows.clone());
29 }
30
31 table.set_data_style(TextStyle::basic_left());
32 table.set_header_style(TextStyle::basic_center().style(Style::new().on(Color::Blue)));
33 table.set_theme(TableTheme::rounded());
34 table.set_structure(false, true, false);
35
36 let output_table = table
37 .draw(width)
38 .unwrap_or_else(|| format!("Couldn't fit table into {width} columns!"));
39
40 println!("{output_table}")
41}
pub fn set_index_style(&mut self, style: TextStyle)
Sourcepub fn set_data_style(&mut self, style: TextStyle)
pub fn set_data_style(&mut self, style: TextStyle)
Examples found in repository?
examples/table_demo.rs (line 31)
6fn main() {
7 let args: Vec<_> = std::env::args().collect();
8 let mut width = 0;
9
10 if args.len() > 1 {
11 width = args[1].parse::<usize>().expect("Need a width in columns");
12 }
13
14 if width < 4 {
15 println!("Width must be greater than or equal to 4, setting width to 80");
16 width = 80;
17 }
18
19 let (table_headers, row_data) = make_table_data();
20
21 let headers = to_cell_info_vec(&table_headers);
22 let rows = to_cell_info_vec(&row_data);
23
24 let mut table = NuTable::new(4, 3);
25 table.set_row(0, headers);
26
27 for i in 0..3 {
28 table.set_row(i + 1, rows.clone());
29 }
30
31 table.set_data_style(TextStyle::basic_left());
32 table.set_header_style(TextStyle::basic_center().style(Style::new().on(Color::Blue)));
33 table.set_theme(TableTheme::rounded());
34 table.set_structure(false, true, false);
35
36 let output_table = table
37 .draw(width)
38 .unwrap_or_else(|| format!("Couldn't fit table into {width} columns!"));
39
40 println!("{output_table}")
41}
pub fn set_indent(&mut self, indent: TableIndent)
Sourcepub fn set_theme(&mut self, theme: TableTheme)
pub fn set_theme(&mut self, theme: TableTheme)
Examples found in repository?
examples/table_demo.rs (line 33)
6fn main() {
7 let args: Vec<_> = std::env::args().collect();
8 let mut width = 0;
9
10 if args.len() > 1 {
11 width = args[1].parse::<usize>().expect("Need a width in columns");
12 }
13
14 if width < 4 {
15 println!("Width must be greater than or equal to 4, setting width to 80");
16 width = 80;
17 }
18
19 let (table_headers, row_data) = make_table_data();
20
21 let headers = to_cell_info_vec(&table_headers);
22 let rows = to_cell_info_vec(&row_data);
23
24 let mut table = NuTable::new(4, 3);
25 table.set_row(0, headers);
26
27 for i in 0..3 {
28 table.set_row(i + 1, rows.clone());
29 }
30
31 table.set_data_style(TextStyle::basic_left());
32 table.set_header_style(TextStyle::basic_center().style(Style::new().on(Color::Blue)));
33 table.set_theme(TableTheme::rounded());
34 table.set_structure(false, true, false);
35
36 let output_table = table
37 .draw(width)
38 .unwrap_or_else(|| format!("Couldn't fit table into {width} columns!"));
39
40 println!("{output_table}")
41}
Sourcepub fn set_structure(&mut self, index: bool, header: bool, footer: bool)
pub fn set_structure(&mut self, index: bool, header: bool, footer: bool)
Examples found in repository?
examples/table_demo.rs (line 34)
6fn main() {
7 let args: Vec<_> = std::env::args().collect();
8 let mut width = 0;
9
10 if args.len() > 1 {
11 width = args[1].parse::<usize>().expect("Need a width in columns");
12 }
13
14 if width < 4 {
15 println!("Width must be greater than or equal to 4, setting width to 80");
16 width = 80;
17 }
18
19 let (table_headers, row_data) = make_table_data();
20
21 let headers = to_cell_info_vec(&table_headers);
22 let rows = to_cell_info_vec(&row_data);
23
24 let mut table = NuTable::new(4, 3);
25 table.set_row(0, headers);
26
27 for i in 0..3 {
28 table.set_row(i + 1, rows.clone());
29 }
30
31 table.set_data_style(TextStyle::basic_left());
32 table.set_header_style(TextStyle::basic_center().style(Style::new().on(Color::Blue)));
33 table.set_theme(TableTheme::rounded());
34 table.set_structure(false, true, false);
35
36 let output_table = table
37 .draw(width)
38 .unwrap_or_else(|| format!("Couldn't fit table into {width} columns!"));
39
40 println!("{output_table}")
41}
pub fn set_border_header(&mut self, on: bool)
pub fn set_trim(&mut self, strategy: TrimStrategy)
pub fn set_strategy(&mut self, expand: bool)
pub fn set_border_color(&mut self, color: Style)
pub fn clear_border_color(&mut self)
pub fn get_records_mut(&mut self) -> &mut [Vec<NuRecordsValue>]
pub fn clear_all_colors(&mut self)
Sourcepub fn draw(self, termwidth: usize) -> Option<String>
pub fn draw(self, termwidth: usize) -> Option<String>
Converts a table to a String.
It returns None in case where table cannot be fit to a terminal width.
Examples found in repository?
examples/table_demo.rs (line 37)
6fn main() {
7 let args: Vec<_> = std::env::args().collect();
8 let mut width = 0;
9
10 if args.len() > 1 {
11 width = args[1].parse::<usize>().expect("Need a width in columns");
12 }
13
14 if width < 4 {
15 println!("Width must be greater than or equal to 4, setting width to 80");
16 width = 80;
17 }
18
19 let (table_headers, row_data) = make_table_data();
20
21 let headers = to_cell_info_vec(&table_headers);
22 let rows = to_cell_info_vec(&row_data);
23
24 let mut table = NuTable::new(4, 3);
25 table.set_row(0, headers);
26
27 for i in 0..3 {
28 table.set_row(i + 1, rows.clone());
29 }
30
31 table.set_data_style(TextStyle::basic_left());
32 table.set_header_style(TextStyle::basic_center().style(Style::new().on(Color::Blue)));
33 table.set_theme(TableTheme::rounded());
34 table.set_structure(false, true, false);
35
36 let output_table = table
37 .draw(width)
38 .unwrap_or_else(|| format!("Couldn't fit table into {width} columns!"));
39
40 println!("{output_table}")
41}
Sourcepub fn draw_unchecked(self, termwidth: usize) -> Option<String>
pub fn draw_unchecked(self, termwidth: usize) -> Option<String>
Converts a table to a String.
It returns None in case where table cannot be fit to a terminal width.
Sourcepub fn total_width(&self) -> usize
pub fn total_width(&self) -> usize
Return a total table width.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NuTable
impl RefUnwindSafe for NuTable
impl Send for NuTable
impl Sync for NuTable
impl Unpin for NuTable
impl UnwindSafe for NuTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoSpanned for T
impl<T> IntoSpanned for T
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Set the foreground color generically Read more
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Set the background color generically. Read more
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Change the foreground color to black
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Change the background color to black
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Change the foreground color to red
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Change the background color to red
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Change the foreground color to green
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Change the background color to green
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Change the foreground color to yellow
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Change the background color to yellow
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Change the foreground color to blue
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Change the background color to blue
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Change the foreground color to magenta
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Change the background color to magenta
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Change the foreground color to purple
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Change the background color to purple
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Change the foreground color to cyan
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Change the background color to cyan
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Change the foreground color to white
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Change the background color to white
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Change the foreground color to the terminal default
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Change the background color to the terminal default
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Change the foreground color to bright black
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Change the background color to bright black
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Change the foreground color to bright red
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Change the background color to bright red
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Change the foreground color to bright green
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Change the background color to bright green
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Change the foreground color to bright yellow
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Change the background color to bright yellow
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Change the foreground color to bright blue
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Change the background color to bright blue
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Change the foreground color to bright magenta
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Change the background color to bright magenta
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Change the foreground color to bright purple
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Change the background color to bright purple
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Change the foreground color to bright cyan
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Change the background color to bright cyan
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Change the foreground color to bright white
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Change the background color to bright white
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Make the text bold
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Make the text dim
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Make the text italicized
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Make the text underlined
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Make the text blink
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Make the text blink (but fast!)
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Swap the foreground and background colors
Hide the text
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Cross out the text
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
Set the foreground color at runtime. Only use if you do not know which color will be used at
compile-time. If the color is constant, use either
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
Set the background color at runtime. Only use if you do not know what color to use at
compile-time. If the color is constant, use either
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read moreSource§fn fg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
Set the foreground color to a specific RGB value.
Source§fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
Set the background color to a specific RGB value.
Source§fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
Sets the foreground color to an RGB value.
Source§fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
Sets the background color to an RGB value.