aboutsummaryrefslogtreecommitdiff
path: root/src/selection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/selection.rs')
-rw-r--r--src/selection.rs33
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)));