little-kitty 0.0.3

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

use std::{io, sync::atomic::*};

static KITTY_ENABLED: AtomicBool = AtomicBool::new(false);

/// Enable the Kitty graphics protocol if it's supported and not already enabled.
pub fn enable_kitty_if_supported() -> io::Result<bool> {
    Ok(if is_kitty_enabled() {
        true
    } else {
        let is_supported = Command::default().is_supported()?;
        KITTY_ENABLED.store(is_supported, Ordering::SeqCst);
        is_supported
    })
}

/// Whether the Kitty graphics protocol is enabled.
pub fn is_kitty_enabled() -> bool {
    KITTY_ENABLED.load(Ordering::SeqCst)
}

/// Return an error if the Kitty graphics protocol is not enabled.
pub fn ensure_kitty_enabled() -> io::Result<()> {
    if is_kitty_enabled() { Ok(()) } else { Err(io::Error::other("Kitty not enabled")) }
}