MCPcopy Create free account
hub / github.com/anomalyco/opencode / getCopyMethod

Function getCopyMethod

packages/tui/src/clipboard.ts:98–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96let copyMethod: Promise<(text: string) => Promise<void>> | undefined
97
98function getCopyMethod() {
99 return (copyMethod ??= (async () => {
100 const { which } = await import("@opencode-ai/core/util/which")
101 const native = copyCommand(platform(), Boolean(process.env.WAYLAND_DISPLAY), (name) => Boolean(which(name)))
102 if (native?.[0] === "osascript") {
103 return async (text: string) => {
104 const escaped = text.replace(/\\/g, "\\\\").replace(/"/g, '\\"')
105 await command("osascript", ["-e", `set the clipboard to "${escaped}"`]).catch(() => undefined)
106 }
107 }
108 if (native) {
109 return async (text: string) => {
110 await command(native[0], native.slice(1), text).catch(() => undefined)
111 }
112 }
113 return async (text: string) => {
114 const { default: clipboardy } = await import("clipboardy")
115 await clipboardy.write(text).catch(() => undefined)
116 }
117 })())
118}
119
120export async function write(text: string) {
121 writeOsc52(text)

Callers 1

writeFunction · 0.85

Calls 4

copyCommandFunction · 0.85
writeMethod · 0.80
commandFunction · 0.70
whichFunction · 0.50

Tested by

no test coverage detected