Module style

Module style 

Source
Expand description

The style module provides an API to customize the style settings for a GridPrinter instance, such as the font foreground color, the font background color, and the font text style (bold, italic, strike-through, etc.).

§Example

use grid_printer::GridPrinter;
use grid_printer::style::{Fg, Bg, Sgr, StyleOpt};
use std::error::Error;
 
fn main() -> Result<(), Box<dyn Error>> {
 
    let grid = vec![
        vec![1, 2, 3, 4, ],
        vec![5, 6, 7, 8, ],
        vec![9, 10, 11, 12, ],
    ];
 
    let rows = grid.len();
    let cols = grid[0].len();
     
    let printer = GridPrinter::builder(rows, cols)
        .col_style(0, StyleOpt::new().fg(Fg::Magenta))?
        .col_style(1, StyleOpt::new().fg(Fg::Black).bg(Bg::BrightYellow))?
        .col_style(2, StyleOpt::new().sgr(Sgr::StrikeThrough))?
        .col_style(3, StyleOpt::new().fg(Fg::Cyan))?
        .build();
    printer.print(&grid);
 
    Ok(())
}

§Output

1      2        3       4
5      6        7       8
9      10      11     12

Structs§

StyleOpt
A struct providing optional customization of the foreground color, background color, and text style of a GridPrinter column.

Enums§

Bg
An enumeration of background color options.
Fg
An enumeration of foreground color options.
Sgr
Select Graphic Renditions, i.e. an enumeration of text style options, such as bold, italic, etc.

Functions§

stylize
A function which will print a given &str s in accordance to the StylOpt opt.