Struct Colorization

Source
pub struct Colorization { /* private fields */ }
Expand description

Colorization sets a color for the whole table data (so it’s not include the borders).

You can colorize borders in a different round using BorderColor or Theme

§Examples

use std::iter::FromIterator;

use tabled::builder::Builder;
use tabled::settings::{style::BorderColor, themes::Colorization, Color, Style};

let data = [["Hello", "World"], ["Hi", "World"], ["Halo", "World"]];

let color1 = Color::FG_BLACK | Color::BG_WHITE;
let color2 = Color::BG_BLACK | Color::FG_WHITE;
let color3 = Color::FG_RED | Color::BG_RED;

let mut table = Builder::from_iter(data).build();
table
    .with(Colorization::chess(color1, color2))
    .with(Style::modern())
    .with(BorderColor::filled(color3));

println!("{table}");

Implementations§

Source§

impl Colorization

Source

pub fn chess(white: Color, black: Color) -> Self

Creates a Colorization with a chess pattern.

use std::iter::FromIterator;

use tabled::builder::Builder;
use tabled::settings::{themes::Colorization, Color, Style};

let data = [["Hello", "World"], ["Hi", "World"], ["Halo", "World"]];

let color1 = Color::FG_BLACK | Color::BG_WHITE;
let color2 = Color::BG_BLACK | Color::FG_WHITE;

let mut table = Builder::from_iter(data).build();
table
    .with(Colorization::chess(color1, color2))
    .with(Style::empty());

println!("{table}");
Source

pub fn exact<I, O>(colors: I, target: O) -> ExactColorization<O>
where I: IntoIterator, I::Item: Into<Color>,

Creates a Colorization with a target Object.

use std::iter::FromIterator;

use tabled::builder::Builder;
use tabled::settings::object::Rows;
use tabled::settings::{themes::Colorization, Color, Style};

let data = [["Hello", "World"], ["Hi", "World"], ["Halo", "World"]];

let color1 = Color::FG_BLACK | Color::BG_WHITE;
let color2 = Color::BG_BLACK | Color::FG_WHITE;

let mut table = Builder::from_iter(data).build();
table
    .with(Colorization::exact([color1, color2], Rows::first()))
    .with(Style::empty());

println!("{table}");
Source

pub fn rows<I>(colors: I) -> Self
where I: IntoIterator, I::Item: Into<Color>,

Creates a Colorization with a pattern which changes row by row.

use std::iter::FromIterator;

use tabled::builder::Builder;
use tabled::settings::object::Rows;
use tabled::settings::{themes::Colorization, Color, Style};

let data = [["Hello", "World"], ["Hi", "World"], ["Halo", "World"]];

let color1 = Color::FG_BLACK | Color::BG_WHITE;
let color2 = Color::BG_BLACK | Color::FG_WHITE;

let mut table = Builder::from_iter(data).build();
table
    .with(Colorization::rows([color1, color2]))
    .with(Style::empty());

println!("{table}");
Source

pub fn columns<I>(colors: I) -> Self
where I: IntoIterator, I::Item: Into<Color>,

Creates a Colorization with a pattern which changes column by column.

use std::iter::FromIterator;

use tabled::builder::Builder;
use tabled::settings::object::Rows;
use tabled::settings::{themes::Colorization, Color, Style};

let data = [["Hello", "World"], ["Hi", "World"], ["Halo", "World"]];

let color1 = Color::FG_BLACK | Color::BG_WHITE;
let color2 = Color::BG_BLACK | Color::FG_WHITE;

let mut table = Builder::from_iter(data).build();
table
    .with(Colorization::columns([color1, color2]))
    .with(Style::empty());

println!("{table}");
Source

pub fn by_row<I>(colors: I) -> Self
where I: IntoIterator, I::Item: Into<Color>,

Creates a Colorization with a pattern which peaks cells one by one iterating over rows.

use std::iter::FromIterator;

use tabled::builder::Builder;
use tabled::settings::object::Rows;
use tabled::settings::{themes::Colorization, Color, Style};

let data = [["Hello", "World"], ["Hi", "World"], ["Halo", "World"]];

let color1 = Color::FG_BLACK | Color::BG_WHITE;
let color2 = Color::BG_BLACK | Color::FG_WHITE;

let mut table = Builder::from_iter(data).build();
table
    .with(Colorization::by_row([color1, color2]))
    .with(Style::empty());

println!("{table}");
Source

pub fn by_column<I>(colors: I) -> Self
where I: IntoIterator, I::Item: Into<Color>,

Creates a Colorization with a pattern which peaks cells one by one iterating over columns.

use std::iter::FromIterator;

use tabled::builder::Builder;
use tabled::settings::object::Rows;
use tabled::settings::{themes::Colorization, Color, Style};

let data = [["Hello", "World"], ["Hi", "World"], ["Halo", "World"]];

let color1 = Color::FG_BLACK | Color::BG_WHITE;
let color2 = Color::BG_BLACK | Color::FG_WHITE;

let mut table = Builder::from_iter(data).build();
table
    .with(Colorization::by_column([color1, color2]))
    .with(Style::empty());

println!("{table}");

Trait Implementations§

Source§

impl Clone for Colorization

Source§

fn clone(&self) -> Colorization

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Colorization

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Colorization

Source§

fn eq(&self, other: &Colorization) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<R, D> TableOption<R, ColoredConfig, D> for Colorization
where R: Records + ExactRecords,

Source§

fn change(self, records: &mut R, cfg: &mut ColoredConfig, _: &mut D)

The function modificaties of records and a grid configuration.
Source§

fn hint_change(&self) -> Option<Entity>

A hint whether an TableOption is going to change table layout. Read more
Source§

impl Eq for Colorization

Source§

impl StructuralPartialEq for Colorization

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.