Skip to content

Commit

Permalink
Support serializing tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Dec 7, 2019
1 parent 903d75e commit ca12cf5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions addons/xterm-addon-serialize/src/SerializeAddon.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,16 @@ describe('SerializeAddon', () => {
it('serialize tabs correctly', async () => {
const lines = [
'a\tb',
'foo\tbar\tbaz'
'aa\tc',
'aaa\td'
];
const expected = [
'a\x1b[7Cb',
'aa\x1b[6Cc',
'aaa\x1b[5Cd'
];
await writeSync(page, lines.join('\\r\\n'));
assert.equal(await page.evaluate(`serializeAddon.serialize();`), lines.join('\r\n'));
assert.equal(await page.evaluate(`serializeAddon.serialize();`), expected.join('\r\n'));
});
});

Expand Down
11 changes: 11 additions & 0 deletions addons/xterm-addon-serialize/src/SerializeAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
private _rowIndex: number = 0;
private _allRows: string[] = new Array<string>();
private _currentRow: string = '';
private _nullCellCount: number = 0;
private _sgrSeq: number[] = [];

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

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

protected _nextCell(cell: IBufferCell, oldCell: IBufferCell, row: number, col: number): void {
// Count number of null cells encountered after the last non-null cell and move the cursor
// if a non-null cell is found (eg. \t or cursor move)
if (cell.char === '') {
this._nullCellCount++;
} else if (this._nullCellCount > 0) {
this._currentRow += `\x1b[${this._nullCellCount}C`;
this._nullCellCount = 0;
}

const fgChanged = !cell.equalFg(oldCell);
const bgChanged = !cell.equalBg(oldCell);
const flagsChanged = !cell.equalFlags(oldCell);
Expand Down

0 comments on commit ca12cf5

Please sign in to comment.