pub struct Colors {
    pub foreground: Option<Color>,
    pub background: Option<Color>,
}
Expand description

Represents, optionally, a foreground and/or a background color.

It can be applied using the SetColors command.

It can also be created from a Colored value or a tuple of (Color, Color) in the order (foreground, background).

The then method can be used to combine Colors values.

For example:

use crossterm::style::{Color, Colors, Colored};

// An example color, loaded from a config, file in ANSI format.
let config_color = "38;2;23;147;209";

// Default to green text on a black background.
let default_colors = Colors::new(Color::Green, Color::Black);
// Load a colored value from a config and override the default colors
let colors = match Colored::parse_ansi(config_color) {
    Some(colored) => default_colors.then(&colored.into()),
    None => default_colors,
};

See Color.

Fields

foreground: Option<Color>background: Option<Color>

Implementations

Returns a new Color which, when applied, has the same effect as applying self and then other.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.