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

Function buildOsc52Sequence

cli/src/utils/clipboard.ts:194–214  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

192const OSC52_MAX_PAYLOAD = 32_000
193
194function buildOsc52Sequence(text: string): string | null {
195 const env = getCliEnv()
196 if (env.TERM === 'dumb') return null
197
198 const base64 = Buffer.from(text, 'utf8').toString('base64')
199 if (base64.length > OSC52_MAX_PAYLOAD) return null
200
201 const osc = `\x1b]52;c;${base64}\x07`
202
203 // tmux: wrap in DCS passthrough with doubled ESC
204 if (env.TMUX) {
205 return `\x1bPtmux;${osc.replace(/\x1b/g, '\x1b\x1b')}\x1b\\`
206 }
207
208 // GNU screen: wrap in DCS passthrough
209 if (env.STY) {
210 return `\x1bP${osc}\x1b\\`
211 }
212
213 return osc
214}
215
216function tryCopyViaOsc52(text: string): boolean {
217 const sequence = buildOsc52Sequence(text)

Callers 1

tryCopyViaOsc52Function · 0.85

Calls 2

getCliEnvFunction · 0.90
fromMethod · 0.80

Tested by

no test coverage detected