Function ansi_colours::ansi256_from_rgb[][src]

pub fn ansi256_from_rgb<C: AsRGB>(rgb: C) -> u8

Returns index of a colour in 256-colour ANSI palette approximating given sRGB colour.

Because the first 16 colours of the palette are not standardised and usually user-configurable, the function essentially ignores them.

Th first argument uses AsRGB trait so that the function can be called in multiple ways using different representations of RGB colours such as 0xRRGGBB integer, (r, g, b) tuple or [r, g, b] array.

Examples

assert_eq!( 16, ansi_colours::ansi256_from_rgb(0x000000));
assert_eq!( 16, ansi_colours::ansi256_from_rgb( (  1,   1,   1)));
assert_eq!( 16, ansi_colours::ansi256_from_rgb( [  0,   1,   2]));
assert_eq!( 67, ansi_colours::ansi256_from_rgb(&( 95, 135, 175)));
assert_eq!(231, ansi_colours::ansi256_from_rgb(&[255, 255, 255]));