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