xterm-query 0.6.0

query your terminal
Documentation

MIT Latest Version docs Chat on Miaou

Query the terminal by writing an escape sequence and reading the reply.

The terminal must be in raw mode (otherwise reads block on a newline), and the query should be issued when nothing else is reading terminal input.

The provided example in examples/kitty demonstrates querying the terminal to know whether the Kitty graphics protocol is supported, and manages entering and leaving raw mode.

Platform support

This crate supports Linux, MacOS, and Windows. When a platform is not supported, the query functions return XQError::Unsupported.

Unix reads the reply from /dev/tty using poll/select. Windows reads it from the console input (CONIN$) after switching it to ENABLE_VIRTUAL_TERMINAL_INPUT for the duration of the query.

Windows limitation

The Windows wait wakes on any console input event, including focus, mouse, and buffer-resize events, which under VT-input mode may be delivered as escape sequences. If such an event arrives in the query window, the reply can be wrong or empty, so callers should treat an unparsable reply as "unsupported" and degrade gracefully. Issue queries while the terminal is otherwise quiet (e.g. at startup, before an input loop begins).