MCPcopy
hub / github.com/xtermjs/xterm.js / _extractColor

Method _extractColor

src/common/InputHandler.ts:2324–2382  ·  view source on GitHub ↗

* Helper to extract and apply color params/subparams. * Returns advance for params index.

(params: IParams, pos: number, attr: IAttributeData)

Source from the content-addressed store, hash-verified

2322 * Returns advance for params index.
2323 */
2324 private _extractColor(params: IParams, pos: number, attr: IAttributeData): number {
2325 // normalize params
2326 // meaning: [target, CM, ign, val, val, val]
2327 // RGB : [ 38/48, 2, ign, r, g, b]
2328 // P256 : [ 38/48, 5, ign, v, ign, ign]
2329 const accu = [0, 0, -1, 0, 0, 0];
2330
2331 // alignment placeholder for non color space sequences
2332 let cSpace = 0;
2333
2334 // return advance we took in params
2335 let advance = 0;
2336
2337 do {
2338 accu[advance + cSpace] = params.params[pos + advance];
2339 if (params.hasSubParams(pos + advance)) {
2340 const subparams = params.getSubParams(pos + advance)!;
2341 let i = 0;
2342 do {
2343 if (accu[1] === 5) {
2344 cSpace = 1;
2345 }
2346 accu[advance + i + 1 + cSpace] = subparams[i];
2347 } while (++i < subparams.length && i + advance + 1 + cSpace < accu.length);
2348 break;
2349 }
2350 // exit early if can decide color mode with semicolons
2351 if ((accu[1] === 5 && advance + cSpace >= 2)
2352 || (accu[1] === 2 && advance + cSpace >= 5)) {
2353 break;
2354 }
2355 // offset colorSpace slot for semicolon mode
2356 if (accu[1]) {
2357 cSpace = 1;
2358 }
2359 } while (++advance + pos < params.length && advance + cSpace < accu.length);
2360
2361 // set default values to 0
2362 for (let i = 2; i < accu.length; ++i) {
2363 if (accu[i] === -1) {
2364 accu[i] = 0;
2365 }
2366 }
2367
2368 // apply colors
2369 switch (accu[0]) {
2370 case 38:
2371 attr.fg = this._updateAttrColor(attr.fg, accu[1], accu[3], accu[4], accu[5]);
2372 break;
2373 case 48:
2374 attr.bg = this._updateAttrColor(attr.bg, accu[1], accu[3], accu[4], accu[5]);
2375 break;
2376 case 58:
2377 attr.extended = attr.extended.clone();
2378 attr.extended.underlineColor = this._updateAttrColor(attr.extended.underlineColor, accu[1], accu[3], accu[4], accu[5]);
2379 }
2380
2381 return advance;

Callers 1

charAttributesMethod · 0.95

Calls 4

_updateAttrColorMethod · 0.95
hasSubParamsMethod · 0.65
getSubParamsMethod · 0.65
cloneMethod · 0.65

Tested by

no test coverage detected