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

Class BufferLine

src/common/buffer/BufferLine.ts:61–551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59 * memory allocs / GC pressure can be greatly reduced by reusing the CellData object.
60 */
61export class BufferLine implements IBufferLine {
62 protected _data: Uint32Array;
63 protected _combined: {[index: number]: string} = {};
64 protected _extendedAttrs: {[index: number]: IExtendedAttrs | undefined} = {};
65 public length: number;
66
67 constructor(cols: number, fillCellData?: ICellData, public isWrapped: boolean = false) {
68 this._data = new Uint32Array(cols * CELL_SIZE);
69 const cell = fillCellData || CellData.fromCharData([0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]);
70 for (let i = 0; i < cols; ++i) {
71 this.setCell(i, cell);
72 }
73 this.length = cols;
74 }
75
76 /**
77 * Get cell data CharData.
78 * @deprecated
79 */
80 public get(index: number): CharData {
81 const content = this._data[index * CELL_SIZE + Cell.CONTENT];
82 const cp = content & Content.CODEPOINT_MASK;
83 return [
84 this._data[index * CELL_SIZE + Cell.FG],
85 (content & Content.IS_COMBINED_MASK)
86 ? this._combined[index]
87 : (cp) ? stringFromCodePoint(cp) : '',
88 content >> Content.WIDTH_SHIFT,
89 (content & Content.IS_COMBINED_MASK)
90 ? this._combined[index].charCodeAt(this._combined[index].length - 1)
91 : cp
92 ];
93 }
94
95 /**
96 * Set cell data from CharData.
97 * @deprecated
98 */
99 public set(index: number, value: CharData): void {
100 this._data[index * CELL_SIZE + Cell.FG] = value[CHAR_DATA_ATTR_INDEX];
101 if (value[CHAR_DATA_CHAR_INDEX].length > 1) {
102 this._combined[index] = value[1];
103 this._data[index * CELL_SIZE + Cell.CONTENT] = index | Content.IS_COMBINED_MASK | (value[CHAR_DATA_WIDTH_INDEX] << Content.WIDTH_SHIFT);
104 } else {
105 this._data[index * CELL_SIZE + Cell.CONTENT] = value[CHAR_DATA_CHAR_INDEX].charCodeAt(0) | (value[CHAR_DATA_WIDTH_INDEX] << Content.WIDTH_SHIFT);
106 }
107 }
108
109 /**
110 * primitive getters
111 * use these when only one value is needed, otherwise use `loadCell`
112 */
113 public getWidth(index: number): number {
114 return this._data[index * CELL_SIZE + Cell.CONTENT] >> Content.WIDTH_SHIFT;
115 }
116
117 /** Test whether content has width. */
118 public hasWidth(index: number): number {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected