From aeabcb3ddb94930375cf1e398d1f38800e88d595 Mon Sep 17 00:00:00 2001 From: dcorral Date: Thu, 6 Nov 2025 21:38:12 +0100 Subject: [PATCH] Use alternate screen for ssh sessions --- src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9ba0a3d..99fa143 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,18 +14,16 @@ fn main() -> Result<(), Box> { 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> { } disable_raw_mode()?; - execute!(terminal.backend_mut(), LeaveAlternateScreen)?; + if use_alternate_screen { + execute!(terminal.backend_mut(), LeaveAlternateScreen)?; + } Ok(()) }