From 77fcde0a2736c3927d1bc589bd9b4d0173a9df46 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Wed, 10 Jun 2026 02:26:25 +0300 Subject: fix: support paste in modal inputs refs #302 --- src/platform/macos.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/platform/macos.rs') diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 652b7a41..df957652 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -463,6 +463,40 @@ pub fn write_clipboard(bytes: &[u8]) -> bool { ) } +pub fn read_clipboard_text() -> Option { + const MAX_CLIPBOARD_TEXT_BYTES: usize = 1024 * 1024; + + let mut child = Command::new("pbpaste") + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::null()) + .spawn() + .ok()?; + let stdout = child.stdout.take()?; + let read = match read_limited_reader(stdout, MAX_CLIPBOARD_TEXT_BYTES) { + Ok(LimitedRead::Oversized) => { + let _ = child.kill(); + let _ = child.wait(); + return None; + } + Ok(read) => read, + Err(_) => { + let _ = child.kill(); + let _ = child.wait(); + return None; + } + }; + let status = child.wait().ok()?; + if !status.success() { + return None; + } + match read { + LimitedRead::Complete(bytes) => String::from_utf8(bytes).ok(), + LimitedRead::Empty => None, + LimitedRead::Oversized => unreachable!("oversized clipboard text is handled before wait"), + } +} + pub fn open_url(url: &str) -> std::io::Result<()> { Command::new("open") .arg(url) -- cgit v1.2.3