Use alternate screen for ssh sessions
All checks were successful
Deploy to VPS / deploy (push) Successful in 1m1s
All checks were successful
Deploy to VPS / deploy (push) Successful in 1m1s
This commit is contained in:
12
src/main.rs
12
src/main.rs
@@ -14,18 +14,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
enable_raw_mode()?;
|
enable_raw_mode()?;
|
||||||
let (mut width, mut height) = crossterm::terminal::size()?;
|
let (mut width, mut height) = crossterm::terminal::size()?;
|
||||||
if width == 0 || height == 0 {
|
if width == 0 || height == 0 {
|
||||||
// Fallback for SSH or terminals that don't report size
|
|
||||||
width = 80;
|
width = 80;
|
||||||
height = 24;
|
height = 24;
|
||||||
}
|
}
|
||||||
println!("Width: {}, Height: {}", width, height);
|
println!("Width: {}, Height: {}", width, height);
|
||||||
// if width < 15 || height < 15 {
|
let use_alternate_screen =
|
||||||
// disable_raw_mode()?;
|
std::env::var("SSH_CLIENT").is_err() && std::env::var("SSH_TTY").is_err();
|
||||||
// println!("Your console is too small.");
|
|
||||||
// return Ok(());
|
|
||||||
// }
|
|
||||||
let mut stdout = stdout();
|
let mut stdout = stdout();
|
||||||
|
if use_alternate_screen {
|
||||||
execute!(stdout, EnterAlternateScreen)?;
|
execute!(stdout, EnterAlternateScreen)?;
|
||||||
|
}
|
||||||
let backend = CrosstermBackend::new(stdout);
|
let backend = CrosstermBackend::new(stdout);
|
||||||
let mut terminal = Terminal::new(backend)?;
|
let mut terminal = Terminal::new(backend)?;
|
||||||
|
|
||||||
@@ -50,6 +48,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disable_raw_mode()?;
|
disable_raw_mode()?;
|
||||||
|
if use_alternate_screen {
|
||||||
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
|
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user