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

Method _xtermGraphicsAttributes

addons/addon-image/src/ImageAddon.ts:249–316  ·  view source on GitHub ↗

* Implementation of xterm's graphics attribute sequence. * * Supported features: * - read/change palette limits (max 4096 by sixel lib) * - read SIXEL canvas geometry (reports current window canvas or * squared pixelLimit if canvas > pixel limit) * * Everything else is deactiv

(params: (number | number[])[])

Source from the content-addressed store, hash-verified

247 * Everything else is deactivated.
248 */
249 private _xtermGraphicsAttributes(params: (number | number[])[]): boolean {
250 if (params.length < 2) {
251 return true;
252 }
253 if (params[0] === GaItem.COLORS) {
254 switch (params[1]) {
255 case GaAction.READ:
256 this._report(`\x1b[?${params[0]};${GaStatus.SUCCESS};${this._opts.sixelPaletteLimit}S`);
257 return true;
258 case GaAction.SET_DEFAULT:
259 this._opts.sixelPaletteLimit = this._defaultOpts.sixelPaletteLimit;
260 this._report(`\x1b[?${params[0]};${GaStatus.SUCCESS};${this._opts.sixelPaletteLimit}S`);
261 // also reset protocol handlers for now
262 for (const handler of this._handlers.values()) {
263 handler.reset();
264 }
265 return true;
266 case GaAction.SET:
267 if (params.length > 2 && !(params[2] instanceof Array) && params[2] <= MAX_SIXEL_PALETTE_SIZE) {
268 this._opts.sixelPaletteLimit = params[2];
269 this._report(`\x1b[?${params[0]};${GaStatus.SUCCESS};${this._opts.sixelPaletteLimit}S`);
270 } else {
271 this._report(`\x1b[?${params[0]};${GaStatus.ACTION_ERROR}S`);
272 }
273 return true;
274 case GaAction.READ_MAX:
275 this._report(`\x1b[?${params[0]};${GaStatus.SUCCESS};${MAX_SIXEL_PALETTE_SIZE}S`);
276 return true;
277 default:
278 this._report(`\x1b[?${params[0]};${GaStatus.ACTION_ERROR}S`);
279 return true;
280 }
281 }
282 if (params[0] === GaItem.SIXEL_GEO) {
283 switch (params[1]) {
284 // we only implement read and read_max here
285 case GaAction.READ:
286 let width = this._renderer?.dimensions?.css.canvas.width;
287 let height = this._renderer?.dimensions?.css.canvas.height;
288 if (!width || !height) {
289 // for some reason we have no working image renderer
290 // --> fallback to default cell size
291 const cellSize = CELL_SIZE_DEFAULT;
292 width = (this._terminal?.cols || 80) * cellSize.width;
293 height = (this._terminal?.rows || 24) * cellSize.height;
294 }
295 if (width * height < this._opts.pixelLimit) {
296 this._report(`\x1b[?${params[0]};${GaStatus.SUCCESS};${width.toFixed(0)};${height.toFixed(0)}S`);
297 } else {
298 // if we overflow pixelLimit report that squared instead
299 const x = Math.floor(Math.sqrt(this._opts.pixelLimit));
300 this._report(`\x1b[?${params[0]};${GaStatus.SUCCESS};${x};${x}S`);
301 }
302 return true;
303 case GaAction.READ_MAX:
304 // read_max returns pixelLimit as square area
305 const x = Math.floor(Math.sqrt(this._opts.pixelLimit));
306 this._report(`\x1b[?${params[0]};${GaStatus.SUCCESS};${x};${x}S`);

Callers 1

activateMethod · 0.95

Calls 3

_reportMethod · 0.95
resetMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected