curd-editor 0.6.0

A small terminal code editor: projects with a file tree, git status, tabs, quick open and language-server support
use std::io::stdout;

use crossterm::{
    event::{
        DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, EnableBracketedPaste,
        EnableFocusChange, EnableMouseCapture,
    },
    execute,
    terminal::{self, EnterAlternateScreen, LeaveAlternateScreen},
};

pub struct Terminal;

impl Terminal {
    pub fn start() -> std::io::Result<Self> {
        terminal::enable_raw_mode()?;
        // Bracketed paste makes the terminal hand over pasted text in one
        // piece, so it can be inserted as-is instead of as typed keys.
        // Mouse capture reports clicks and the wheel; focus reports say when
        // the user comes back from another window.
        execute!(
            stdout(),
            EnterAlternateScreen,
            EnableBracketedPaste,
            EnableMouseCapture,
            EnableFocusChange
        )?;
        Ok(Self)
    }

    pub fn size() -> std::io::Result<(usize, usize)> {
        let (width, height) = terminal::size()?;
        Ok((width as usize, height as usize))
    }
}

impl Drop for Terminal {
    fn drop(&mut self) {
        let _ = execute!(
            stdout(),
            DisableFocusChange,
            DisableMouseCapture,
            DisableBracketedPaste,
            LeaveAlternateScreen
        );
        let _ = terminal::disable_raw_mode();
    }
}