better cleanup implemented
This commit is contained in:
@@ -6,7 +6,7 @@ use crossterm::{
|
||||
};
|
||||
use crossterm::cursor::{SetCursorStyle, EnableBlinking};
|
||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
||||
use std::io::{self, stdout};
|
||||
use std::io::{self, stdout, Write};
|
||||
use tonic::transport::Channel;
|
||||
use ratatui::backend::Backend;
|
||||
|
||||
@@ -73,20 +73,32 @@ impl AppTerminal {
|
||||
}
|
||||
|
||||
pub fn cleanup(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Disable raw mode first
|
||||
let _ = disable_raw_mode(); // Ignore errors as we're cleaning up
|
||||
// Get a separate stdout handle for cleanup operations
|
||||
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!(
|
||||
self.terminal.backend_mut(),
|
||||
crossterm::terminal::LeaveAlternateScreen,
|
||||
crossterm::cursor::SetCursorStyle::DefaultUserShape,
|
||||
crossterm::cursor::Show,
|
||||
stdout,
|
||||
crossterm::terminal::Clear(crossterm::terminal::ClearType::All),
|
||||
crossterm::cursor::MoveTo(0, 0)
|
||||
)?;
|
||||
|
||||
// Ensure all commands are flushed using the Backend trait's flush
|
||||
self.terminal.backend_mut().flush()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user