MCPcopy Create free account
hub / github.com/GCWing/BitFun / readable_foreground_for

Function readable_foreground_for

src/apps/cli/src/ui/theme.rs:545–574  ·  view source on GitHub ↗
(background: Color)

Source from the content-addressed store, hash-verified

543}
544
545fn readable_foreground_for(background: Color) -> Color {
546 match background {
547 Color::Reset => Color::Reset,
548 Color::Black
549 | Color::Red
550 | Color::Green
551 | Color::Blue
552 | Color::Magenta
553 | Color::DarkGray => Color::White,
554 Color::Yellow
555 | Color::Gray
556 | Color::LightRed
557 | Color::LightGreen
558 | Color::LightYellow
559 | Color::LightBlue
560 | Color::LightMagenta
561 | Color::LightCyan
562 | Color::White
563 | Color::Cyan => Color::Black,
564 Color::Indexed(idx) => readable_foreground_for(idx_to_ansi16(idx)),
565 Color::Rgb(r, g, b) => {
566 let lum = relative_luminance(r, g, b);
567 if lum > 0.36 {
568 Color::Black
569 } else {
570 Color::White
571 }
572 }
573 }
574}
575
576fn relative_luminance(r: u8, g: u8, b: u8) -> f64 {
577 fn channel(v: u8) -> f64 {

Callers 1

selection_foregroundMethod · 0.85

Calls 2

idx_to_ansi16Function · 0.85
relative_luminanceFunction · 0.85

Tested by

no test coverage detected