pub fn detect_light(timeout: Duration) -> Option<bool>Expand description
Query the terminal for its background colour and decide light vs.
dark. Returns Some(true) for light, Some(false) for dark,
None when the terminal didn’t respond within timeout.
Implementation (Unix):
- Write OSC 11 query (
ESC ] 11 ; ? BEL) to stdout. - Wait up to
timeoutfor stdin to become readable (libc::poll, single fd). - Read available bytes via
libc::read, parse thergb:RRRR/GGGG/BBBBpayload. - Compute Rec. 709 relative luminance, threshold at 128/255.
Windows / non-Unix: returns None immediately. Windows conhost
doesn’t respond to OSC 11 at all; Windows Terminal does but the
libc::poll path isn’t available there. A future improvement can
add a Win32-specific path via PeekConsoleInput.