Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions addons/addon-search/src/DecorationManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Copyright (c) 2026 The xterm.js authors. All rights reserved.
* @license MIT
*/

import { assert } from 'chai';
import { DecorationManager } from './DecorationManager';
import { SearchEngine } from './SearchEngine';
import { SearchLineCache } from './SearchLineCache';
import { Terminal } from 'browser/public/Terminal';
import type { ISearchDecorationOptions } from '@xterm/addon-search';
import type { IDecorationOptions } from '@xterm/xterm';
import { DisposableStore } from 'common/Lifecycle';

function writeP(terminal: Terminal, data: string): Promise<void> {
return new Promise(r => terminal.write(data, r));
}

describe('DecorationManager', () => {
let store: DisposableStore;
let terminal: Terminal;
let decorationManager: DecorationManager;

beforeEach(() => {
store = new DisposableStore();
terminal = store.add(new Terminal({ cols: 10, rows: 5 }));
decorationManager = store.add(new DecorationManager(terminal));
});

it('should split highlight decorations for a wrapped match', async () => {
await writeP(terminal, '0123456789abcde');
const searchEngine = new SearchEngine(terminal, store.add(new SearchLineCache(terminal)));
const match = searchEngine.find('9abc', 0, 0);
assert.ok(match);

const decorationOptions: IDecorationOptions[] = [];
const registerDecoration = terminal.registerDecoration.bind(terminal);
terminal.registerDecoration = (options: IDecorationOptions) => {
decorationOptions.push(options);
return registerDecoration(options);
};

const options: ISearchDecorationOptions = {
matchOverviewRuler: '#ff0000',
activeMatchColorOverviewRuler: '#00ff00'
};
decorationManager.createHighlightDecorations([match], options);

assert.strictEqual(decorationOptions.length, 2);
assert.strictEqual(decorationOptions[0].x, 9);
assert.strictEqual(decorationOptions[0].width, 1);
assert.strictEqual(decorationOptions[1].x, 0);
assert.strictEqual(decorationOptions[1].width, 3);

const withOverviewRuler = decorationOptions.filter(o => o.overviewRulerOptions !== undefined);
assert.strictEqual(withOverviewRuler.length, 2);
});

it('should only add one overview ruler marker per buffer line', async () => {
await writeP(terminal, 'abcdefghij');
const decorationOptions: IDecorationOptions[] = [];
const registerDecoration = terminal.registerDecoration.bind(terminal);
terminal.registerDecoration = (options: IDecorationOptions) => {
decorationOptions.push(options);
return registerDecoration(options);
};

const options: ISearchDecorationOptions = {
matchOverviewRuler: '#ff0000',
activeMatchColorOverviewRuler: '#00ff00'
};
decorationManager.createHighlightDecorations([
{ term: 'a', col: 0, row: 0, size: 1 },
{ term: 'f', col: 5, row: 0, size: 1 }
], options);

const withOverviewRuler = decorationOptions.filter(o => o.overviewRulerOptions !== undefined);
assert.strictEqual(withOverviewRuler.length, 1);
assert.strictEqual(withOverviewRuler[0].x, 0);
});
});
41 changes: 5 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"workspaces": [
"addons/*"
],
"overrides": {
"serialize-javascript": "^7.0.3"
},
"keywords": [
"cli",
"command-line",
Expand Down
97 changes: 87 additions & 10 deletions src/common/InputHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import { MockCoreService, MockBufferService, MockOptionsService, MockLogService,
import { IBufferService, ICoreService, type IOscLinkService } from './services/Services';
import { DEFAULT_OPTIONS } from './services/OptionsService';
import { BufferService } from './services/BufferService';
import { CharsetService } from './services/CharsetService';
import { CoreService } from './services/CoreService';
import { OscLinkService } from './services/OscLinkService';
import { CHARSETS } from './data/Charsets';


function getCursor(bufferService: IBufferService): number[] {
Expand Down Expand Up @@ -639,19 +641,38 @@ describe('InputHandler', () => {
});
describe('print', () => {
it('should not cause an infinite loop (regression test)', () => {
const inputHandler = new TestInputHandler(
new MockBufferService(80, 30),
new MockCharsetService(),
new MockCoreService(),
new MockLogService(),
new MockOptionsService(),
new MockOscLinkService(),
new MockMouseStateService(),
new MockUnicodeService()
);
const container = new Uint32Array(10);
container[0] = 0x200B;
const lineCountBefore = bufferService.buffer.lines.length;
inputHandler.print(container, 0, 1);
assert.strictEqual(bufferService.buffer.y, 0);
assert.strictEqual(bufferService.buffer.lines.length, lineCountBefore);
});
it('should join combining characters in a single print', async () => {
await inputHandler.parseP('e\u0301');
assert.strictEqual(bufferService.buffer.translateBufferLineToString(0, true), 'e\u0301');
assert.strictEqual(bufferService.buffer.x, 1);
});
it('should join combining characters split across parse calls', async () => {
await inputHandler.parseP('e');
await inputHandler.parseP('\u0301');
assert.strictEqual(bufferService.buffer.translateBufferLineToString(0, true), 'e\u0301');
assert.strictEqual(bufferService.buffer.x, 1);
});
it('should repeat preceding grapheme cluster via REP', async () => {
await inputHandler.parseP('e\u0301\x1b[2b');
assert.strictEqual(bufferService.buffer.translateBufferLineToString(0, true), 'e\u0301e\u0301e\u0301');
assert.strictEqual(bufferService.buffer.x, 3);
});
it('should not repeat when REP has no preceding join state', async () => {
await inputHandler.parseP('\x1b[2b');
assert.strictEqual(bufferService.buffer.translateBufferLineToString(0, true), '');
assert.strictEqual(bufferService.buffer.x, 0);
});
it('should not repeat after an intervening escape sequence', async () => {
await inputHandler.parseP('a\x1b[0m\x1b[2b');
assert.strictEqual(bufferService.buffer.translateBufferLineToString(0, true), 'a');
assert.strictEqual(bufferService.buffer.x, 1);
});
it('should clear cells to the right on early wrap-around', async () => {
bufferService.resize(5, 5);
Expand All @@ -668,6 +689,49 @@ describe('InputHandler', () => {
});
});

describe('ISO-2022 character sets', () => {
let charsetService: CharsetService;

beforeEach(() => {
charsetService = new CharsetService();
inputHandler = new TestInputHandler(
bufferService,
charsetService,
coreService,
new MockLogService(),
optionsService,
oscLinkService,
new MockMouseStateService(),
new MockUnicodeService()
);
});

it('should map G0 line drawing via ESC ( 0', async () => {
await inputHandler.parseP('\x1b(0q\x1b(Bq');
assert.strictEqual(bufferService.buffer.translateBufferLineToString(0, true), '\u2500q');
});

it('should map G1 line drawing after ESC ) 0 and SO', async () => {
await inputHandler.parseP('\x1b)0\x0eq\x0f\x1b(Bq');
assert.strictEqual(bufferService.buffer.translateBufferLineToString(0, true), '\u2500q');
});

it('should restore charset and glevel on ESC 7 / ESC 8', async () => {
await inputHandler.parseP('\x1b)0\x0e');
assert.strictEqual(charsetService.glevel, 1);
assert.strictEqual(charsetService.charset, CHARSETS['0']);
await inputHandler.parseP('\x1b7');
await inputHandler.parseP('\x0f\x1b(B');
assert.strictEqual(charsetService.glevel, 0);
assert.ok(charsetService.charset === undefined);
await inputHandler.parseP('\x1b8');
assert.strictEqual(charsetService.glevel, 1);
assert.strictEqual(charsetService.charset, CHARSETS['0']);
await inputHandler.parseP('q');
assert.strictEqual(bufferService.buffer.translateBufferLineToString(0, true), '\u2500');
});
});

describe('alt screen', () => {
let bufferService: IBufferService;
let handler: TestInputHandler;
Expand Down Expand Up @@ -1182,6 +1246,19 @@ describe('InputHandler', () => {
await inputHandler.parseP('\x1b[100;100H');
assert.deepEqual(getCursor(bufferService), [9, 9]);
});
it('cursor position (CUP) with DECOM and scroll margins', async () => {
await inputHandler.parseP('\x1b[?6h\x1b[2;3r\x1b[1;1H');
assert.deepEqual(getCursor(bufferService), [0, 1]);
await inputHandler.parseP('X');
assert.strictEqual(getLines(bufferService, 3)[1], 'X');
await inputHandler.parseP('\x1b[2;1H');
assert.deepEqual(getCursor(bufferService), [0, 2]);
await inputHandler.parseP('\x1b[10;10H');
assert.deepEqual(getCursor(bufferService), [9, 2]);
await inputHandler.parseP('\x1b[?6l');
await inputHandler.parseP('\x1b[2;1H');
assert.deepEqual(getCursor(bufferService), [0, 1]);
});
it('horizontal position absolute (HPA)', async () => {
await inputHandler.parseP('\x1b[`');
assert.deepEqual(getCursor(bufferService), [0, 0]);
Expand Down
54 changes: 54 additions & 0 deletions src/common/WindowsMode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2026 The xterm.js authors. All rights reserved.
* @license MIT
*/

import { assert } from 'chai';
import { DEFAULT_ATTR_DATA } from './buffer/BufferLine';
import { updateWindowsModeWrappedState } from './WindowsMode';
import { BufferService } from './services/BufferService';
import { OptionsService } from './services/OptionsService';
import { MockLogService } from './TestUtils.test';

describe('WindowsMode', () => {
describe('updateWindowsModeWrappedState', () => {
it('should mark the next line wrapped when the previous line ends in a non-whitespace character', () => {
const bufferService = new BufferService(new OptionsService({ rows: 5, cols: 10 }), new MockLogService());
const buffer = bufferService.buffer;
const previousLine = buffer.lines.get(buffer.ybase)!;
for (let i = 0; i < bufferService.cols; i++) {
previousLine!.setCellFromCodepoint(i, 'a'.charCodeAt(0), 1, DEFAULT_ATTR_DATA);
}
buffer.y = 1;

updateWindowsModeWrappedState(bufferService);

assert.strictEqual(buffer.lines.get(buffer.ybase + 1)!.isWrapped, true);
});

it('should not mark the next line wrapped when the previous line ends in whitespace', () => {
const bufferService = new BufferService(new OptionsService({ rows: 5, cols: 10 }), new MockLogService());
const buffer = bufferService.buffer;
const previousLine = buffer.lines.get(buffer.ybase)!;
for (let i = 0; i < bufferService.cols - 1; i++) {
previousLine!.setCellFromCodepoint(i, 'a'.charCodeAt(0), 1, DEFAULT_ATTR_DATA);
}
previousLine!.setCellFromCodepoint(bufferService.cols - 1, ' '.charCodeAt(0), 1, DEFAULT_ATTR_DATA);
buffer.y = 1;

updateWindowsModeWrappedState(bufferService);

assert.strictEqual(buffer.lines.get(buffer.ybase + 1)!.isWrapped, false);
});

it('should not mark the next line wrapped when the previous line ends in a null cell', () => {
const bufferService = new BufferService(new OptionsService({ rows: 5, cols: 10 }), new MockLogService());
const buffer = bufferService.buffer;
buffer.y = 1;

updateWindowsModeWrappedState(bufferService);

assert.strictEqual(buffer.lines.get(buffer.ybase + 1)!.isWrapped, false);
});
});
});
Loading
Loading