Skip to content

Commit ca12cf5

Browse files
committed
Support serializing tabs
1 parent 903d75e commit ca12cf5

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

addons/xterm-addon-serialize/src/SerializeAddon.api.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,16 @@ describe('SerializeAddon', () => {
260260
it('serialize tabs correctly', async () => {
261261
const lines = [
262262
'a\tb',
263-
'foo\tbar\tbaz'
263+
'aa\tc',
264+
'aaa\td'
265+
];
266+
const expected = [
267+
'a\x1b[7Cb',
268+
'aa\x1b[6Cc',
269+
'aaa\x1b[5Cd'
264270
];
265271
await writeSync(page, lines.join('\\r\\n'));
266-
assert.equal(await page.evaluate(`serializeAddon.serialize();`), lines.join('\r\n'));
272+
assert.equal(await page.evaluate(`serializeAddon.serialize();`), expected.join('\r\n'));
267273
});
268274
});
269275

addons/xterm-addon-serialize/src/SerializeAddon.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
7979
private _rowIndex: number = 0;
8080
private _allRows: string[] = new Array<string>();
8181
private _currentRow: string = '';
82+
private _nullCellCount: number = 0;
8283
private _sgrSeq: number[] = [];
8384

8485
constructor(buffer: IBuffer) {
@@ -92,6 +93,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
9293
protected _lineEnd(row: number): void {
9394
this._allRows[this._rowIndex++] = this._currentRow;
9495
this._currentRow = '';
96+
this._nullCellCount = 0;
9597
}
9698

9799
protected _cellFlagsChanged(cell: IBufferCell, oldCell: IBufferCell, row: number, col: number): void {
@@ -133,6 +135,15 @@ class StringSerializeHandler extends BaseSerializeHandler {
133135
}
134136

135137
protected _nextCell(cell: IBufferCell, oldCell: IBufferCell, row: number, col: number): void {
138+
// Count number of null cells encountered after the last non-null cell and move the cursor
139+
// if a non-null cell is found (eg. \t or cursor move)
140+
if (cell.char === '') {
141+
this._nullCellCount++;
142+
} else if (this._nullCellCount > 0) {
143+
this._currentRow += `\x1b[${this._nullCellCount}C`;
144+
this._nullCellCount = 0;
145+
}
146+
136147
const fgChanged = !cell.equalFg(oldCell);
137148
const bgChanged = !cell.equalBg(oldCell);
138149
const flagsChanged = !cell.equalFlags(oldCell);

0 commit comments

Comments
 (0)