Use alternate screen for ssh sessions
All checks were successful
Deploy to VPS / deploy (push) Successful in 1m1s

This commit is contained in:
2025-11-06 21:38:12 +01:00
parent 70e791a78e
commit aeabcb3ddb

View File

@@ -14,18 +14,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
enable_raw_mode()?;
let (mut width, mut height) = crossterm::terminal::size()?;
if width == 0 || height == 0 {
// Fallback for SSH or terminals that don't report size
width = 80;
height = 24;
}
println!("Width: {}, Height: {}", width, height);
// if width < 15 || height < 15 {
// disable_raw_mode()?;
// println!("Your console is too small.");
// return Ok(());
// }
let use_alternate_screen =
std::env::var("SSH_CLIENT").is_err() && std::env::var("SSH_TTY").is_err();
let mut stdout = stdout();
execute!(stdout, EnterAlternateScreen)?;
if use_alternate_screen {
execute!(stdout, EnterAlternateScreen)?;
}
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
@@ -50,6 +48,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
disable_raw_mode()?;
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
if use_alternate_screen {
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
}
Ok(())
}