better cleanup implemented
This commit is contained in:
@@ -6,7 +6,7 @@ use crossterm::{
|
|||||||
};
|
};
|
||||||
use crossterm::cursor::{SetCursorStyle, EnableBlinking};
|
use crossterm::cursor::{SetCursorStyle, EnableBlinking};
|
||||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
use ratatui::{backend::CrosstermBackend, Terminal};
|
||||||
use std::io::{self, stdout};
|
use std::io::{self, stdout, Write};
|
||||||
use tonic::transport::Channel;
|
use tonic::transport::Channel;
|
||||||
use ratatui::backend::Backend;
|
use ratatui::backend::Backend;
|
||||||
|
|
||||||
@@ -73,20 +73,32 @@ impl AppTerminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn cleanup(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn cleanup(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Disable raw mode first
|
// Get a separate stdout handle for cleanup operations
|
||||||
let _ = disable_raw_mode(); // Ignore errors as we're cleaning up
|
let mut stdout = stdout();
|
||||||
|
|
||||||
// Execute cleanup commands
|
// Step 1: Show cursor first (most important for user experience)
|
||||||
|
execute!(stdout, crossterm::cursor::Show)?;
|
||||||
|
|
||||||
|
// Step 2: Reset cursor style to default
|
||||||
|
execute!(stdout, crossterm::cursor::SetCursorStyle::DefaultUserShape)?;
|
||||||
|
|
||||||
|
// Step 3: Leave alternate screen mode
|
||||||
|
execute!(stdout, crossterm::terminal::LeaveAlternateScreen)?;
|
||||||
|
|
||||||
|
// Step 4: Disable raw mode
|
||||||
|
disable_raw_mode()?;
|
||||||
|
|
||||||
|
// Step 5: Flush all pending changes to ensure they're applied
|
||||||
|
stdout.flush()?;
|
||||||
|
|
||||||
|
// Step 6: Final reset - clear screen and move cursor to home position
|
||||||
|
// This ensures terminal is in a known good state
|
||||||
execute!(
|
execute!(
|
||||||
self.terminal.backend_mut(),
|
stdout,
|
||||||
crossterm::terminal::LeaveAlternateScreen,
|
crossterm::terminal::Clear(crossterm::terminal::ClearType::All),
|
||||||
crossterm::cursor::SetCursorStyle::DefaultUserShape,
|
crossterm::cursor::MoveTo(0, 0)
|
||||||
crossterm::cursor::Show,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Ensure all commands are flushed using the Backend trait's flush
|
|
||||||
self.terminal.backend_mut().flush()?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user