MCPcopy Index your code
hub / github.com/endbasic/endbasic / rgb_to_ansi_color

Function rgb_to_ansi_color

std/src/console/colors.rs:314–316  ·  view source on GitHub ↗

Converts an RGB color to an ANSI color number if there is an exact match. This function does a linear scan of the known colors table and, as such, should not be used in performance-critical places. TODO(jmmv): Make this efficient and remove the warning above.

(rgb: RGB)

Source from the content-addressed store, hash-verified

312/// used in performance-critical places.
313// TODO(jmmv): Make this efficient and remove the warning above.
314pub fn rgb_to_ansi_color(rgb: RGB) -> Option<u8> {
315 COLORS.iter().position(|candidate| *candidate == rgb).map(|index| index as u8)
316}
317
318#[cfg(test)]
319mod tests {

Callers 3

peek_pixelMethod · 0.85
set_draw_colorMethod · 0.85
peek_pixelMethod · 0.85

Calls 1

iterMethod · 0.80

Tested by

no test coverage detected