refactor: move terminal guard to own file

This commit is contained in:
Lukas Wölfer
2026-01-24 08:50:06 +01:00
parent 15c792fc21
commit 0081e79492
2 changed files with 34 additions and 32 deletions

29
src/terminal_guard.rs Normal file
View File

@@ -0,0 +1,29 @@
use crossterm::cursor::Show;
use crossterm::execute;
use crossterm::terminal::{LeaveAlternateScreen, disable_raw_mode};
pub struct TerminalModeGuard {
active: bool,
}
impl TerminalModeGuard {
pub fn new() -> Self {
Self { active: true }
}
pub fn cleanup(&mut self) {
if !self.active {
return;
}
let _ = disable_raw_mode();
let mut stdout = std::io::stdout();
let _ = execute!(stdout, LeaveAlternateScreen, Show);
self.active = false;
}
}
impl Drop for TerminalModeGuard {
fn drop(&mut self) {
self.cleanup();
}
}