refactor: organize host modules and document architecture with UML
Verify Tessera GUI / verify (push) Failing after 2m2s
Verify Tessera GUI / verify (push) Failing after 2m2s
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
//! Clipboard text is always UTF-8, including Finder/LaunchServices launches without LANG.
|
||||
use anyhow::{Result, bail};
|
||||
#[cfg(target_os = "macos")]
|
||||
fn command(program: &str) -> std::process::Command {
|
||||
let mut cmd = std::process::Command::new(program);
|
||||
cmd.env("LC_ALL", "en_US.UTF-8")
|
||||
.env("LC_CTYPE", "en_US.UTF-8")
|
||||
.env("LANG", "en_US.UTF-8");
|
||||
cmd
|
||||
}
|
||||
pub fn read() -> Result<String> {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let output = command("/usr/bin/pbpaste")
|
||||
.arg("-Prefer")
|
||||
.arg("txt")
|
||||
.output()?;
|
||||
if !output.status.success() {
|
||||
bail!("system clipboard read failed");
|
||||
}
|
||||
// Never silently replace invalid bytes in the user's source.
|
||||
Ok(String::from_utf8(output.stdout)?)
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
bail!("system clipboard adapter is not available on this platform")
|
||||
}
|
||||
}
|
||||
pub fn write(value: &str) -> Result<()> {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
use std::io::Write;
|
||||
let mut child = command("/usr/bin/pbcopy")
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.spawn()?;
|
||||
let mut stdin = child
|
||||
.stdin
|
||||
.take()
|
||||
.ok_or_else(|| anyhow::anyhow!("clipboard stdin is unavailable"))?;
|
||||
stdin.write_all(value.as_bytes())?;
|
||||
drop(stdin);
|
||||
if !child.wait()?.success() {
|
||||
bail!("system clipboard write failed");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
let _ = value;
|
||||
bail!("system clipboard adapter is not available on this platform")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user