feat: default editing to shared system clipboard
This commit is contained in:
@@ -0,0 +1,576 @@
|
||||
use std::path::PathBuf;
|
||||
use std::time::Duration;
|
||||
|
||||
const MAX_CLIPBOARD_BYTES: usize = 4 * 1024 * 1024;
|
||||
const COMMAND_TIMEOUT: Duration = Duration::from_secs(2);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
const MAC_READ: &str = r#"
|
||||
ObjC.import('AppKit');
|
||||
function run() {
|
||||
var text = $.NSPasteboard.generalPasteboard.stringForType($.NSPasteboardTypeString);
|
||||
if (text.isNil()) return;
|
||||
$.NSFileHandle.fileHandleWithStandardOutput.writeData(
|
||||
text.dataUsingEncoding($.NSUTF8StringEncoding));
|
||||
}
|
||||
"#;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
const MAC_WRITE: &str = r#"
|
||||
ObjC.import('AppKit');
|
||||
function run() {
|
||||
var data = $.NSFileHandle.fileHandleWithStandardInput.readDataToEndOfFile;
|
||||
var text = $.NSString.alloc.initWithDataEncoding(data, $.NSUTF8StringEncoding);
|
||||
if (text.isNil()) throw Error('Clipboard input is not UTF-8');
|
||||
var pasteboard = $.NSPasteboard.generalPasteboard;
|
||||
pasteboard.clearContents;
|
||||
if (!pasteboard.setStringForType(text, $.NSPasteboardTypeString))
|
||||
throw Error('Cannot write plain-text clipboard');
|
||||
}
|
||||
"#;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum ClipboardMode {
|
||||
System,
|
||||
Separate,
|
||||
}
|
||||
|
||||
struct ClipboardCommand {
|
||||
program: PathBuf,
|
||||
args: &'static [&'static str],
|
||||
}
|
||||
|
||||
struct Commands {
|
||||
reader: ClipboardCommand,
|
||||
writer: ClipboardCommand,
|
||||
}
|
||||
|
||||
pub struct SystemClipboard {
|
||||
commands: Option<Result<Commands, String>>,
|
||||
timeout: Duration,
|
||||
}
|
||||
|
||||
impl Default for SystemClipboard {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl SystemClipboard {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
commands: None,
|
||||
timeout: COMMAND_TIMEOUT,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn with_commands(reader: PathBuf, writer: PathBuf) -> Self {
|
||||
Self {
|
||||
commands: Some(Ok(Commands {
|
||||
reader: ClipboardCommand {
|
||||
program: reader,
|
||||
args: &[],
|
||||
},
|
||||
writer: ClipboardCommand {
|
||||
program: writer,
|
||||
args: &[],
|
||||
},
|
||||
})),
|
||||
timeout: COMMAND_TIMEOUT,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read(&mut self) -> Result<String, String> {
|
||||
let timeout = self.timeout;
|
||||
let commands = self.commands.get_or_insert_with(select_commands);
|
||||
let command = &commands.as_ref().map_err(Clone::clone)?.reader;
|
||||
let bytes = run(command, None, timeout)?;
|
||||
String::from_utf8(bytes).map_err(|_| "System clipboard is not valid UTF-8".into())
|
||||
}
|
||||
|
||||
pub fn write(&mut self, text: &str) -> Result<(), String> {
|
||||
if text.len() > MAX_CLIPBOARD_BYTES {
|
||||
return Err("System clipboard text exceeds 4 MiB".into());
|
||||
}
|
||||
let timeout = self.timeout;
|
||||
let commands = self.commands.get_or_insert_with(select_commands);
|
||||
let command = &commands.as_ref().map_err(Clone::clone)?.writer;
|
||||
run(command, Some(text.as_bytes()), timeout).map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
fn executable(name: &str) -> Option<PathBuf> {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
let paths = std::env::var_os("PATH")?;
|
||||
std::env::split_paths(&paths)
|
||||
.map(|directory| directory.join(name))
|
||||
.find(|path| {
|
||||
path.metadata().is_ok_and(|metadata| {
|
||||
metadata.is_file() && metadata.permissions().mode() & 0o111 != 0
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn select_commands() -> Result<Commands, String> {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
if let Some(program) = executable("osascript") {
|
||||
return Ok(Commands {
|
||||
reader: ClipboardCommand {
|
||||
program: program.clone(),
|
||||
args: &["-l", "JavaScript", "-e", MAC_READ],
|
||||
},
|
||||
writer: ClipboardCommand {
|
||||
program,
|
||||
args: &["-l", "JavaScript", "-e", MAC_WRITE],
|
||||
},
|
||||
});
|
||||
}
|
||||
Err("System clipboard requires osascript with JXA/AppKit on PATH".into())
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if std::env::var_os("WAYLAND_DISPLAY").is_some_and(|value| !value.is_empty()) {
|
||||
if let (Some(reader), Some(writer)) = (executable("wl-paste"), executable("wl-copy")) {
|
||||
return Ok(Commands {
|
||||
reader: ClipboardCommand {
|
||||
program: reader,
|
||||
args: &["--no-newline", "--type", "text"],
|
||||
},
|
||||
writer: ClipboardCommand {
|
||||
program: writer,
|
||||
args: &["--type", "text/plain;charset=utf-8"],
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
if std::env::var_os("DISPLAY").is_some_and(|value| !value.is_empty()) {
|
||||
if let Some(program) = executable("xclip") {
|
||||
return Ok(Commands {
|
||||
reader: ClipboardCommand {
|
||||
program: program.clone(),
|
||||
args: &["-selection", "clipboard", "-target", "UTF8_STRING", "-out"],
|
||||
},
|
||||
writer: ClipboardCommand {
|
||||
program,
|
||||
args: &["-selection", "clipboard", "-target", "UTF8_STRING", "-in"],
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Err("System clipboard requires Wayland with wl-paste/wl-copy or X11 with xclip".into())
|
||||
}
|
||||
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
|
||||
{
|
||||
Err("System clipboard is unsupported on this platform".into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
|
||||
fn run(_: &ClipboardCommand, _: Option<&[u8]>, _: Duration) -> Result<Vec<u8>, String> {
|
||||
Err("System clipboard is unsupported on this platform".into())
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
fn run(
|
||||
command: &ClipboardCommand,
|
||||
input: Option<&[u8]>,
|
||||
timeout: Duration,
|
||||
) -> Result<Vec<u8>, String> {
|
||||
use std::io::{self, Read, Write};
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::time::Instant;
|
||||
|
||||
let mut command_process = Command::new(&command.program);
|
||||
command_process
|
||||
.args(command.args)
|
||||
.process_group(0)
|
||||
.stdin(if input.is_some() {
|
||||
Stdio::piped()
|
||||
} else {
|
||||
Stdio::null()
|
||||
})
|
||||
.stdout(if input.is_none() {
|
||||
Stdio::piped()
|
||||
} else {
|
||||
Stdio::null()
|
||||
})
|
||||
// Native tools may echo input in diagnostics. Never capture or surface stderr.
|
||||
.stderr(Stdio::null());
|
||||
let child = command_process
|
||||
.spawn()
|
||||
.map_err(|error| format!("Cannot start system clipboard command: {error}"))?;
|
||||
let mut process = ClipboardProcess(Some(child));
|
||||
let child = process.0.as_mut().expect("clipboard child exists");
|
||||
let mut stdin = child.stdin.take();
|
||||
let mut stdout = child.stdout.take();
|
||||
if let Some(pipe) = &stdin {
|
||||
nonblocking(pipe).map_err(|error| format!("Cannot open clipboard input: {error}"))?;
|
||||
}
|
||||
if let Some(pipe) = &stdout {
|
||||
nonblocking(pipe).map_err(|error| format!("Cannot open clipboard output: {error}"))?;
|
||||
}
|
||||
let started = Instant::now();
|
||||
let mut written = 0;
|
||||
let mut output = Vec::new();
|
||||
let mut status = None;
|
||||
let mut chunk = [0_u8; 8192];
|
||||
loop {
|
||||
if started.elapsed() >= timeout {
|
||||
return Err("System clipboard command timed out".into());
|
||||
}
|
||||
let mut progressed = false;
|
||||
if let Some(pipe) = stdin.as_mut() {
|
||||
let bytes = input.expect("input pipe has bytes");
|
||||
if written == bytes.len() {
|
||||
stdin.take();
|
||||
progressed = true;
|
||||
} else {
|
||||
let end = bytes.len().min(written + chunk.len());
|
||||
match pipe.write(&bytes[written..end]) {
|
||||
Ok(0) => return Err("System clipboard command closed its input".into()),
|
||||
Ok(count) => {
|
||||
written += count;
|
||||
progressed = true;
|
||||
}
|
||||
Err(error)
|
||||
if matches!(
|
||||
error.kind(),
|
||||
io::ErrorKind::WouldBlock | io::ErrorKind::Interrupted
|
||||
) => {}
|
||||
Err(error) => return Err(format!("System clipboard write failed: {error}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(pipe) = stdout.as_mut() {
|
||||
let limit = chunk.len().min(MAX_CLIPBOARD_BYTES + 1 - output.len());
|
||||
match pipe.read(&mut chunk[..limit]) {
|
||||
Ok(0) => {
|
||||
stdout.take();
|
||||
progressed = true;
|
||||
}
|
||||
Ok(count) => {
|
||||
if output.len() + count > MAX_CLIPBOARD_BYTES {
|
||||
return Err("System clipboard text exceeds 4 MiB".into());
|
||||
}
|
||||
output.extend_from_slice(&chunk[..count]);
|
||||
progressed = true;
|
||||
}
|
||||
Err(error)
|
||||
if matches!(
|
||||
error.kind(),
|
||||
io::ErrorKind::WouldBlock | io::ErrorKind::Interrupted
|
||||
) => {}
|
||||
Err(error) => return Err(format!("System clipboard read failed: {error}")),
|
||||
}
|
||||
}
|
||||
if status.is_none() {
|
||||
status = process
|
||||
.0
|
||||
.as_mut()
|
||||
.expect("clipboard child exists")
|
||||
.try_wait()
|
||||
.map_err(|error| format!("Cannot wait for system clipboard command: {error}"))?;
|
||||
}
|
||||
if let Some(exit) = status {
|
||||
if !exit.success() {
|
||||
return Err(format!("System clipboard command failed ({exit})"));
|
||||
}
|
||||
if stdin.is_none() && stdout.is_none() {
|
||||
// Clipboard owners (wl-copy/xclip) intentionally leave a serving child alive.
|
||||
process.0.take();
|
||||
return Ok(output);
|
||||
}
|
||||
}
|
||||
if !progressed {
|
||||
let remaining = timeout.saturating_sub(started.elapsed());
|
||||
wait_for_pipes(stdin.as_ref(), stdout.as_ref(), remaining)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
struct ClipboardProcess(Option<std::process::Child>);
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
impl Drop for ClipboardProcess {
|
||||
fn drop(&mut self) {
|
||||
if let Some(mut child) = self.0.take() {
|
||||
// Also close inherited pipes held by descendants, as in the Ruby host runner.
|
||||
// SAFETY: spawn placed this child in a process group with its own PID.
|
||||
unsafe {
|
||||
kill(-(child.id() as i32), 9);
|
||||
}
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
fn nonblocking(pipe: &impl std::os::fd::AsRawFd) -> std::io::Result<()> {
|
||||
#[cfg(target_os = "macos")]
|
||||
const O_NONBLOCK: i32 = 0x0004;
|
||||
#[cfg(target_os = "linux")]
|
||||
const O_NONBLOCK: i32 = 0x0800;
|
||||
// SAFETY: the descriptor is borrowed from a live child pipe; F_GETFL/F_SETFL
|
||||
// inspect/change flags only and neither consume the descriptor nor access pointers.
|
||||
unsafe {
|
||||
let flags = fcntl(pipe.as_raw_fd(), 3);
|
||||
if flags == -1 || fcntl(pipe.as_raw_fd(), 4, flags | O_NONBLOCK) == -1 {
|
||||
Err(std::io::Error::last_os_error())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
#[repr(C)]
|
||||
struct PollFd {
|
||||
fd: i32,
|
||||
events: i16,
|
||||
revents: i16,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
type PollCount = u32;
|
||||
#[cfg(target_os = "linux")]
|
||||
type PollCount = usize;
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
fn wait_for_pipes(
|
||||
stdin: Option<&std::process::ChildStdin>,
|
||||
stdout: Option<&std::process::ChildStdout>,
|
||||
remaining: Duration,
|
||||
) -> Result<(), String> {
|
||||
use std::os::fd::AsRawFd;
|
||||
|
||||
let mut pipes = [
|
||||
PollFd {
|
||||
fd: stdin.map_or(-1, AsRawFd::as_raw_fd),
|
||||
events: 4,
|
||||
revents: 0,
|
||||
},
|
||||
PollFd {
|
||||
fd: stdout.map_or(-1, AsRawFd::as_raw_fd),
|
||||
events: 1,
|
||||
revents: 0,
|
||||
},
|
||||
];
|
||||
// Recheck process completion at least every 5 ms, waking immediately on pipe readiness.
|
||||
let milliseconds = remaining.as_millis().min(5) as i32;
|
||||
// SAFETY: the C-compatible array is live for the call; negative descriptors are ignored.
|
||||
if unsafe { poll(pipes.as_mut_ptr(), pipes.len() as PollCount, milliseconds) } == -1 {
|
||||
let error = std::io::Error::last_os_error();
|
||||
if error.kind() != std::io::ErrorKind::Interrupted {
|
||||
return Err(format!("Cannot poll system clipboard command: {error}"));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
unsafe extern "C" {
|
||||
fn fcntl(fd: i32, command: i32, ...) -> i32;
|
||||
fn kill(pid: i32, signal: i32) -> i32;
|
||||
fn poll(fds: *mut PollFd, count: PollCount, timeout: i32) -> i32;
|
||||
}
|
||||
|
||||
#[cfg(all(test, any(target_os = "macos", target_os = "linux")))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
static FIXTURE_ID: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
struct Fixture(PathBuf);
|
||||
|
||||
impl Fixture {
|
||||
fn new() -> Self {
|
||||
let path = std::env::temp_dir().join(format!(
|
||||
"vamp-clipboard-{}-{}",
|
||||
std::process::id(),
|
||||
FIXTURE_ID.fetch_add(1, Ordering::Relaxed)
|
||||
));
|
||||
fs::create_dir(&path).unwrap();
|
||||
Self(path)
|
||||
}
|
||||
|
||||
fn command(&self, name: &str, body: &str) -> PathBuf {
|
||||
let path = self.0.join(name);
|
||||
fs::write(&path, format!("#!/bin/sh\n{body}\n")).unwrap();
|
||||
fs::set_permissions(&path, fs::Permissions::from_mode(0o700)).unwrap();
|
||||
path
|
||||
}
|
||||
|
||||
fn clipboard(&self, text: &[u8]) -> SystemClipboard {
|
||||
let state = self.0.join("state");
|
||||
fs::write(&state, text).unwrap();
|
||||
let state = format!("'{}'", state.to_str().unwrap().replace('\'', "'\\''"));
|
||||
SystemClipboard::with_commands(
|
||||
self.command("read", &format!("exec /bin/cat {state}")),
|
||||
self.command("write", &format!("exec /bin/cat > {state}")),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Fixture {
|
||||
fn drop(&mut self) {
|
||||
fs::remove_dir_all(&self.0).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn construction_does_not_probe_or_spawn() {
|
||||
assert!(SystemClipboard::new().commands.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trips_unicode_whitespace_and_large_pipes_exactly() {
|
||||
let fixture = Fixture::new();
|
||||
let mut clipboard = fixture.clipboard(b"");
|
||||
for text in ["", " héllo\t世界🙂\r\n\n", &"é\n".repeat(300_000)] {
|
||||
clipboard.write(text).unwrap();
|
||||
assert_eq!(fs::read(fixture.0.join("state")).unwrap(), text.as_bytes());
|
||||
assert_eq!(clipboard.read().unwrap(), text);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_oversize_and_invalid_utf8_without_leaking_contents() {
|
||||
let fixture = Fixture::new();
|
||||
let mut clipboard = fixture.clipboard(&[0xff, b'\n']);
|
||||
assert_eq!(
|
||||
clipboard.read().unwrap_err(),
|
||||
"System clipboard is not valid UTF-8"
|
||||
);
|
||||
let maximum = "é".repeat(MAX_CLIPBOARD_BYTES / 2);
|
||||
clipboard.write(&maximum).unwrap();
|
||||
assert_eq!(clipboard.read().unwrap(), maximum);
|
||||
let too_large = format!("{maximum}x");
|
||||
assert_eq!(
|
||||
clipboard.write(&too_large).unwrap_err(),
|
||||
"System clipboard text exceeds 4 MiB"
|
||||
);
|
||||
assert_eq!(
|
||||
fs::read(fixture.0.join("state")).unwrap(),
|
||||
maximum.as_bytes()
|
||||
);
|
||||
fs::write(fixture.0.join("state"), &too_large).unwrap();
|
||||
assert_eq!(
|
||||
clipboard.read().unwrap_err(),
|
||||
"System clipboard text exceeds 4 MiB"
|
||||
);
|
||||
let mut incomplete = vec![b'x'; MAX_CLIPBOARD_BYTES - 1];
|
||||
incomplete.push(0xc3);
|
||||
fs::write(fixture.0.join("state"), incomplete).unwrap();
|
||||
assert_eq!(
|
||||
clipboard.read().unwrap_err(),
|
||||
"System clipboard is not valid UTF-8"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_failures_and_stderr_cannot_leak_clipboard_text() {
|
||||
let fixture = Fixture::new();
|
||||
let failed = fixture.command(
|
||||
"failed",
|
||||
"printf 'private clipboard payload' >&2\nprintf 'private clipboard payload'\nexit 23",
|
||||
);
|
||||
let mut clipboard = SystemClipboard::with_commands(failed.clone(), failed);
|
||||
let error = clipboard.read().unwrap_err();
|
||||
assert!(error.contains("failed"));
|
||||
assert!(!error.contains("private clipboard payload"));
|
||||
let error = clipboard.write("private clipboard payload").unwrap_err();
|
||||
assert!(!error.contains("private clipboard payload"));
|
||||
let missing = fixture.0.join("not-an-executable");
|
||||
let mut clipboard = SystemClipboard::with_commands(missing.clone(), missing);
|
||||
assert!(clipboard.read().unwrap_err().contains("Cannot start"));
|
||||
assert!(
|
||||
clipboard
|
||||
.write("secret")
|
||||
.unwrap_err()
|
||||
.contains("Cannot start")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignored_stderr_does_not_block_large_writes() {
|
||||
let fixture = Fixture::new();
|
||||
let mut clipboard = fixture.clipboard(b"");
|
||||
let state = fixture.0.join("state");
|
||||
let state = format!("'{}'", state.to_str().unwrap().replace('\'', "'\\''"));
|
||||
clipboard
|
||||
.commands
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.writer
|
||||
.program = fixture.command(
|
||||
"noisy",
|
||||
&format!("/bin/dd if=/dev/zero bs=65536 count=8 >&2\nexec /bin/cat > {state}"),
|
||||
);
|
||||
let text = "λ\n".repeat(300_000);
|
||||
clipboard.write(&text).unwrap();
|
||||
assert_eq!(clipboard.read().unwrap(), text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_process_cleanup_kills_and_reaps_a_running_child() {
|
||||
use std::io::Read;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
unsafe extern "C" {
|
||||
fn waitpid(pid: i32, status: *mut i32, options: i32) -> i32;
|
||||
}
|
||||
|
||||
let fixture = Fixture::new();
|
||||
let hung = fixture.command("running", "printf R\nwhile :; do :; done");
|
||||
let mut command = Command::new(hung);
|
||||
command
|
||||
.process_group(0)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null());
|
||||
let mut child = command.spawn().unwrap();
|
||||
let pid = child.id() as i32;
|
||||
let mut ready = [0];
|
||||
child
|
||||
.stdout
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.read_exact(&mut ready)
|
||||
.unwrap();
|
||||
assert_eq!(ready, [b'R']);
|
||||
drop(ClipboardProcess(Some(child)));
|
||||
let mut status = 0;
|
||||
// SAFETY: waitpid's output pointer is valid; WNOHANG cannot block this check.
|
||||
assert_eq!(unsafe { waitpid(pid, &mut status, 1) }, -1);
|
||||
assert_eq!(std::io::Error::last_os_error().raw_os_error(), Some(10));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn immediate_injected_timeout_terminates_nonterminating_commands() {
|
||||
let fixture = Fixture::new();
|
||||
let hung = fixture.command("hung", "while :; do :; done");
|
||||
let mut clipboard = SystemClipboard::with_commands(hung.clone(), hung);
|
||||
// No assertion depends on wall-clock speed or a deadline remaining in the future.
|
||||
clipboard.timeout = Duration::ZERO;
|
||||
assert_eq!(
|
||||
clipboard.read().unwrap_err(),
|
||||
"System clipboard command timed out"
|
||||
);
|
||||
assert_eq!(
|
||||
clipboard.write("text").unwrap_err(),
|
||||
"System clipboard command timed out"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user