File: main.rs

package info (click to toggle)
rust-xterm-query 0.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 124 kB
  • sloc: makefile: 2
file content (31 lines) | stat: -rw-r--r-- 1,137 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/// In order to query, go to raw mode, query the terminal, then leave raw mode.
///
/// This example uses crossterm because I'm used to it but you may use other
/// crates to manage raw mode.
fn query(query: &str, timeout_ms: u64) -> Result<String, xterm_query::XQError> {
    use crossterm::terminal::*;
    enable_raw_mode()?;
    let res = xterm_query::query_osc(query, timeout_ms);
    disable_raw_mode()?;
    res
}

/// Ask the terminal whether the Kitty image protocol is supported
pub fn main() {
    let start = std::time::Instant::now();
    match query("\x1b_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\\x1b[c", 50) {
        Err(e) => {
            eprintln!("Error: {}", e);
            println!("(we should assume the Kitty image protocol isn't available)");
        }
        Ok(response) => {
            let kitty_support = response.starts_with("_Gi=31;OK");
            if kitty_support {
                println!("Kitty image protocol IS supported");
            } else {
                println!("Kitty image protocol is NOT supported");
            }
        }
    }
    println!("Operation took {:?}", start.elapsed());
}