diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-09-02 16:09:19 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-02 16:09:19 +0300 |
| commit | d08e44686d8b19bd9555cc99ec9068d9fde05f16 (patch) | |
| tree | ca2f34d2117efbf770095c437f9d6402c24d9fb3 /src/platform | |
| parent | 8633a398e653eee47b375c963996c78a8a14aa48 (diff) | |
fix(client): detach when terminal geometry is unavailable (#3531)
refs #3519
Diffstat (limited to 'src/platform')
| -rw-r--r-- | src/platform/fallback.rs | 5 | ||||
| -rw-r--r-- | src/platform/mod.rs | 17 | ||||
| -rw-r--r-- | src/platform/unix_common.rs | 4 | ||||
| -rw-r--r-- | src/platform/windows.rs | 4 |
4 files changed, 30 insertions, 0 deletions
diff --git a/src/platform/fallback.rs b/src/platform/fallback.rs index 7e14dcd8..09d82c6c 100644 --- a/src/platform/fallback.rs +++ b/src/platform/fallback.rs @@ -13,6 +13,11 @@ pub(crate) fn set_default_plugin_pane_pwd( ) { } +#[cfg(not(unix))] +pub(super) fn read_terminal_grid_size() -> std::io::Result<(u16, u16)> { + crossterm::terminal::size() +} + pub(crate) fn remote_ssh_config_paths() -> super::RemoteSshConfigPaths { super::RemoteSshConfigPaths { user_config: std::env::var_os("HOME") diff --git a/src/platform/mod.rs b/src/platform/mod.rs index fc80bc64..b831e120 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -69,6 +69,23 @@ pub(crate) const fn capabilities() -> PlatformCapabilities { } } +pub(crate) fn terminal_grid_size() -> std::io::Result<(u16, u16)> { + #[cfg(unix)] + let (cols, rows) = unix_common::read_terminal_grid_size()?; + #[cfg(windows)] + let (cols, rows) = windows::read_terminal_grid_size()?; + #[cfg(not(any(unix, windows)))] + let (cols, rows) = fallback::read_terminal_grid_size()?; + + if cols == 0 || rows == 0 { + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, + "terminal reported a zero-sized grid", + )); + } + Ok((cols, rows)) +} + #[cfg(not(windows))] pub fn launch_server_daemon_command(command: &mut std::process::Command) -> std::io::Result<u32> { command.spawn().map(|child| child.id()) diff --git a/src/platform/unix_common.rs b/src/platform/unix_common.rs index ce5bba00..a7926c22 100644 --- a/src/platform/unix_common.rs +++ b/src/platform/unix_common.rs @@ -1,5 +1,9 @@ use std::path::{Path, PathBuf}; +pub(super) fn read_terminal_grid_size() -> std::io::Result<(u16, u16)> { + crossterm::terminal::window_size().map(|size| (size.columns, size.rows)) +} + fn set_sigpipe_disposition(handler: libc::sighandler_t) { let mut action: libc::sigaction = unsafe { std::mem::zeroed() }; action.sa_sigaction = handler; diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 2fdba9c8..b05b9e6f 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -15,6 +15,10 @@ use std::{ mod clipboard_image; +pub(super) fn read_terminal_grid_size() -> std::io::Result<(u16, u16)> { + crossterm::terminal::size() +} + pub(crate) fn replace_file( source: &std::path::Path, destination: &std::path::Path, |
