MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / copyTextToClipboard

Function copyTextToClipboard

cli/src/utils/clipboard.ts:86–133  ·  view source on GitHub ↗
(
  text: string,
  {
    successMessage,
    errorMessage,
    durationMs,
    suppressGlobalMessage = false,
  }: CopyToClipboardOptions = {},
)

Source from the content-addressed store, hash-verified

84}
85
86export async function copyTextToClipboard(
87 text: string,
88 {
89 successMessage,
90 errorMessage,
91 durationMs,
92 suppressGlobalMessage = false,
93 }: CopyToClipboardOptions = {},
94) {
95 if (!text || text.trim().length === 0) {
96 return
97 }
98
99 try {
100 let copied: boolean
101 if (isRemoteSession()) {
102 // Remote/SSH: prefer renderer OSC 52 (through render pipeline),
103 // then our manual OSC 52, then platform tools
104 copied = tryCopyViaRenderer(text) || tryCopyViaOsc52(text) || tryCopyViaPlatformTool(text)
105 } else {
106 // Local: prefer platform tools (reliable with tmux),
107 // then renderer OSC 52, then our manual OSC 52 as fallback
108 copied = tryCopyViaPlatformTool(text) || tryCopyViaRenderer(text) || tryCopyViaOsc52(text)
109 }
110
111 if (!copied) {
112 throw new Error('No clipboard method available')
113 }
114
115 if (!suppressGlobalMessage) {
116 const message =
117 successMessage !== undefined
118 ? successMessage
119 : getDefaultSuccessMessage(text)
120 if (message) {
121 showClipboardMessage(message, { durationMs })
122 }
123 }
124 } catch (error) {
125 logger.error(error, 'Failed to copy to clipboard')
126 if (!suppressGlobalMessage) {
127 showClipboardMessage(errorMessage ?? 'Failed to copy to clipboard', {
128 durationMs,
129 })
130 }
131 throw error
132 }
133}
134
135export function clearClipboardMessage() {
136 if (clearTimer) {

Callers 4

LoginModalFunction · 0.90
handleCopyFunction · 0.90
clipboard.test.tsFile · 0.90
handleSelectionFunction · 0.90

Calls 6

isRemoteSessionFunction · 0.85
tryCopyViaRendererFunction · 0.85
tryCopyViaOsc52Function · 0.85
tryCopyViaPlatformToolFunction · 0.85
getDefaultSuccessMessageFunction · 0.85
showClipboardMessageFunction · 0.85

Tested by

no test coverage detected