little-kitty 0.0.3

A low-level interface for the Kitty Graphics Protocol
Documentation
use little_kitty::command::*;

fn main() {
    println!("Kitty supported: {}", Command::default().is_supported().expect("is_supported"));

    // This query should always return OK when Kitty is supported

    print_response(
        Command::default()
            // Action = query
            .with_control('a', 'q')
            // Image ID
            .with_control('i', 1)
            // format = RGBA (24 bits)
            .with_control('f', 24)
            // Image width
            .with_control('s', 1)
            // Image height
            .with_control('v', 1)
            .with_expect_response()
            .execute_with_payload(b"AAAA") // 24 bits in Base64
            .expect("execute_with_payload"),
    );

    // This command should always return an error when Kitty is supported

    print_response(
        Command::default()
            // Image ID
            .with_control('i', 1)
            // Transmission medium = shared memory object
            .with_control('t', 's')
            .with_expect_response()
            .execute_with_payload(b"not a shared memory object")
            .expect("execute_with_payload"),
    );
}

fn print_response(response: Option<Response>) {
    match response {
        Some(response) => {
            if response.is_ok() {
                println!("OK!")
            } else {
                println!("Error message: {}", response.message.expect("message"))
            }
        }

        None => println!("No response"),
    }
}