style: Using clippy lints

This commit is contained in:
Lukas Wölfer
2026-01-24 09:05:22 +01:00
parent 0081e79492
commit d9eaeb1848
3 changed files with 26 additions and 35 deletions

View File

@@ -2,28 +2,18 @@ use crossterm::cursor::Show;
use crossterm::execute;
use crossterm::terminal::{LeaveAlternateScreen, disable_raw_mode};
pub struct TerminalModeGuard {
active: bool,
}
/// A guard that ensures the terminal is restored to its original state
/// when dropped.
#[derive(Default, Debug)]
pub struct TerminalModeGuard;
impl TerminalModeGuard {
pub fn new() -> Self {
Self { active: true }
}
impl TerminalModeGuard {}
pub fn cleanup(&mut self) {
if !self.active {
return;
}
impl Drop for TerminalModeGuard {
#[allow(clippy::let_underscore_must_use, reason = "We want to ignore errors during cleanup.")]
fn drop(&mut self) {
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();
}
}