refactor: extract terminal guard

This commit is contained in:
Stevan Freeborn
2026-07-28 09:32:43 -05:00
parent dc1b08095c
commit 06d8a6fa8a
+22
View File
@@ -0,0 +1,22 @@
use crossterm::{
ExecutableCommand,
terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
};
use std::io::{self, stdout};
pub struct TerminalGuard;
impl TerminalGuard {
pub fn new() -> Result<Self, io::Error> {
enable_raw_mode()?;
stdout().execute(EnterAlternateScreen)?;
Ok(TerminalGuard)
}
}
impl Drop for TerminalGuard {
fn drop(&mut self) {
let _ = disable_raw_mode();
let _ = stdout().execute(LeaveAlternateScreen);
}
}