diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-04-21 16:30:04 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-21 16:30:04 +0300 |
| commit | 3397e1ce2922c4ae9b814e8110e81de7d201de81 (patch) | |
| tree | c457a7cf0af271dea1a412474fad5a33c1b60be8 /src/selection.rs | |
| parent | 2818ff492d45d17fd4f9b15478d703c6c664a8c0 (diff) | |
feat: add persistent server-client sessions
Make herdr persistent by default.
Launching herdr now starts or reattaches to a background session
server. Clients can detach and reattach while panes and agent
processes keep running. Session mode now supports multi-client attach,
auto-detect startup, and a thin-client/headless-server split.
This also refactors the large app, ui, input, pane, config,
workspace, and persistence modules into smaller focused submodules,
while preserving behavior and colocating tests with the code they
exercise.
Upgrade notes:
- persistence mode is now the default
- in-app quit detaches the current client instead of stopping the server
- use `herdr server stop` to stop the background session
- use `--no-session` for the old single-process behavior
- default socket paths now live under the config directory
Diffstat (limited to 'src/selection.rs')
| -rw-r--r-- | src/selection.rs | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/selection.rs b/src/selection.rs index 9d29b08e..6b2fc093 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -11,7 +11,7 @@ //! coordinates. That keeps selection stable while the pane scrolls. use ratatui::layout::Rect; -use std::io::Write; +use std::{ffi::OsStr, io::Write}; use crate::{layout::PaneId, pane::ScrollMetrics}; @@ -171,6 +171,17 @@ fn osc52_sequence(bytes: &[u8]) -> String { format!("\x1b]52;c;{encoded}\x07") } +fn should_prefer_osc52_for_env(ssh_connection: Option<&OsStr>, ssh_tty: Option<&OsStr>) -> bool { + ssh_connection.is_some() || ssh_tty.is_some() +} + +fn should_prefer_osc52() -> bool { + should_prefer_osc52_for_env( + std::env::var_os("SSH_CONNECTION").as_deref(), + std::env::var_os("SSH_TTY").as_deref(), + ) +} + /// Write clipboard bytes to the system clipboard via OSC 52. /// /// OSC 52 format: `ESC ] 52 ; c ; <base64> BEL` @@ -178,7 +189,7 @@ fn osc52_sequence(bytes: &[u8]) -> String { /// Some terminals still only honor BEL-terminated OSC 52 writes, so herdr /// emits BEL here even though ST works in newer emulators. pub fn write_osc52_bytes(bytes: &[u8]) { - if crate::platform::write_clipboard(bytes) { + if !should_prefer_osc52() && crate::platform::write_clipboard(bytes) { return; } @@ -187,11 +198,6 @@ pub fn write_osc52_bytes(bytes: &[u8]) { let _ = std::io::stdout().flush(); } -/// Write text to the system clipboard via OSC 52. -pub fn write_osc52(text: &str) { - write_osc52_bytes(text.as_bytes()); -} - #[cfg(test)] mod tests { use super::*; @@ -210,6 +216,19 @@ mod tests { } #[test] + fn ssh_sessions_prefer_osc52() { + assert!(should_prefer_osc52_for_env( + Some(OsStr::new("1 2 3 4")), + None + )); + assert!(should_prefer_osc52_for_env( + None, + Some(OsStr::new("/dev/ttys001")) + )); + assert!(!should_prefer_osc52_for_env(None, None)); + } + + #[test] fn ordering_forward() { let sel = make_sel(2, 5, 4, 10); assert_eq!(sel.ordered(), ((2, 5), (4, 10))); |
