From f077edaf11fe0ca681d4138104578049ee9ef16d Mon Sep 17 00:00:00 2001 From: won Date: Fri, 27 Feb 2026 00:14:56 -0800 Subject: [PATCH] /dev/tty --- codex-rs/tui/src/clipboard_text.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/codex-rs/tui/src/clipboard_text.rs b/codex-rs/tui/src/clipboard_text.rs index 452a9bd486..931bd1b343 100644 --- a/codex-rs/tui/src/clipboard_text.rs +++ b/codex-rs/tui/src/clipboard_text.rs @@ -2,10 +2,12 @@ use base64::Engine as _; #[cfg(not(target_os = "android"))] use std::ffi::OsStr; -#[cfg(not(target_os = "android"))] +#[cfg(all(not(target_os = "android"), unix))] use std::fs::OpenOptions; #[cfg(not(target_os = "android"))] use std::io::Write; +#[cfg(all(not(target_os = "android"), windows))] +use std::io::stdout; #[cfg(all(not(target_os = "android"), target_os = "linux"))] use std::process::Stdio; @@ -30,18 +32,29 @@ pub fn copy_text_to_clipboard(text: &str) -> Result<(), String> { ) { ClipboardCopyPath::Osc52 => { let sequence = osc52_sequence(text, std::env::var_os("TMUX").is_some()); + #[cfg(unix)] let mut tty = OpenOptions::new() .write(true) .open("/dev/tty") .map_err(|e| { format!("clipboard unavailable: failed to open /dev/tty for OSC 52 copy: {e}") })?; + #[cfg(unix)] tty.write_all(sequence.as_bytes()).map_err(|e| { format!("clipboard unavailable: failed to write OSC 52 escape sequence: {e}") })?; + #[cfg(unix)] tty.flush().map_err(|e| { format!("clipboard unavailable: failed to flush OSC 52 escape sequence: {e}") })?; + #[cfg(windows)] + stdout().write_all(sequence.as_bytes()).map_err(|e| { + format!("clipboard unavailable: failed to write OSC 52 escape sequence: {e}") + })?; + #[cfg(windows)] + stdout().flush().map_err(|e| { + format!("clipboard unavailable: failed to flush OSC 52 escape sequence: {e}") + })?; Ok(()) } #[cfg(target_os = "linux")]