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)
| 312 | /// used in performance-critical places. |
| 313 | // TODO(jmmv): Make this efficient and remove the warning above. |
| 314 | pub 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)] |
| 319 | mod tests { |
no test coverage detected