Detect whether the terminal has a light background using OSC 11. Uses `terminal-colorsaurus` to send an OSC 11 query to the terminal, which returns the actual background RGB color. This works reliably on iTerm2, Terminal.app, `WezTerm`, Alacritty, and most modern terminals. Falls back to `false` (dark) if the terminal doesn't respond to the query (e.g. `TERM=dumb`, piped output, very old termina
()
| 218 | /// Falls back to `false` (dark) if the terminal doesn't respond to the |
| 219 | /// query (e.g. `TERM=dumb`, piped output, very old terminals). |
| 220 | fn is_light_terminal() -> bool { |
| 221 | use terminal_colorsaurus::{QueryOptions, ThemeMode as ColorsaurusMode}; |
| 222 | matches!( |
| 223 | terminal_colorsaurus::theme_mode(QueryOptions::default()), |
| 224 | Ok(ColorsaurusMode::Light) |
| 225 | ) |
| 226 | } |
| 227 | |
| 228 | #[cfg(test)] |
| 229 | mod tests { |