little-kitty 0.0.3

A low-level interface for the Kitty Graphics Protocol
Documentation
use {crossterm::terminal::*, std::io::*};

//
// RawMode
//

/// Terminal raw mode.
///
/// Restores the original mode when dropped.
///
/// It should be constructed *before* acquiring stdout, stderr, and stdin handles.
pub struct RawMode {
    was_raw: bool,
}

impl RawMode {
    /// Constructor.
    pub fn new() -> Result<Self> {
        let was_raw = is_raw_mode_enabled()?;
        if !was_raw {
            enable_raw_mode()?;
        }
        Ok(Self { was_raw })
    }
}

impl Drop for RawMode {
    fn drop(&mut self) {
        if !self.was_raw {
            _ = disable_raw_mode();
        }
    }
}