MCPcopy Create free account
hub / github.com/Noumena-Network/code / parseOSC

Function parseOSC

src/ink/termio/osc.ts:257–311  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

255 * @param content - The sequence content (without ESC ] and terminator)
256 */
257export function parseOSC(content: string): Action | null {
258 const semicolonIdx = content.indexOf(';')
259 const command = semicolonIdx >= 0 ? content.slice(0, semicolonIdx) : content
260 const data = semicolonIdx >= 0 ? content.slice(semicolonIdx + 1) : ''
261
262 const commandNum = parseInt(command, 10)
263
264 // Window/icon title
265 if (commandNum === OSC.SET_TITLE_AND_ICON) {
266 return { type: 'title', action: { type: 'both', title: data } }
267 }
268 if (commandNum === OSC.SET_ICON) {
269 return { type: 'title', action: { type: 'iconName', name: data } }
270 }
271 if (commandNum === OSC.SET_TITLE) {
272 return { type: 'title', action: { type: 'windowTitle', title: data } }
273 }
274
275 // Hyperlinks (OSC 8)
276 if (commandNum === OSC.HYPERLINK) {
277 const parts = data.split(';')
278 const paramsStr = parts[0] ?? ''
279 const url = parts.slice(1).join(';')
280
281 if (url === '') {
282 return { type: 'link', action: { type: 'end' } }
283 }
284
285 const params: Record<string, string> = {}
286 if (paramsStr) {
287 for (const pair of paramsStr.split(':')) {
288 const eqIdx = pair.indexOf('=')
289 if (eqIdx >= 0) {
290 params[pair.slice(0, eqIdx)] = pair.slice(eqIdx + 1)
291 }
292 }
293 }
294
295 return {
296 type: 'link',
297 action: {
298 type: 'start',
299 url,
300 params: Object.keys(params).length > 0 ? params : undefined,
301 },
302 }
303 }
304
305 // Tab status (OSC 21337)
306 if (commandNum === OSC.TAB_STATUS) {
307 return { type: 'tabStatus', action: parseTabStatus(data) }
308 }
309
310 return { type: 'unknown', sequence: `\x1b]${content}` }
311}
312
313/**
314 * Parse an XParseColor-style color spec into an RGB Color.

Callers 1

processSequenceMethod · 0.85

Calls 2

parseTabStatusFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected