pub struct GridPrinterBuilder { /* private fields */ }
Expand description
A Builder to create/customize a GridPrinter instance
use grid_printer::GridPrinter;
use grid_printer::GridPrinterBuilder;
let rows = 3;
let cols = 3;
let printer: GridPrinter = GridPrinterBuilder::new(rows, cols)
.col_spacing(4)
.build();
Implementations§
Source§impl GridPrinterBuilder
impl GridPrinterBuilder
pub fn new(rows: usize, cols: usize) -> Self
Sourcepub fn col_spacing(self, col_spacing: usize) -> Self
pub fn col_spacing(self, col_spacing: usize) -> Self
Examples found in repository?
examples/cars.rs (line 14)
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}
pub fn col_styles( self, col_styles: Vec<Option<StyleOpt>>, ) -> Result<Self, GridPrinterErr>
Sourcepub fn col_style(
self,
idx: usize,
opt: StyleOpt,
) -> Result<Self, GridPrinterErr>
pub fn col_style( self, idx: usize, opt: StyleOpt, ) -> Result<Self, GridPrinterErr>
Examples found in repository?
examples/colors.rs (line 17)
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}
Sourcepub fn build(self) -> GridPrinter
pub fn build(self) -> GridPrinter
Examples found in repository?
examples/cars.rs (line 15)
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 21)
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}
Trait Implementations§
Source§impl Debug for GridPrinterBuilder
impl Debug for GridPrinterBuilder
Auto Trait Implementations§
impl Freeze for GridPrinterBuilder
impl RefUnwindSafe for GridPrinterBuilder
impl Send for GridPrinterBuilder
impl Sync for GridPrinterBuilder
impl Unpin for GridPrinterBuilder
impl UnwindSafe for GridPrinterBuilder
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