pub struct GridPrinter { /* private fields */ }
Expand description
An API to easily print a two dimensional array to stdout.
§Example
use grid_printer::GridPrinter;
let cars = vec![
vec!["Make", "Model", "Color", "Year", "Price", ],
vec!["Ford", "Pinto", "Green", "1978", "$750.00", ],
vec!["Toyota", "Tacoma", "Red", "2006", "$15,475.23", ],
vec!["Lamborghini", "Diablo", "Yellow", "2001", "$238,459.99", ],
];
let rows = cars.len();
let cols = cars[0].len();
let printer = GridPrinter::builder(rows, cols)
.col_spacing(4)
.build();
printer.print(&cars);
Output:
Make Model Color Year Price
Ford Pinto Green 1978 $750.00
Toyota Tacoma Red 2006 $15,475.23
Lamborghini Diablo Yellow 2001 $238,459.99
Implementations§
Source§impl GridPrinter
impl GridPrinter
pub fn new(rows: usize, cols: usize) -> Self
Sourcepub fn builder(rows: usize, cols: usize) -> GridPrinterBuilder
pub fn builder(rows: usize, cols: usize) -> GridPrinterBuilder
Examples found in repository?
examples/cars.rs (line 13)
3fn main() {
4 let cars = vec![
5 vec!["Make", "Model", "Color", "Year", "Price", ],
6 vec!["Ford", "Pinto", "Green", "1978", "$750.00", ],
7 vec!["Toyota", "Tacoma", "Red", "2006", "$15,475.23", ],
8 vec!["Lamborghini", "Diablo", "Yellow", "2001", "$238,459.99", ],
9 ];
10
11 let rows = cars.len();
12 let cols = cars[0].len();
13 let printer = GridPrinter::builder(rows, cols)
14 .col_spacing(4)
15 .build();
16 printer.print(&cars);
17}
More examples
examples/colors.rs (line 16)
5fn main() -> Result<(), Box<dyn Error>> {
6
7 let grid = vec![
8 vec![1, 2, 3, 4, ],
9 vec![5, 6, 7, 8, ],
10 vec![9, 10, 11, 12, ],
11 ];
12
13 let rows = grid.len();
14 let cols = grid[0].len();
15
16 let printer = GridPrinter::builder(rows, cols)
17 .col_style(0, StyleOpt::new().fg(Fg::Magenta))?
18 .col_style(1, StyleOpt::new().fg(Fg::Black).bg(Bg::BrightYellow))?
19 .col_style(2, StyleOpt::new().sgr(Sgr::StrikeThrough))?
20 .col_style(3, StyleOpt::new().fg(Fg::Cyan))?
21 .build();
22 printer.print(&grid);
23
24 Ok(())
25}
pub fn print_cell( &self, cell: &str, col_idx: usize, style_opt: Option<&StyleOpt>, )
Sourcepub fn print<F: Display>(&self, source: &[Vec<F>])
pub fn print<F: Display>(&self, source: &[Vec<F>])
Examples found in repository?
examples/cars.rs (line 16)
3fn main() {
4 let cars = vec![
5 vec!["Make", "Model", "Color", "Year", "Price", ],
6 vec!["Ford", "Pinto", "Green", "1978", "$750.00", ],
7 vec!["Toyota", "Tacoma", "Red", "2006", "$15,475.23", ],
8 vec!["Lamborghini", "Diablo", "Yellow", "2001", "$238,459.99", ],
9 ];
10
11 let rows = cars.len();
12 let cols = cars[0].len();
13 let printer = GridPrinter::builder(rows, cols)
14 .col_spacing(4)
15 .build();
16 printer.print(&cars);
17}
More examples
examples/colors.rs (line 22)
5fn main() -> Result<(), Box<dyn Error>> {
6
7 let grid = vec![
8 vec![1, 2, 3, 4, ],
9 vec![5, 6, 7, 8, ],
10 vec![9, 10, 11, 12, ],
11 ];
12
13 let rows = grid.len();
14 let cols = grid[0].len();
15
16 let printer = GridPrinter::builder(rows, cols)
17 .col_style(0, StyleOpt::new().fg(Fg::Magenta))?
18 .col_style(1, StyleOpt::new().fg(Fg::Black).bg(Bg::BrightYellow))?
19 .col_style(2, StyleOpt::new().sgr(Sgr::StrikeThrough))?
20 .col_style(3, StyleOpt::new().fg(Fg::Cyan))?
21 .build();
22 printer.print(&grid);
23
24 Ok(())
25}
Auto Trait Implementations§
impl !Freeze for GridPrinter
impl !RefUnwindSafe for GridPrinter
impl Send for GridPrinter
impl !Sync for GridPrinter
impl Unpin for GridPrinter
impl UnwindSafe for GridPrinter
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