style: Using clippy lints
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user