pub struct TermColor {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub index: u8,
}
Expand description

Abstraction for Terminal colors

Container of Terminal Color, for storing is RGB value and it’s color index.

Fields

r: u8

Red channel

g: u8

Green channel

b: u8

Blue channel

index: u8

Implementations

Create a TermColor from 24bit RGB color by finding the best approximate color in the 256 Terminal colors palette

Find the terminal color that minimizes the asimilarity of a general RGB color by a exahustive calculation of quadrances, return the TermColor which minimizes the quadrance.

Calculates the quadrance of two TermColors to measure similarity

The quadrance is a quadratic measure to compare how similar two colors are and is defined by the sum of the squares of the differences of each channel when the two color are equal the quadrance is equal to zero, The biggest the quadrance can be is when comparing opposite colors (as white and black) and can be shown to be three times the maximum value of the channels, in this case each channels has an maximum equal to 255 thus the quadrance(white, black) = 3 * 255 * 255.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

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 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.