terminal-colorsaurus 1.0.3

A cross-platform library for determining the terminal's background and foreground color. It answers the question «Is this terminal dark or light?».
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use super::super::read_timed_out;
use std::io;
use std::os::windows::io::AsRawHandle as _;
use std::time::Duration;
use terminal_trx::Transceive;
use windows_sys::Win32::Foundation::{WAIT_ABANDONED, WAIT_OBJECT_0, WAIT_TIMEOUT};
use windows_sys::Win32::System::Threading::WaitForSingleObject;

pub(crate) fn poll_read(terminal: &dyn Transceive, timeout: Duration) -> io::Result<()> {
    let handle = terminal.input_buffer_handle();
    match unsafe { WaitForSingleObject(handle.as_raw_handle(), timeout.as_millis() as u32) } {
        // The state of the specified object is signaled.
        WAIT_OBJECT_0 => Ok(()),
        WAIT_ABANDONED | WAIT_TIMEOUT => Err(read_timed_out()),
        _ => Err(io::Error::last_os_error()),
    }
}