MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / write_text

Method write_text

crates/opencode-tui/src/ui/clipboard.rs:54–93  ·  view source on GitHub ↗
(text: &str)

Source from the content-addressed store, hash-verified

52 }
53
54 pub fn write_text(text: &str) -> anyhow::Result<()> {
55 // Always attempt OSC 52 first — works over SSH when the terminal
56 // emulator supports it, even without native clipboard tools.
57 write_osc52(text);
58
59 if cfg!(target_os = "macos") {
60 return write_with_command("pbcopy", &[], text);
61 }
62
63 if cfg!(target_os = "windows") {
64 return write_with_command(
65 "powershell",
66 &[
67 "-NoProfile",
68 "-Command",
69 "[Console]::InputEncoding = [System.Text.Encoding]::UTF8; Set-Clipboard -Value ([Console]::In.ReadToEnd())",
70 ],
71 text,
72 );
73 }
74
75 // Linux: try native clipboard tools, fall back to OSC 52 only.
76 if std::env::var("WAYLAND_DISPLAY").is_ok() {
77 if write_with_command("wl-copy", &[], text).is_ok() {
78 return Ok(());
79 }
80 }
81
82 if write_with_command("xclip", &["-selection", "clipboard"], text).is_ok() {
83 return Ok(());
84 }
85
86 if write_with_command("xsel", &["--clipboard", "--input"], text).is_ok() {
87 return Ok(());
88 }
89
90 // No native tool available — OSC 52 was already sent above,
91 // so the clipboard write likely succeeded via the terminal emulator.
92 Ok(())
93 }
94}
95
96fn write_osc52(text: &str) {

Callers

nothing calls this directly

Calls 2

write_osc52Function · 0.85
write_with_commandFunction · 0.85

Tested by

no test coverage detected