Compare commits
38
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b1dbc2a71 | ||
|
|
be4b136e01 | ||
|
|
1a67b6f4b3 | ||
|
|
afaed108e4 | ||
|
|
c27d6bb462 | ||
|
|
9c4f0f96ca | ||
|
|
18c370a154 | ||
|
|
850f4ad738 | ||
|
|
b665f6259a | ||
|
|
d195dc9a3b | ||
|
|
4e5994d8a2 | ||
|
|
4a0cb5ae6b | ||
|
|
9e72a4b6d3 | ||
|
|
f484584b70 | ||
|
|
e749cb6125 | ||
|
|
8df996f9e7 | ||
|
|
51f6186352 | ||
|
|
ae5c41c518 | ||
|
|
17e7dafa17 | ||
|
|
df9fb7e473 | ||
|
|
41d9c4080f | ||
|
|
f100e93ba5 | ||
|
|
1d3825d341 | ||
|
|
57315e6cc9 | ||
|
|
2be4fc68e5 | ||
|
|
66fabfc232 | ||
|
|
3e2a42eb29 | ||
|
|
6a47d09b4c | ||
|
|
b36001ee7b | ||
|
|
e64f25a0dd | ||
|
|
3bcb57545e | ||
|
|
dc726a2ae6 | ||
|
|
06e5ac7ab4 | ||
|
|
c6e3492a4a | ||
|
|
86291b6e96 | ||
|
|
685434ca84 | ||
|
|
ff72c00219 | ||
|
|
69ee4ad23b |
@@ -22,6 +22,9 @@ build/
|
|||||||
yarn.lock
|
yarn.lock
|
||||||
test-results/
|
test-results/
|
||||||
|
|
||||||
|
# Tracing/debug files
|
||||||
|
.cursor/nal-trace/
|
||||||
|
|
||||||
# Keep bundled code out of Git
|
# Keep bundled code out of Git
|
||||||
dist/
|
dist/
|
||||||
demo/dist/
|
demo/dist/
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ Xterm.js is used in many world-class applications to provide great terminal expe
|
|||||||
- [**SSH Connection Manager**](https://github.com/Amtrend/ssh-manager): Modern web-based SSH terminal and SFTP manager with AES-256 encryption, PWA support, and session management.
|
- [**SSH Connection Manager**](https://github.com/Amtrend/ssh-manager): Modern web-based SSH terminal and SFTP manager with AES-256 encryption, PWA support, and session management.
|
||||||
- [**WooTTY**](https://github.com/icoretech/wootty): Flawless browser terminal for real operators.
|
- [**WooTTY**](https://github.com/icoretech/wootty): Flawless browser terminal for real operators.
|
||||||
- [**Orca**](https://github.com/stablyai/orca): Agentic development environment for 100x builders.
|
- [**Orca**](https://github.com/stablyai/orca): Agentic development environment for 100x builders.
|
||||||
|
- [**4bit**](https://ciembor.github.io/4bit): Terminal Color Scheme Designer.
|
||||||
- [And much more...](https://github.com/xtermjs/xterm.js/network/dependents?package_id=UGFja2FnZS0xNjYzMjc4OQ%3D%3D)
|
- [And much more...](https://github.com/xtermjs/xterm.js/network/dependents?package_id=UGFja2FnZS0xNjYzMjc4OQ%3D%3D)
|
||||||
|
|
||||||
Do you use xterm.js in your application as well? Please [open a Pull Request](https://github.com/sourcelair/xterm.js/pulls) to include it here. We would love to have it on our list. Please add any new contributions to the end of the list.
|
Do you use xterm.js in your application as well? Please [open a Pull Request](https://github.com/sourcelair/xterm.js/pulls) to include it here. We would love to have it on our list. Please add any new contributions to the end of the list.
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export class SixelHandler implements IDcsHandler, IResetHandler {
|
|||||||
const height = this._dec.height;
|
const height = this._dec.height;
|
||||||
|
|
||||||
// partial fix for https://github.com/jerch/xterm-addon-image/issues/37
|
// partial fix for https://github.com/jerch/xterm-addon-image/issues/37
|
||||||
if (!width || ! height) {
|
if (!width || !height) {
|
||||||
if (height) {
|
if (height) {
|
||||||
this._storage.advanceCursor(height);
|
this._storage.advanceCursor(height);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -533,8 +533,8 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
|
|||||||
|
|
||||||
private _sendResponse(id: number, message: string, quiet: number, placementId?: number): void {
|
private _sendResponse(id: number, message: string, quiet: number, placementId?: number): void {
|
||||||
const isOk = message === 'OK';
|
const isOk = message === 'OK';
|
||||||
if (isOk && quiet === 1) return;
|
if (isOk && quiet >= 1) return;
|
||||||
if (!isOk && quiet === 2) return;
|
if (!isOk && quiet >= 2) return;
|
||||||
|
|
||||||
const pPart = placementId ? `,p=${placementId}` : '';
|
const pPart = placementId ? `,p=${placementId}` : '';
|
||||||
const response = `\x1b_Gi=${id}${pPart};${message}\x1b\\`;
|
const response = `\x1b_Gi=${id}${pPart};${message}\x1b\\`;
|
||||||
|
|||||||
@@ -617,6 +617,18 @@ test.describe('Kitty Graphics Protocol', () => {
|
|||||||
strictEqual(await ctx.page.evaluate('window.kittyGotResponse'), false);
|
strictEqual(await ctx.page.evaluate('window.kittyGotResponse'), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('suppresses OK response when q=2', async () => {
|
||||||
|
await ctx.page.evaluate(() => {
|
||||||
|
(window as any).kittyGotResponse = false;
|
||||||
|
(window as any).term.onData(() => { (window as any).kittyGotResponse = true; });
|
||||||
|
});
|
||||||
|
|
||||||
|
await ctx.proxy.write(`\x1b_Gi=81,a=q,q=2,f=100;${KITTY_BLACK_1X1_BASE64}\x1b\\`);
|
||||||
|
await timeout(100);
|
||||||
|
|
||||||
|
strictEqual(await ctx.page.evaluate('window.kittyGotResponse'), false);
|
||||||
|
});
|
||||||
|
|
||||||
test('suppresses error response when q=2', async () => {
|
test('suppresses error response when q=2', async () => {
|
||||||
await ctx.page.evaluate(() => {
|
await ctx.page.evaluate(() => {
|
||||||
(window as any).kittyGotResponse = false;
|
(window as any).kittyGotResponse = false;
|
||||||
@@ -797,6 +809,30 @@ test.describe('Kitty Graphics Protocol', () => {
|
|||||||
|
|
||||||
strictEqual(await ctx.page.evaluate('window.kittyGotResponse'), false);
|
strictEqual(await ctx.page.evaluate('window.kittyGotResponse'), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a=t OK suppressed by q=2', async () => {
|
||||||
|
await ctx.page.evaluate(() => {
|
||||||
|
(window as any).kittyGotResponse = false;
|
||||||
|
(window as any).term.onData(() => { (window as any).kittyGotResponse = true; });
|
||||||
|
});
|
||||||
|
|
||||||
|
await ctx.proxy.write(`\x1b_Gi=181,a=t,q=2,f=100;${KITTY_BLACK_1X1_BASE64}\x1b\\`);
|
||||||
|
await timeout(100);
|
||||||
|
|
||||||
|
strictEqual(await ctx.page.evaluate('window.kittyGotResponse'), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a=T OK suppressed by q=2', async () => {
|
||||||
|
await ctx.page.evaluate(() => {
|
||||||
|
(window as any).kittyGotResponse = false;
|
||||||
|
(window as any).term.onData(() => { (window as any).kittyGotResponse = true; });
|
||||||
|
});
|
||||||
|
|
||||||
|
await ctx.proxy.write(`\x1b_Gi=191,a=T,q=2,f=100;${KITTY_BLACK_1X1_BASE64}\x1b\\`);
|
||||||
|
await timeout(100);
|
||||||
|
|
||||||
|
strictEqual(await ctx.page.evaluate('window.kittyGotResponse'), false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test.describe('Transmission medium rejection', () => {
|
test.describe('Transmission medium rejection', () => {
|
||||||
@@ -1146,6 +1182,22 @@ test.describe('Kitty Graphics Protocol', () => {
|
|||||||
strictEqual(await getImageStorageLength(), 1);
|
strictEqual(await getImageStorageLength(), 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('OK response suppressed by q=2', async () => {
|
||||||
|
await ctx.proxy.write(`\x1b_Ga=t,f=100,i=221;${KITTY_BLACK_1X1_BASE64}\x1b\\`);
|
||||||
|
await timeout(100);
|
||||||
|
|
||||||
|
await ctx.page.evaluate(() => {
|
||||||
|
(window as any).kittyGotResponse = false;
|
||||||
|
(window as any).term.onData(() => { (window as any).kittyGotResponse = true; });
|
||||||
|
});
|
||||||
|
|
||||||
|
await ctx.proxy.write(`\x1b_Ga=p,i=221,q=2\x1b\\`);
|
||||||
|
await timeout(100);
|
||||||
|
|
||||||
|
strictEqual(await ctx.page.evaluate('window.kittyGotResponse'), false);
|
||||||
|
strictEqual(await getImageStorageLength(), 1);
|
||||||
|
});
|
||||||
|
|
||||||
test('ENOENT error suppressed by q=2', async () => {
|
test('ENOENT error suppressed by q=2', async () => {
|
||||||
await ctx.page.evaluate(() => {
|
await ctx.page.evaluate(() => {
|
||||||
(window as any).kittyGotResponse = false;
|
(window as any).kittyGotResponse = false;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
"package": "webpack",
|
"package": "webpack",
|
||||||
"pretest": "npm run build",
|
"pretest": "npm run build",
|
||||||
"test": "nyc mocha out/**/*.test.js",
|
"test": "nyc mocha out/**/*.test.js",
|
||||||
"prepublish": "npm run package"
|
"prepublishOnly": "npm run package"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"font",
|
"font",
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lru-cache": "^5.1.0",
|
"@types/lru-cache": "^5.1.0",
|
||||||
"@types/opentype.js": "^0.7.0",
|
"@types/opentype.js": "^0.7.0",
|
||||||
"axios": "^1.15.0",
|
"axios": "^1.15.2",
|
||||||
"font-finder": "^1.1.0",
|
"font-finder": "^1.1.0",
|
||||||
"mkdirp": "0.5.5",
|
"mkdirp": "0.5.5",
|
||||||
"yauzl": "^3.2.1"
|
"yauzl": "^3.2.1"
|
||||||
|
|||||||
@@ -358,7 +358,9 @@ export class GlyphRenderer extends Disposable {
|
|||||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
|
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, activeBuffer.subarray(0, bufferLength), gl.STREAM_DRAW);
|
gl.bufferData(gl.ARRAY_BUFFER, activeBuffer.subarray(0, bufferLength), gl.STREAM_DRAW);
|
||||||
|
|
||||||
// Bind the atlas page texture if they have changed
|
// Bind the atlas page texture if they have changed. AtlasPage.version is globally
|
||||||
|
// monotonic, so a page object swap at the same index (which happens after a page merge)
|
||||||
|
// is detected by the same comparison.
|
||||||
for (let i = 0; i < this._atlas.pages.length; i++) {
|
for (let i = 0; i < this._atlas.pages.length; i++) {
|
||||||
if (this._atlas.pages[i].version !== this._atlasTextures[i].version) {
|
if (this._atlas.pages[i].version !== this._atlasTextures[i].version) {
|
||||||
this._bindAtlasPageTexture(gl, this._atlas, i);
|
this._bindAtlasPageTexture(gl, this._atlas, i);
|
||||||
@@ -371,6 +373,10 @@ export class GlyphRenderer extends Disposable {
|
|||||||
|
|
||||||
public setAtlas(atlas: ITextureAtlas): void {
|
public setAtlas(atlas: ITextureAtlas): void {
|
||||||
this._atlas = atlas;
|
this._atlas = atlas;
|
||||||
|
this.invalidateAtlasTextures();
|
||||||
|
}
|
||||||
|
|
||||||
|
public invalidateAtlasTextures(): void {
|
||||||
for (const glTexture of this._atlasTextures) {
|
for (const glTexture of this._atlasTextures) {
|
||||||
glTexture.version = -1;
|
glTexture.version = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,8 +336,9 @@ export class RectangleRenderer extends Disposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vertices.attributes.length < offset + 4) {
|
if (vertices.attributes.length < offset + INDICES_PER_RECTANGLE) {
|
||||||
vertices.attributes = expandFloat32Array(vertices.attributes, this._terminal.rows * this._terminal.cols * INDICES_PER_RECTANGLE);
|
// +1 for the viewport-clear rectangle at offset 0.
|
||||||
|
vertices.attributes = expandFloat32Array(vertices.attributes, (this._terminal.rows * this._terminal.cols + 1) * INDICES_PER_RECTANGLE);
|
||||||
}
|
}
|
||||||
$x1 = startX * this._dimensions.device.cell.width;
|
$x1 = startX * this._dimensions.device.cell.width;
|
||||||
$y1 = y * this._dimensions.device.cell.height;
|
$y1 = y * this._dimensions.device.cell.height;
|
||||||
|
|||||||
@@ -133,7 +133,9 @@ export class TextureAtlas implements ITextureAtlas {
|
|||||||
|
|
||||||
private _requestClearModel = false;
|
private _requestClearModel = false;
|
||||||
public beginFrame(): boolean {
|
public beginFrame(): boolean {
|
||||||
return this._requestClearModel;
|
const result = this._requestClearModel;
|
||||||
|
this._requestClearModel = false;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public clearTexture(): void {
|
public clearTexture(): void {
|
||||||
@@ -193,7 +195,7 @@ export class TextureAtlas implements ITextureAtlas {
|
|||||||
|
|
||||||
// Merge into the new page
|
// Merge into the new page
|
||||||
const mergedPage = this._mergePages(mergingPages, mergedPageIndex);
|
const mergedPage = this._mergePages(mergingPages, mergedPageIndex);
|
||||||
mergedPage.version++;
|
mergedPage.version = ++AtlasPage.nextVersion;
|
||||||
|
|
||||||
// Delete the pages, shifting glyph texture pages as needed
|
// Delete the pages, shifting glyph texture pages as needed
|
||||||
for (let i = sortedMergingPagesIndexes.length - 1; i >= 0; i--) {
|
for (let i = sortedMergingPagesIndexes.length - 1; i >= 0; i--) {
|
||||||
@@ -251,7 +253,7 @@ export class TextureAtlas implements ITextureAtlas {
|
|||||||
for (const g of adjustingPage.glyphs) {
|
for (const g of adjustingPage.glyphs) {
|
||||||
g.texturePage--;
|
g.texturePage--;
|
||||||
}
|
}
|
||||||
adjustingPage.version++;
|
adjustingPage.version = ++AtlasPage.nextVersion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -937,7 +939,7 @@ export class TextureAtlas implements ITextureAtlas {
|
|||||||
rasterizedGlyph.size.y
|
rasterizedGlyph.size.y
|
||||||
);
|
);
|
||||||
activePage.addGlyph(rasterizedGlyph);
|
activePage.addGlyph(rasterizedGlyph);
|
||||||
activePage.version++;
|
activePage.version = ++AtlasPage.nextVersion;
|
||||||
|
|
||||||
return rasterizedGlyph;
|
return rasterizedGlyph;
|
||||||
}
|
}
|
||||||
@@ -1047,9 +1049,13 @@ class AtlasPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to check whether the canvas of the atlas page has changed.
|
* Monotonically increasing across all atlas pages globally. Used to detect when the texture
|
||||||
|
* unit at a given index needs to be re-uploaded — both for content changes within the same
|
||||||
|
* page and for a page object swap at the same index (which happens after a page merge,
|
||||||
|
* where a per-page counter could coincide with the previously-bound page's value).
|
||||||
*/
|
*/
|
||||||
public version = 0;
|
public static nextVersion: number = 0;
|
||||||
|
public version = ++AtlasPage.nextVersion;
|
||||||
|
|
||||||
// Texture atlas current positioning data. The texture packing strategy used is to fill from
|
// Texture atlas current positioning data. The texture packing strategy used is to fill from
|
||||||
// left-to-right and top-to-bottom. When the glyph being written is less than half of the current
|
// left-to-right and top-to-bottom. When the glyph being written is less than half of the current
|
||||||
@@ -1092,7 +1098,7 @@ class AtlasPage {
|
|||||||
this.currentRow.y = 0;
|
this.currentRow.y = 0;
|
||||||
this.currentRow.height = 0;
|
this.currentRow.height = 0;
|
||||||
this.fixedRows.length = 0;
|
this.fixedRows.length = 0;
|
||||||
this.version++;
|
this.version = ++AtlasPage.nextVersion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ import { addDisposableListener } from 'browser/Dom';
|
|||||||
import { combinedDisposable, Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
|
import { combinedDisposable, Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
|
||||||
import { createRenderDimensions } from 'browser/renderer/shared/RendererUtils';
|
import { createRenderDimensions } from 'browser/renderer/shared/RendererUtils';
|
||||||
|
|
||||||
|
const enum Constants {
|
||||||
|
MERGE_RETRY_LIMIT = 32
|
||||||
|
}
|
||||||
|
|
||||||
export class WebglRenderer extends Disposable implements IRenderer {
|
export class WebglRenderer extends Disposable implements IRenderer {
|
||||||
private _renderLayers: IRenderLayer[];
|
private _renderLayers: IRenderLayer[];
|
||||||
private _cursorBlinkStateManager: MutableDisposable<CursorBlinkStateManager> = this._register(new MutableDisposable());
|
private _cursorBlinkStateManager: MutableDisposable<CursorBlinkStateManager> = this._register(new MutableDisposable());
|
||||||
@@ -375,6 +379,19 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|||||||
this._updateModel(start, end);
|
this._updateModel(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A mid-update atlas page merge invalidates vertex data and may not bump the host
|
||||||
|
// page's version, so re-run the update and force a full texture rebind.
|
||||||
|
let merged = false;
|
||||||
|
let mergeRetries = 0;
|
||||||
|
while (this._charAtlas && this._glyphRenderer.value.beginFrame() && mergeRetries++ < Constants.MERGE_RETRY_LIMIT) {
|
||||||
|
merged = true;
|
||||||
|
this._clearModel(true);
|
||||||
|
this._updateModel(0, this._terminal.rows - 1);
|
||||||
|
}
|
||||||
|
if (merged) {
|
||||||
|
this._glyphRenderer.value.invalidateAtlasTextures();
|
||||||
|
}
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
this._rectangleRenderer.value.renderBackgrounds();
|
this._rectangleRenderer.value.renderBackgrounds();
|
||||||
this._glyphRenderer.value.render(this._model);
|
this._glyphRenderer.value.render(this._model);
|
||||||
|
|||||||
@@ -252,6 +252,11 @@ export class OptionsWindow extends BaseWindow implements IControlWindow {
|
|||||||
input.value = 'auto';
|
input.value = 'auto';
|
||||||
this._handlers.updateTerminalSize();
|
this._handlers.updateTerminalSize();
|
||||||
}
|
}
|
||||||
|
const screenElement = document.querySelector('.xterm-screen');
|
||||||
|
if (screenElement instanceof HTMLElement) {
|
||||||
|
screenElement.style.outline = this._autoResize ? ''
|
||||||
|
: 'solid thin red';
|
||||||
|
}
|
||||||
} else if (o === 'theme') {
|
} else if (o === 'theme') {
|
||||||
value = this._getTheme();
|
value = this._getTheme();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export default tseslint.config(
|
|||||||
singleline: { delimiter: 'comma', requireLast: false }
|
singleline: { delimiter: 'comma', requireLast: false }
|
||||||
}],
|
}],
|
||||||
'@stylistic/type-annotation-spacing': 'warn',
|
'@stylistic/type-annotation-spacing': 'warn',
|
||||||
|
'@stylistic/space-unary-ops': 'warn',
|
||||||
|
|
||||||
'@typescript-eslint/array-type': ['warn', { default: 'array', readonly: 'generic' }],
|
'@typescript-eslint/array-type': ['warn', { default: 'array', readonly: 'generic' }],
|
||||||
'@typescript-eslint/consistent-type-assertions': 'warn',
|
'@typescript-eslint/consistent-type-assertions': 'warn',
|
||||||
|
|||||||
Generated
+9
-706
File diff suppressed because it is too large
Load Diff
@@ -56,7 +56,6 @@
|
|||||||
"test-unit": "node ./bin/test_unit.js",
|
"test-unit": "node ./bin/test_unit.js",
|
||||||
"test-unit-slow-tests": "npm run test-unit | grep \"ms)\"",
|
"test-unit-slow-tests": "npm run test-unit | grep \"ms)\"",
|
||||||
"test-unit-coverage": "node ./bin/test_unit.js --coverage",
|
"test-unit-coverage": "node ./bin/test_unit.js --coverage",
|
||||||
"test-unit-dev": "cross-env NODE_PATH='./out' mocha",
|
|
||||||
"test-integration": "node ./bin/test_integration.js --workers=75%",
|
"test-integration": "node ./bin/test_integration.js --workers=75%",
|
||||||
"test-integration-chromium": "node ./bin/test_integration.js --workers=75% \"--project=Chromium\"",
|
"test-integration-chromium": "node ./bin/test_integration.js --workers=75% \"--project=Chromium\"",
|
||||||
"test-integration-firefox": "node ./bin/test_integration.js --workers=75% \"--project=FirefoxStable\"",
|
"test-integration-firefox": "node ./bin/test_integration.js --workers=75% \"--project=FirefoxStable\"",
|
||||||
@@ -80,15 +79,11 @@
|
|||||||
"@playwright/test": "^1.57.0",
|
"@playwright/test": "^1.57.0",
|
||||||
"@stylistic/eslint-plugin": "^4.4.1",
|
"@stylistic/eslint-plugin": "^4.4.1",
|
||||||
"@types/chai": "^4.2.22",
|
"@types/chai": "^4.2.22",
|
||||||
"@types/debug": "^4.1.7",
|
|
||||||
"@types/deep-equal": "^1.0.1",
|
|
||||||
"@types/express": "4",
|
"@types/express": "4",
|
||||||
"@types/express-ws": "^3.0.1",
|
"@types/express-ws": "^3.0.1",
|
||||||
"@types/jsdom": "^27.0.0",
|
"@types/jsdom": "^27.0.0",
|
||||||
"@types/mocha": "^9.0.0",
|
"@types/mocha": "^9.0.0",
|
||||||
"@types/node": "^22.19.3",
|
"@types/node": "^22.19.3",
|
||||||
"@types/trusted-types": "^1.0.6",
|
|
||||||
"@types/utf8": "^3.0.0",
|
|
||||||
"@types/webpack": "^5.28.0",
|
"@types/webpack": "^5.28.0",
|
||||||
"@types/ws": "^8.2.0",
|
"@types/ws": "^8.2.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
||||||
@@ -96,8 +91,6 @@
|
|||||||
"@typescript/native-preview": "^7.0.0-dev.20260213.1",
|
"@typescript/native-preview": "^7.0.0-dev.20260213.1",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"concurrently": "^9.1.2",
|
"concurrently": "^9.1.2",
|
||||||
"cross-env": "^7.0.3",
|
|
||||||
"deep-equal": "^2.0.5",
|
|
||||||
"esbuild": "~0.25.2",
|
"esbuild": "~0.25.2",
|
||||||
"eslint": "^9.39.2",
|
"eslint": "^9.39.2",
|
||||||
"eslint-plugin-jsdoc": "^50.8.0",
|
"eslint-plugin-jsdoc": "^50.8.0",
|
||||||
@@ -113,7 +106,6 @@
|
|||||||
"ts-loader": "^9.3.1",
|
"ts-loader": "^9.3.1",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"typescript-eslint": "^8.50.1",
|
"typescript-eslint": "^8.50.1",
|
||||||
"utf8": "^3.0.0",
|
|
||||||
"webpack": "^5.61.0",
|
"webpack": "^5.61.0",
|
||||||
"webpack-cli": "^4.9.1",
|
"webpack-cli": "^4.9.1",
|
||||||
"ws": "^8.2.3",
|
"ws": "^8.2.3",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export class MouseCoordsService implements IMouseCoordsService {
|
|||||||
|
|
||||||
public getCoords(event: {clientX: number, clientY: number}, element: HTMLElement, colCount: number, rowCount: number, isSelection?: boolean): [number, number] | undefined {
|
public getCoords(event: {clientX: number, clientY: number}, element: HTMLElement, colCount: number, rowCount: number, isSelection?: boolean): [number, number] | undefined {
|
||||||
return getCoords(
|
return getCoords(
|
||||||
window,
|
getWindow(element),
|
||||||
event,
|
event,
|
||||||
element,
|
element,
|
||||||
colCount,
|
colCount,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export class RenderService extends Disposable implements IRenderService {
|
|||||||
private _renderDebouncer: IRenderDebouncerWithCallback;
|
private _renderDebouncer: IRenderDebouncerWithCallback;
|
||||||
private _pausedResizeTask: DebouncedIdleTask;
|
private _pausedResizeTask: DebouncedIdleTask;
|
||||||
private _observerDisposable = this._register(new MutableDisposable());
|
private _observerDisposable = this._register(new MutableDisposable());
|
||||||
|
private _intersectionObserver: IntersectionObserver | undefined;
|
||||||
|
|
||||||
private _isPaused: boolean = false;
|
private _isPaused: boolean = false;
|
||||||
private _needsFullRefresh: boolean = false;
|
private _needsFullRefresh: boolean = false;
|
||||||
@@ -127,8 +128,12 @@ export class RenderService extends Disposable implements IRenderService {
|
|||||||
// and resume based on terminal visibility if so
|
// and resume based on terminal visibility if so
|
||||||
if ('IntersectionObserver' in w) {
|
if ('IntersectionObserver' in w) {
|
||||||
const observer = new w.IntersectionObserver(e => this._handleIntersectionChange(e[e.length - 1]), { threshold: 0 });
|
const observer = new w.IntersectionObserver(e => this._handleIntersectionChange(e[e.length - 1]), { threshold: 0 });
|
||||||
|
this._observerDisposable.value = toDisposable(() => {
|
||||||
|
this._intersectionObserver?.disconnect();
|
||||||
|
this._intersectionObserver = undefined;
|
||||||
|
});
|
||||||
|
this._intersectionObserver = observer;
|
||||||
observer.observe(screenElement);
|
observer.observe(screenElement);
|
||||||
this._observerDisposable.value = toDisposable(() => observer.disconnect());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,42 @@ export class TimeoutTimer implements IDisposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedules a single runner on the microtask queue. Unlike {@link TimeoutTimer}, a scheduled
|
||||||
|
* microtask cannot be unqueued; {@link cancel} prevents the runner from executing if it has not
|
||||||
|
* run yet.
|
||||||
|
*/
|
||||||
|
export class MicrotaskTimer implements IDisposable {
|
||||||
|
private _isScheduled = false;
|
||||||
|
private _isDisposed = false;
|
||||||
|
|
||||||
|
public dispose(): void {
|
||||||
|
this.cancel();
|
||||||
|
this._isDisposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public cancel(): void {
|
||||||
|
this._isScheduled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set(runner: () => void): void {
|
||||||
|
if (this._isDisposed) {
|
||||||
|
throw new Error('Calling set on a disposed MicrotaskTimer');
|
||||||
|
}
|
||||||
|
if (this._isScheduled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._isScheduled = true;
|
||||||
|
queueMicrotask(() => {
|
||||||
|
if (!this._isScheduled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._isScheduled = false;
|
||||||
|
runner();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class IntervalTimer implements IDisposable {
|
export class IntervalTimer implements IDisposable {
|
||||||
private _disposable: IDisposable | undefined;
|
private _disposable: IDisposable | undefined;
|
||||||
private _isDisposed = false;
|
private _isDisposed = false;
|
||||||
|
|||||||
+32
-25
@@ -2904,32 +2904,39 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
/**
|
/**
|
||||||
* CSI Ps ; Ps ; Ps t - Various window manipulations and reports (xterm)
|
* CSI Ps ; Ps ; Ps t - Various window manipulations and reports (xterm)
|
||||||
*
|
*
|
||||||
* Note: Only those listed below are supported. All others are left to integrators and
|
* @vt: #P[Guarded by windowOptions; disabled by default for security. See below.] CSI WINMAN "Window Manipulation" "CSI Ps ; Ps t" "Various window manipulations and reports (xterm)."
|
||||||
* need special treatment based on the embedding environment.
|
|
||||||
*
|
*
|
||||||
* Ps = 1 4 supported
|
* All `Ps` values are guarded by the corresponding `windowOptions` setting and disabled by
|
||||||
* Report xterm text area size in pixels.
|
* default for security (see `ITerminalOptions.windowOptions`). Custom `CSI t` handlers registered
|
||||||
* Result is CSI 4 ; height ; width t
|
* via `registerCsiHandler` are subject to the same guard.
|
||||||
* Ps = 14 ; 2 not implemented
|
*
|
||||||
* Ps = 16 supported
|
* | Ps | Action | windowOptions | Support |
|
||||||
* Report xterm character cell size in pixels.
|
* | --- | --- | --- | --- |
|
||||||
* Result is CSI 6 ; height ; width t
|
* | 1 | De-iconify window | restoreWin | #P[No default implementation.] |
|
||||||
* Ps = 18 supported
|
* | 2 | Iconify window | minimizeWin | #P[No default implementation.] |
|
||||||
* Report the size of the text area in characters.
|
* | 3 | Move window to [x, y] | setWinPosition | #P[No default implementation.] |
|
||||||
* Result is CSI 8 ; height ; width t
|
* | 4 | Resize window in pixels | setWinSizePixels | #P[No default implementation.] |
|
||||||
* Ps = 20 supported
|
* | 5 | Raise window | raiseWin | #P[No default implementation.] |
|
||||||
* Report xterm window's icon label.
|
* | 6 | Lower window | lowerWin | #P[No default implementation.] |
|
||||||
* Result is OSC L label ST
|
* | 7 | Refresh window | refreshWin | #P[No default implementation.] |
|
||||||
* Ps = 21 supported
|
* | 8 | Resize text area in characters | setWinSizeChars | #P[No default implementation.] |
|
||||||
* Report xterm window's title.
|
* | 9 | Maximize window | maximizeWin | #P[No default implementation.] |
|
||||||
* Result is OSC l label ST
|
* | 10 | Full-screen mode | fullscreenWin | #P[No default implementation.] |
|
||||||
* Ps = 22 ; 0 -> Save xterm icon and window title on stack. supported
|
* | 11 | Report window state | getWinState | #P[No default implementation.] |
|
||||||
* Ps = 22 ; 1 -> Save xterm icon title on stack. supported
|
* | 13 | Report window position | getWinPosition | #P[No default implementation.] |
|
||||||
* Ps = 22 ; 2 -> Save xterm window title on stack. supported
|
* | 14 | Report text area size in pixels (`CSI 4 ; height ; width t`) | getWinSizePixels | #P[Browser only; requires render service.] |
|
||||||
* Ps = 23 ; 0 -> Restore xterm icon and window title from stack. supported
|
* | 14 ; 2 | Report window size in pixels | getWinSizePixels | #N |
|
||||||
* Ps = 23 ; 1 -> Restore xterm icon title from stack. supported
|
* | 15 | Report screen size in pixels | getScreenSizePixels | #P[No default implementation.] |
|
||||||
* Ps = 23 ; 2 -> Restore xterm window title from stack. supported
|
* | 16 | Report cell size in pixels (`CSI 6 ; height ; width t`) | getCellSizePixels | #P[Browser only; requires render service.] |
|
||||||
* Ps >= 24 not implemented
|
* | 18 | Report text area size in characters (`CSI 8 ; height ; width t`) | getWinSizeChars | #Y |
|
||||||
|
* | 19 | Report screen size in characters | getScreenSizeChars | #P[No default implementation.] |
|
||||||
|
* | 20 | Report icon title (OSC) | getIconTitle | #P[No default implementation.] |
|
||||||
|
* | 21 | Report window title (OSC) | getWinTitle | #P[No default implementation.] |
|
||||||
|
* | 22 | Push title(s) on stack | pushTitle | #Y |
|
||||||
|
* | 23 | Pop title(s) from stack | popTitle | #Y |
|
||||||
|
* | >= 24 | Resize to Ps lines (DECSLPP) | setWinLines | #N |
|
||||||
|
*
|
||||||
|
* Note: `setWinLines` also gates DECCOLM (`CSI ? 3 h/l`), see DECSET mode 3.
|
||||||
*/
|
*/
|
||||||
public windowOptions(params: IParams): boolean {
|
public windowOptions(params: IParams): boolean {
|
||||||
if (!paramToWindowOption(params.params[0], this._optionsService.rawOptions.windowOptions)) {
|
if (!paramToWindowOption(params.params[0], this._optionsService.rawOptions.windowOptions)) {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { StringToUtf32, stringFromCodePoint, Utf8ToUtf32, utf32ToString } from 'common/input/TextDecoder';
|
import { StringToUtf32, stringFromCodePoint, Utf8ToUtf32, utf32ToString } from 'common/input/TextDecoder';
|
||||||
import { encode } from 'utf8';
|
|
||||||
|
|
||||||
|
|
||||||
// convert UTF32 codepoints to string
|
// convert UTF32 codepoints to string
|
||||||
@@ -29,6 +28,35 @@ function fromByteString(s: string): Uint8Array {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stringToUtf8Bytes(s: string): Uint8Array {
|
||||||
|
const bytes: number[] = [];
|
||||||
|
for (let i = 0; i < s.length; i++) {
|
||||||
|
let cp = s.charCodeAt(i);
|
||||||
|
if (cp >= 0xD800 && cp <= 0xDBFF && i + 1 < s.length) {
|
||||||
|
const next = s.charCodeAt(i + 1);
|
||||||
|
if (next >= 0xDC00 && next <= 0xDFFF) {
|
||||||
|
cp = 0x10000 + ((cp - 0xD800) << 10) + (next - 0xDC00);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cp < 0x80) {
|
||||||
|
bytes.push(cp);
|
||||||
|
} else if (cp < 0x800) {
|
||||||
|
bytes.push(0xC0 | (cp >> 6), 0x80 | (cp & 0x3F));
|
||||||
|
} else if (cp < 0x10000) {
|
||||||
|
bytes.push(0xE0 | (cp >> 12), 0x80 | ((cp >> 6) & 0x3F), 0x80 | (cp & 0x3F));
|
||||||
|
} else {
|
||||||
|
bytes.push(
|
||||||
|
0xF0 | (cp >> 18),
|
||||||
|
0x80 | ((cp >> 12) & 0x3F),
|
||||||
|
0x80 | ((cp >> 6) & 0x3F),
|
||||||
|
0x80 | (cp & 0x3F)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Uint8Array(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
function assertDecodedRange(
|
function assertDecodedRange(
|
||||||
min: number,
|
min: number,
|
||||||
max: number,
|
max: number,
|
||||||
@@ -172,7 +200,7 @@ describe('text encodings', () => {
|
|||||||
max,
|
max,
|
||||||
(i) => (i >= 0xD800 && i <= 0xDFFF) || i === 0xFEFF,
|
(i) => (i >= 0xD800 && i <= 0xDFFF) || i === 0xFEFF,
|
||||||
(i) => String.fromCharCode(i),
|
(i) => String.fromCharCode(i),
|
||||||
(input, target) => decoder.decode(fromByteString(encode(input)), target),
|
(input, target) => decoder.decode(stringToUtf8Bytes(input), target),
|
||||||
(data, length) => toString(data, length)
|
(data, length) => toString(data, length)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -187,7 +215,7 @@ describe('text encodings', () => {
|
|||||||
max,
|
max,
|
||||||
() => false,
|
() => false,
|
||||||
(i) => stringFromCodePoint(i),
|
(i) => stringFromCodePoint(i),
|
||||||
(input, target) => decoder.decode(fromByteString(encode(input)), target),
|
(input, target) => decoder.decode(stringToUtf8Bytes(input), target),
|
||||||
(data, length) => toString(data, length)
|
(data, length) => toString(data, length)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -196,7 +224,7 @@ describe('text encodings', () => {
|
|||||||
it('0xFEFF(BOM)', () => {
|
it('0xFEFF(BOM)', () => {
|
||||||
const decoder = new Utf8ToUtf32();
|
const decoder = new Utf8ToUtf32();
|
||||||
const target = new Uint32Array(5);
|
const target = new Uint32Array(5);
|
||||||
const utf8Data = fromByteString(encode(String.fromCharCode(0xFEFF)));
|
const utf8Data = stringToUtf8Bytes(String.fromCharCode(0xFEFF));
|
||||||
const length = decoder.decode(utf8Data, target);
|
const length = decoder.decode(utf8Data, target);
|
||||||
assert.equal(length, 0);
|
assert.equal(length, 0);
|
||||||
decoder.clear();
|
decoder.clear();
|
||||||
@@ -207,7 +235,7 @@ describe('text encodings', () => {
|
|||||||
const decoder = new Utf8ToUtf32();
|
const decoder = new Utf8ToUtf32();
|
||||||
const target = new Uint32Array(500);
|
const target = new Uint32Array(500);
|
||||||
for (let i = 0; i < TEST_STRINGS.length; ++i) {
|
for (let i = 0; i < TEST_STRINGS.length; ++i) {
|
||||||
const utf8Data = fromByteString(encode(TEST_STRINGS[i]));
|
const utf8Data = stringToUtf8Bytes(TEST_STRINGS[i]);
|
||||||
const length = decoder.decode(utf8Data, target);
|
const length = decoder.decode(utf8Data, target);
|
||||||
assert.equal(toString(target, length), TEST_STRINGS[i]);
|
assert.equal(toString(target, length), TEST_STRINGS[i]);
|
||||||
decoder.clear();
|
decoder.clear();
|
||||||
|
|||||||
@@ -4,11 +4,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { DecorationService } from './DecorationService';
|
import { DecorationLineCache, DecorationService } from './DecorationService';
|
||||||
import { IMarker } from 'common/Types';
|
import { IMarker } from 'common/Types';
|
||||||
import { Disposable } from 'common/Lifecycle';
|
import { Disposable } from 'common/Lifecycle';
|
||||||
import { Emitter } from 'common/Event';
|
import { Emitter } from 'common/Event';
|
||||||
import { MockLogService } from 'common/TestUtils.test';
|
import { MockLogService, MockBufferService, MockOptionsService } from 'common/TestUtils.test';
|
||||||
|
import { Buffer } from 'common/buffer/Buffer';
|
||||||
|
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
||||||
|
|
||||||
function createFakeMarker(line: number): IMarker {
|
function createFakeMarker(line: number): IMarker {
|
||||||
return Object.freeze(new class extends Disposable {
|
return Object.freeze(new class extends Disposable {
|
||||||
@@ -19,11 +21,16 @@ function createFakeMarker(line: number): IMarker {
|
|||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createDecorationService(): DecorationService {
|
||||||
|
const bufferService = new MockBufferService(80, 24, new MockOptionsService());
|
||||||
|
return new DecorationService(new MockLogService(), bufferService);
|
||||||
|
}
|
||||||
|
|
||||||
const fakeMarker: IMarker = createFakeMarker(1);
|
const fakeMarker: IMarker = createFakeMarker(1);
|
||||||
|
|
||||||
describe('DecorationService', () => {
|
describe('DecorationService', () => {
|
||||||
it('should set isDisposed to true after dispose', () => {
|
it('should set isDisposed to true after dispose', () => {
|
||||||
const service = new DecorationService(new MockLogService());
|
const service = createDecorationService();
|
||||||
const decoration = service.registerDecoration({
|
const decoration = service.registerDecoration({
|
||||||
marker: fakeMarker
|
marker: fakeMarker
|
||||||
});
|
});
|
||||||
@@ -35,7 +42,7 @@ describe('DecorationService', () => {
|
|||||||
|
|
||||||
describe('forEachDecorationAtCell', () => {
|
describe('forEachDecorationAtCell', () => {
|
||||||
it('should find decoration at its marker line', () => {
|
it('should find decoration at its marker line', () => {
|
||||||
const service = new DecorationService(new MockLogService());
|
const service = createDecorationService();
|
||||||
const decoration = service.registerDecoration({
|
const decoration = service.registerDecoration({
|
||||||
marker: createFakeMarker(5),
|
marker: createFakeMarker(5),
|
||||||
width: 10
|
width: 10
|
||||||
@@ -48,7 +55,7 @@ describe('DecorationService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should find decoration with height > 1 on subsequent lines', () => {
|
it('should find decoration with height > 1 on subsequent lines', () => {
|
||||||
const service = new DecorationService(new MockLogService());
|
const service = createDecorationService();
|
||||||
const decoration = service.registerDecoration({
|
const decoration = service.registerDecoration({
|
||||||
marker: createFakeMarker(5),
|
marker: createFakeMarker(5),
|
||||||
width: 10,
|
width: 10,
|
||||||
@@ -74,7 +81,7 @@ describe('DecorationService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not find decoration outside its x range', () => {
|
it('should not find decoration outside its x range', () => {
|
||||||
const service = new DecorationService(new MockLogService());
|
const service = createDecorationService();
|
||||||
const decoration = service.registerDecoration({
|
const decoration = service.registerDecoration({
|
||||||
marker: createFakeMarker(5),
|
marker: createFakeMarker(5),
|
||||||
x: 5,
|
x: 5,
|
||||||
@@ -99,11 +106,35 @@ describe('DecorationService', () => {
|
|||||||
service.forEachDecorationAtCell(8, 5, undefined, d => foundAtX8.push(d));
|
service.forEachDecorationAtCell(8, 5, undefined, d => foundAtX8.push(d));
|
||||||
assert.strictEqual(foundAtX8.length, 0);
|
assert.strictEqual(foundAtX8.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should find multi-line decoration when single-line decorations exist on other lines', () => {
|
||||||
|
const bufferService = new MockBufferService(80, 24, new MockOptionsService());
|
||||||
|
const serviceWithBuffer = new DecorationService(new MockLogService(), bufferService);
|
||||||
|
const buffer = bufferService.buffer;
|
||||||
|
(buffer as Buffer).fillViewportRows();
|
||||||
|
|
||||||
|
for (let i = 0; i < 100; i++) {
|
||||||
|
serviceWithBuffer.registerDecoration({
|
||||||
|
marker: buffer.addMarker(i),
|
||||||
|
width: 5
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const multiLine = serviceWithBuffer.registerDecoration({
|
||||||
|
marker: buffer.addMarker(10),
|
||||||
|
width: 10,
|
||||||
|
height: 3
|
||||||
|
});
|
||||||
|
assert.ok(multiLine);
|
||||||
|
|
||||||
|
const found: typeof multiLine[] = [];
|
||||||
|
serviceWithBuffer.forEachDecorationAtCell(0, 11, undefined, d => found.push(d));
|
||||||
|
assert.include(found, multiLine);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getDecorationsAtCell', () => {
|
describe('getDecorationsAtCell', () => {
|
||||||
it('should find decoration with height > 1 on subsequent lines', () => {
|
it('should find decoration with height > 1 on subsequent lines', () => {
|
||||||
const service = new DecorationService(new MockLogService());
|
const service = createDecorationService();
|
||||||
const decoration = service.registerDecoration({
|
const decoration = service.registerDecoration({
|
||||||
marker: createFakeMarker(5),
|
marker: createFakeMarker(5),
|
||||||
width: 10,
|
width: 10,
|
||||||
@@ -117,4 +148,73 @@ describe('DecorationService', () => {
|
|||||||
assert.strictEqual([...service.getDecorationsAtCell(0, 8)].length, 0);
|
assert.strictEqual([...service.getDecorationsAtCell(0, 8)].length, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('DecorationLineCache', () => {
|
||||||
|
it('should return undefined for lines with no indexed decorations', () => {
|
||||||
|
const cache = new DecorationLineCache();
|
||||||
|
assert.isUndefined(cache.getDecorationsOnLine(0));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('line index maintenance', () => {
|
||||||
|
it('should keep lookups correct after buffer trim', () => {
|
||||||
|
const bufferService = new MockBufferService(80, 5, new MockOptionsService({ scrollback: 0 }));
|
||||||
|
const service = new DecorationService(new MockLogService(), bufferService);
|
||||||
|
const buffer = bufferService.buffer;
|
||||||
|
(buffer as Buffer).fillViewportRows();
|
||||||
|
|
||||||
|
const marker = buffer.addMarker(buffer.lines.length - 1);
|
||||||
|
const decoration = service.registerDecoration({ marker, width: 10 });
|
||||||
|
assert.ok(decoration);
|
||||||
|
|
||||||
|
buffer.lines.onTrimEmitter.fire(1);
|
||||||
|
|
||||||
|
const found: typeof decoration[] = [];
|
||||||
|
service.forEachDecorationAtCell(0, marker.line, undefined, d => found.push(d));
|
||||||
|
assert.strictEqual(found.length, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove decoration from line index when marker is trimmed off buffer', () => {
|
||||||
|
const bufferService = new MockBufferService(80, 5, new MockOptionsService({ scrollback: 0 }));
|
||||||
|
const service = new DecorationService(new MockLogService(), bufferService);
|
||||||
|
const buffer = bufferService.buffer;
|
||||||
|
(buffer as Buffer).fillViewportRows();
|
||||||
|
|
||||||
|
const marker = buffer.addMarker(0);
|
||||||
|
const decoration = service.registerDecoration({ marker, width: 10 });
|
||||||
|
assert.ok(decoration);
|
||||||
|
|
||||||
|
buffer.lines.onTrimEmitter.fire(1);
|
||||||
|
assert.isTrue(marker.isDisposed);
|
||||||
|
assert.isTrue(decoration!.isDisposed);
|
||||||
|
|
||||||
|
const found: typeof decoration[] = [];
|
||||||
|
service.forEachDecorationAtCell(0, 0, undefined, d => found.push(d));
|
||||||
|
assert.strictEqual(found.length, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should keep multi-line decoration indexed after line insert', async () => {
|
||||||
|
const bufferService = new MockBufferService(80, 10, new MockOptionsService({ scrollback: 100 }));
|
||||||
|
const service = new DecorationService(new MockLogService(), bufferService);
|
||||||
|
const buffer = bufferService.buffer;
|
||||||
|
(buffer as Buffer).fillViewportRows();
|
||||||
|
|
||||||
|
const marker = buffer.addMarker(3);
|
||||||
|
const decoration = service.registerDecoration({ marker, width: 10, height: 3 });
|
||||||
|
assert.ok(decoration);
|
||||||
|
|
||||||
|
buffer.lines.splice(5, 0, buffer.getBlankLine(DEFAULT_ATTR_DATA));
|
||||||
|
await new Promise<void>(resolve => queueMicrotask(resolve));
|
||||||
|
|
||||||
|
const foundOnSpan: typeof decoration[] = [];
|
||||||
|
for (let line = marker.line; line < marker.line + 3; line++) {
|
||||||
|
service.forEachDecorationAtCell(0, line, undefined, d => foundOnSpan.push(d));
|
||||||
|
}
|
||||||
|
assert.include(foundOnSpan, decoration);
|
||||||
|
|
||||||
|
const foundOutsideSpan: typeof decoration[] = [];
|
||||||
|
service.forEachDecorationAtCell(0, marker.line + 3, undefined, d => foundOutsideSpan.push(d));
|
||||||
|
assert.strictEqual(foundOutsideSpan.length, 0);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,19 +3,19 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import type { IDeleteEvent, IInsertEvent } from 'common/CircularList';
|
||||||
|
import { MicrotaskTimer } from 'common/Async';
|
||||||
import { css } from 'common/Color';
|
import { css } from 'common/Color';
|
||||||
import { Disposable, DisposableStore, toDisposable } from 'common/Lifecycle';
|
import { Disposable, DisposableStore, MutableDisposable, toDisposable } from 'common/Lifecycle';
|
||||||
import { IDecorationService, IInternalDecoration, ILogService } from 'common/services/Services';
|
import { IBufferService, IDecorationService, IInternalDecoration, ILogService } from 'common/services/Services';
|
||||||
import { SortedList } from 'common/SortedList';
|
import { SortedList } from 'common/SortedList';
|
||||||
import { IColor } from 'common/Types';
|
import { IColor, ICircularList } from 'common/Types';
|
||||||
import { IDecoration, IDecorationOptions, IMarker } from '@xterm/xterm';
|
import { IDecoration, IDecorationOptions, IMarker } from '@xterm/xterm';
|
||||||
import { Emitter } from 'common/Event';
|
import { Emitter } from 'common/Event';
|
||||||
|
|
||||||
// Work variables to avoid garbage collection
|
// Work variables to avoid garbage collection
|
||||||
let $xmin = 0;
|
let $xmin = 0;
|
||||||
let $xmax = 0;
|
let $xmax = 0;
|
||||||
let $ymin = 0;
|
|
||||||
let $ymax = 0;
|
|
||||||
|
|
||||||
export class DecorationService extends Disposable implements IDecorationService {
|
export class DecorationService extends Disposable implements IDecorationService {
|
||||||
public serviceBrand: any;
|
public serviceBrand: any;
|
||||||
@@ -27,6 +27,8 @@ export class DecorationService extends Disposable implements IDecorationService
|
|||||||
*/
|
*/
|
||||||
private readonly _decorations: SortedList<IInternalDecoration>;
|
private readonly _decorations: SortedList<IInternalDecoration>;
|
||||||
|
|
||||||
|
private readonly _lineCache = this._register(new DecorationLineCache());
|
||||||
|
|
||||||
private readonly _onDecorationRegistered = this._register(new Emitter<IInternalDecoration>());
|
private readonly _onDecorationRegistered = this._register(new Emitter<IInternalDecoration>());
|
||||||
public readonly onDecorationRegistered = this._onDecorationRegistered.event;
|
public readonly onDecorationRegistered = this._onDecorationRegistered.event;
|
||||||
private readonly _onDecorationRemoved = this._register(new Emitter<IInternalDecoration>());
|
private readonly _onDecorationRemoved = this._register(new Emitter<IInternalDecoration>());
|
||||||
@@ -34,12 +36,19 @@ export class DecorationService extends Disposable implements IDecorationService
|
|||||||
|
|
||||||
public get decorations(): IterableIterator<IInternalDecoration> { return this._decorations.values(); }
|
public get decorations(): IterableIterator<IInternalDecoration> { return this._decorations.values(); }
|
||||||
|
|
||||||
constructor(@ILogService private readonly _logService: ILogService) {
|
constructor(
|
||||||
|
@ILogService private readonly _logService: ILogService,
|
||||||
|
@IBufferService private readonly _bufferService: IBufferService
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this._decorations = new SortedList(e => e?.marker.line, this._logService);
|
this._decorations = new SortedList(e => e?.marker.line, this._logService);
|
||||||
|
|
||||||
this._register(toDisposable(() => this.reset()));
|
this._register(toDisposable(() => this.reset()));
|
||||||
|
this._register(this._bufferService.buffers.onBufferActivate(() => {
|
||||||
|
this._lineCache.attachToBufferLines(this._bufferService.buffer.lines);
|
||||||
|
}));
|
||||||
|
this._lineCache.attachToBufferLines(this._bufferService.buffer.lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerDecoration(options: IDecorationOptions): IDecoration | undefined {
|
public registerDecoration(options: IDecorationOptions): IDecoration | undefined {
|
||||||
@@ -53,12 +62,14 @@ export class DecorationService extends Disposable implements IDecorationService
|
|||||||
listener.dispose();
|
listener.dispose();
|
||||||
if (decoration) {
|
if (decoration) {
|
||||||
if (this._decorations.delete(decoration)) {
|
if (this._decorations.delete(decoration)) {
|
||||||
|
this._lineCache.remove(decoration);
|
||||||
this._onDecorationRemoved.fire(decoration);
|
this._onDecorationRemoved.fire(decoration);
|
||||||
}
|
}
|
||||||
markerDispose.dispose();
|
markerDispose.dispose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this._decorations.insert(decoration);
|
this._decorations.insert(decoration);
|
||||||
|
this._lineCache.add(decoration);
|
||||||
this._onDecorationRegistered.fire(decoration);
|
this._onDecorationRegistered.fire(decoration);
|
||||||
}
|
}
|
||||||
return decoration;
|
return decoration;
|
||||||
@@ -69,19 +80,17 @@ export class DecorationService extends Disposable implements IDecorationService
|
|||||||
d.dispose();
|
d.dispose();
|
||||||
}
|
}
|
||||||
this._decorations.clear();
|
this._decorations.clear();
|
||||||
|
this._lineCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public *getDecorationsAtCell(x: number, line: number, layer?: 'bottom' | 'top'): IterableIterator<IInternalDecoration> {
|
public *getDecorationsAtCell(x: number, line: number, layer?: 'bottom' | 'top'): IterableIterator<IInternalDecoration> {
|
||||||
|
const bucket = this._lineCache.getDecorationsOnLine(line);
|
||||||
|
if (!bucket) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let xmin = 0;
|
let xmin = 0;
|
||||||
let xmax = 0;
|
let xmax = 0;
|
||||||
let ymin = 0;
|
for (const d of bucket) {
|
||||||
let ymax = 0;
|
|
||||||
for (const d of this._decorations.values()) {
|
|
||||||
ymin = d.marker.line;
|
|
||||||
ymax = ymin + (d.options.height ?? 1);
|
|
||||||
if (line < ymin || line >= ymax) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
xmin = d.options.x ?? 0;
|
xmin = d.options.x ?? 0;
|
||||||
xmax = xmin + (d.options.width ?? 1);
|
xmax = xmin + (d.options.width ?? 1);
|
||||||
if (x >= xmin && x < xmax && (!layer || (d.options.layer ?? 'bottom') === layer)) {
|
if (x >= xmin && x < xmax && (!layer || (d.options.layer ?? 'bottom') === layer)) {
|
||||||
@@ -91,12 +100,11 @@ export class DecorationService extends Disposable implements IDecorationService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public forEachDecorationAtCell(x: number, line: number, layer: 'bottom' | 'top' | undefined, callback: (decoration: IInternalDecoration) => void): void {
|
public forEachDecorationAtCell(x: number, line: number, layer: 'bottom' | 'top' | undefined, callback: (decoration: IInternalDecoration) => void): void {
|
||||||
for (const d of this._decorations.values()) {
|
const bucket = this._lineCache.getDecorationsOnLine(line);
|
||||||
$ymin = d.marker.line;
|
if (!bucket) {
|
||||||
$ymax = $ymin + (d.options.height ?? 1);
|
return;
|
||||||
if (line < $ymin || line >= $ymax) {
|
}
|
||||||
continue;
|
for (const d of bucket) {
|
||||||
}
|
|
||||||
$xmin = d.options.x ?? 0;
|
$xmin = d.options.x ?? 0;
|
||||||
$xmax = $xmin + (d.options.width ?? 1);
|
$xmax = $xmin + (d.options.width ?? 1);
|
||||||
if (x >= $xmin && x < $xmax && (!layer || (d.options.layer ?? 'bottom') === layer)) {
|
if (x >= $xmin && x < $xmax && (!layer || (d.options.layer ?? 'bottom') === layer)) {
|
||||||
@@ -106,10 +114,235 @@ export class DecorationService extends Disposable implements IDecorationService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per-logical-line index of decorations for fast cell lookup.
|
||||||
|
*
|
||||||
|
* Keys are marker.line coordinates (logical buffer lines), not CircularList ring slots.
|
||||||
|
* Multi-line decorations appear in every line bucket they span. The index is kept aligned
|
||||||
|
* with marker.line updates via buffer line trim/insert/delete events.
|
||||||
|
*/
|
||||||
|
export class DecorationLineCache extends Disposable {
|
||||||
|
private readonly _decorationsByLine: Map<number, IInternalDecoration[]> = new Map();
|
||||||
|
private readonly _decorations = new Set<IInternalDecoration>();
|
||||||
|
private readonly _bufferLineListeners = this._register(new MutableDisposable<DisposableStore>());
|
||||||
|
private readonly _lineIndexSyncTimer = this._register(new MicrotaskTimer());
|
||||||
|
private _lineIndexSyncCallbacks: (() => void)[] = [];
|
||||||
|
|
||||||
|
public clear(): void {
|
||||||
|
this._lineIndexSyncCallbacks.length = 0;
|
||||||
|
this._lineIndexSyncTimer.cancel();
|
||||||
|
this._decorationsByLine.clear();
|
||||||
|
this._decorations.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public add(decoration: IInternalDecoration): void {
|
||||||
|
this._decorations.add(decoration);
|
||||||
|
this._addToLineBuckets(decoration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public remove(decoration: IInternalDecoration): void {
|
||||||
|
this._decorations.delete(decoration);
|
||||||
|
this._removeFromLineBuckets(decoration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getDecorationsOnLine(line: number): ReadonlyArray<IInternalDecoration> | undefined {
|
||||||
|
return this._decorationsByLine.get(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
public attachToBufferLines(lines: ICircularList<unknown>): void {
|
||||||
|
const store = new DisposableStore();
|
||||||
|
this._bufferLineListeners.value = store;
|
||||||
|
store.add(lines.onTrim(amount => this._handleBufferLinesTrim(amount)));
|
||||||
|
store.add(lines.onInsert(event => this._handleBufferLinesInsert(event)));
|
||||||
|
store.add(lines.onDelete(event => this._handleBufferLinesDelete(event)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getDecorationHeight(decoration: IInternalDecoration): number {
|
||||||
|
return decoration.options.height ?? 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _addToLineBuckets(decoration: IInternalDecoration): void {
|
||||||
|
const start = decoration.marker.line;
|
||||||
|
if (start < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
decoration._indexedStartLine = start;
|
||||||
|
const height = this._getDecorationHeight(decoration);
|
||||||
|
for (let line = start; line < start + height; line++) {
|
||||||
|
let bucket = this._decorationsByLine.get(line);
|
||||||
|
if (!bucket) {
|
||||||
|
bucket = [];
|
||||||
|
this._decorationsByLine.set(line, bucket);
|
||||||
|
}
|
||||||
|
bucket.push(decoration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _removeFromLineBuckets(decoration: IInternalDecoration): void {
|
||||||
|
const start = decoration._indexedStartLine;
|
||||||
|
const height = this._getDecorationHeight(decoration);
|
||||||
|
for (let line = start; line < start + height; line++) {
|
||||||
|
const bucket = this._decorationsByLine.get(line);
|
||||||
|
if (!bucket) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const index = bucket.indexOf(decoration);
|
||||||
|
if (index !== -1) {
|
||||||
|
bucket.splice(index, 1);
|
||||||
|
}
|
||||||
|
if (bucket.length === 0) {
|
||||||
|
this._decorationsByLine.delete(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _reindexDecoration(decoration: IInternalDecoration): void {
|
||||||
|
this._removeFromLineBuckets(decoration);
|
||||||
|
if (!decoration.marker.isDisposed && decoration.marker.line >= 0) {
|
||||||
|
this._addToLineBuckets(decoration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Re-index after marker line updates (buffer listeners may run before markers). */
|
||||||
|
private _scheduleLineIndexSync(callback: () => void): void {
|
||||||
|
this._lineIndexSyncCallbacks.push(callback);
|
||||||
|
this._lineIndexSyncTimer.set(() => {
|
||||||
|
const callbacks = this._lineIndexSyncCallbacks;
|
||||||
|
this._lineIndexSyncCallbacks = [];
|
||||||
|
for (const cb of callbacks) {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleBufferLinesTrim(amount: number): void {
|
||||||
|
if (amount <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const newMap = new Map<number, IInternalDecoration[]>();
|
||||||
|
for (const [line, bucket] of this._decorationsByLine) {
|
||||||
|
const newLine = line - amount;
|
||||||
|
if (newLine < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const existing = newMap.get(newLine);
|
||||||
|
if (existing) {
|
||||||
|
existing.push(...bucket);
|
||||||
|
} else {
|
||||||
|
newMap.set(newLine, bucket.slice());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._decorationsByLine.clear();
|
||||||
|
for (const [line, bucket] of newMap) {
|
||||||
|
this._decorationsByLine.set(line, bucket);
|
||||||
|
}
|
||||||
|
for (const d of this._decorations) {
|
||||||
|
if (!d.marker.isDisposed) {
|
||||||
|
d._indexedStartLine -= amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleBufferLinesInsert(event: IInsertEvent): void {
|
||||||
|
this._scheduleLineIndexSync(() => this._applyBufferLinesInsert(event));
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleBufferLinesDelete(event: IDeleteEvent): void {
|
||||||
|
this._scheduleLineIndexSync(() => this._applyBufferLinesDelete(event));
|
||||||
|
}
|
||||||
|
|
||||||
|
private _mergeLineBucket(newMap: Map<number, IInternalDecoration[]>, line: number, bucket: IInternalDecoration[]): void {
|
||||||
|
const existing = newMap.get(line);
|
||||||
|
if (existing) {
|
||||||
|
existing.push(...bucket);
|
||||||
|
} else {
|
||||||
|
newMap.set(line, bucket.slice());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift indexed line keys and sync start lines. O(unique indexed lines), not O(decoration count).
|
||||||
|
* Decorations that span the insert point are re-indexed individually (rare vs single-line hits).
|
||||||
|
*/
|
||||||
|
private _applyBufferLinesInsert(event: IInsertEvent): void {
|
||||||
|
const { index, amount } = event;
|
||||||
|
const spanCrossers: IInternalDecoration[] = [];
|
||||||
|
for (const d of this._decorations) {
|
||||||
|
if (d.marker.isDisposed) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const start = d._indexedStartLine;
|
||||||
|
if (start < index && start + this._getDecorationHeight(d) > index) {
|
||||||
|
spanCrossers.push(d);
|
||||||
|
this._removeFromLineBuckets(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const newMap = new Map<number, IInternalDecoration[]>();
|
||||||
|
for (const [line, bucket] of this._decorationsByLine) {
|
||||||
|
const newLine = line >= index ? line + amount : line;
|
||||||
|
this._mergeLineBucket(newMap, newLine, bucket);
|
||||||
|
}
|
||||||
|
this._decorationsByLine.clear();
|
||||||
|
for (const [line, bucket] of newMap) {
|
||||||
|
this._decorationsByLine.set(line, bucket);
|
||||||
|
}
|
||||||
|
for (const d of this._decorations) {
|
||||||
|
if (d.marker.isDisposed) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (d._indexedStartLine >= index) {
|
||||||
|
d._indexedStartLine = d.marker.line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const d of spanCrossers) {
|
||||||
|
this._addToLineBuckets(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop deleted line keys, shift keys below, sync start lines. Full re-index only when a
|
||||||
|
* multi-line decoration spans across the deleted range but survives.
|
||||||
|
*/
|
||||||
|
private _applyBufferLinesDelete(event: IDeleteEvent): void {
|
||||||
|
const deleteEnd = event.index + event.amount;
|
||||||
|
const newMap = new Map<number, IInternalDecoration[]>();
|
||||||
|
for (const [line, bucket] of this._decorationsByLine) {
|
||||||
|
if (line >= event.index && line < deleteEnd) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const newLine = line >= deleteEnd ? line - event.amount : line;
|
||||||
|
this._mergeLineBucket(newMap, newLine, bucket);
|
||||||
|
}
|
||||||
|
this._decorationsByLine.clear();
|
||||||
|
for (const [line, bucket] of newMap) {
|
||||||
|
this._decorationsByLine.set(line, bucket);
|
||||||
|
}
|
||||||
|
const toReindex: IInternalDecoration[] = [];
|
||||||
|
for (const d of this._decorations) {
|
||||||
|
if (d.marker.isDisposed) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const start = d._indexedStartLine;
|
||||||
|
const height = this._getDecorationHeight(d);
|
||||||
|
if (start >= deleteEnd) {
|
||||||
|
d._indexedStartLine = d.marker.line;
|
||||||
|
} else if (start < event.index && start + height > deleteEnd) {
|
||||||
|
toReindex.push(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const d of toReindex) {
|
||||||
|
this._reindexDecoration(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Decoration extends DisposableStore implements IInternalDecoration {
|
class Decoration extends DisposableStore implements IInternalDecoration {
|
||||||
public readonly marker: IMarker;
|
public readonly marker: IMarker;
|
||||||
public element: HTMLElement | undefined;
|
public element: HTMLElement | undefined;
|
||||||
|
|
||||||
|
/** Start line used for line-index removal when marker.line is cleared on dispose. */
|
||||||
|
public _indexedStartLine: number;
|
||||||
|
|
||||||
public readonly onRenderEmitter = this.add(new Emitter<HTMLElement>());
|
public readonly onRenderEmitter = this.add(new Emitter<HTMLElement>());
|
||||||
public readonly onRender = this.onRenderEmitter.event;
|
public readonly onRender = this.onRenderEmitter.event;
|
||||||
private readonly _onDispose = this.add(new Emitter<void>());
|
private readonly _onDispose = this.add(new Emitter<void>());
|
||||||
@@ -144,6 +377,7 @@ class Decoration extends DisposableStore implements IInternalDecoration {
|
|||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.marker = options.marker;
|
this.marker = options.marker;
|
||||||
|
this._indexedStartLine = options.marker.line;
|
||||||
if (this.options.overviewRulerOptions && !this.options.overviewRulerOptions.position) {
|
if (this.options.overviewRulerOptions && !this.options.overviewRulerOptions.position) {
|
||||||
this.options.overviewRulerOptions.position = 'full';
|
this.options.overviewRulerOptions.position = 'full';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -396,4 +396,6 @@ export interface IInternalDecoration extends IDecoration {
|
|||||||
readonly backgroundColorRGB: IColor | undefined;
|
readonly backgroundColorRGB: IColor | undefined;
|
||||||
readonly foregroundColorRGB: IColor | undefined;
|
readonly foregroundColorRGB: IColor | undefined;
|
||||||
readonly onRenderEmitter: Emitter<HTMLElement>;
|
readonly onRenderEmitter: Emitter<HTMLElement>;
|
||||||
|
/** @internal Start line for line-index removal; kept in sync on buffer line shifts. */
|
||||||
|
_indexedStartLine: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 The xterm.js authors. All rights reserved.
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { perfContext, before, RuntimeCase } from 'xterm-benchmark';
|
||||||
|
import { DecorationService } from 'common/services/DecorationService';
|
||||||
|
import { MockLogService, MockBufferService, MockOptionsService } from 'common/TestUtils.test';
|
||||||
|
const enum Constants {
|
||||||
|
COLS = 80,
|
||||||
|
ROWS = 30,
|
||||||
|
SINGLE_LINE_DECORATION_COUNT = 20_000,
|
||||||
|
MULTI_LINE_DECORATION_COUNT = 19_999,
|
||||||
|
MULTI_LINE_HEIGHT = 2,
|
||||||
|
VIEWPORT_SCAN_ITERATIONS = 20
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerSingleLineDecorations(service: DecorationService, bufferService: MockBufferService, count: number): void {
|
||||||
|
const buffer = bufferService.buffer;
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const line = i % 5000;
|
||||||
|
const marker = buffer.addMarker(line);
|
||||||
|
service.registerDecoration({ marker, width: Constants.COLS });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerMixedDecorations(service: DecorationService, bufferService: MockBufferService): void {
|
||||||
|
const buffer = bufferService.buffer;
|
||||||
|
for (let i = 0; i < Constants.MULTI_LINE_DECORATION_COUNT; i++) {
|
||||||
|
const line = i % 5000;
|
||||||
|
const marker = buffer.addMarker(line);
|
||||||
|
service.registerDecoration({ marker, width: Constants.COLS });
|
||||||
|
}
|
||||||
|
const multiLineMarker = buffer.addMarker(10);
|
||||||
|
service.registerDecoration({
|
||||||
|
marker: multiLineMarker,
|
||||||
|
width: Constants.COLS,
|
||||||
|
height: Constants.MULTI_LINE_HEIGHT
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function scanVisibleGrid(service: DecorationService, rows: number, cols: number): number {
|
||||||
|
let hitCount = 0;
|
||||||
|
for (let row = 0; row < rows; row++) {
|
||||||
|
for (let col = 0; col < cols; col++) {
|
||||||
|
service.forEachDecorationAtCell(col, row, undefined, () => {
|
||||||
|
hitCount++;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hitCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
perfContext('DecorationService.forEachDecorationAtCell', () => {
|
||||||
|
perfContext('single-line dense / sparse line hit', () => {
|
||||||
|
let service: DecorationService;
|
||||||
|
let bufferService: MockBufferService;
|
||||||
|
before(() => {
|
||||||
|
bufferService = new MockBufferService(Constants.COLS, Constants.ROWS, new MockOptionsService());
|
||||||
|
service = new DecorationService(new MockLogService(), bufferService);
|
||||||
|
registerSingleLineDecorations(service, bufferService, Constants.SINGLE_LINE_DECORATION_COUNT);
|
||||||
|
});
|
||||||
|
new RuntimeCase('', () => {
|
||||||
|
let hitCount = 0;
|
||||||
|
for (let i = 0; i < Constants.VIEWPORT_SCAN_ITERATIONS; i++) {
|
||||||
|
service.forEachDecorationAtCell(0, 0, undefined, () => {
|
||||||
|
hitCount++;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return { payloadSize: Constants.VIEWPORT_SCAN_ITERATIONS, hitCount };
|
||||||
|
}, { fork: false }).showAverageRuntime();
|
||||||
|
});
|
||||||
|
|
||||||
|
perfContext('mixed single-line + multi-line / sparse line hit', () => {
|
||||||
|
let service: DecorationService;
|
||||||
|
let bufferService: MockBufferService;
|
||||||
|
before(() => {
|
||||||
|
bufferService = new MockBufferService(Constants.COLS, Constants.ROWS, new MockOptionsService());
|
||||||
|
service = new DecorationService(new MockLogService(), bufferService);
|
||||||
|
registerMixedDecorations(service, bufferService);
|
||||||
|
});
|
||||||
|
new RuntimeCase('', () => {
|
||||||
|
let hitCount = 0;
|
||||||
|
for (let i = 0; i < Constants.VIEWPORT_SCAN_ITERATIONS; i++) {
|
||||||
|
service.forEachDecorationAtCell(0, 10, undefined, () => {
|
||||||
|
hitCount++;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return { payloadSize: Constants.VIEWPORT_SCAN_ITERATIONS, hitCount };
|
||||||
|
}, { fork: false }).showAverageRuntime();
|
||||||
|
});
|
||||||
|
|
||||||
|
perfContext('viewport grid scan', () => {
|
||||||
|
let service: DecorationService;
|
||||||
|
let bufferService: MockBufferService;
|
||||||
|
before(() => {
|
||||||
|
bufferService = new MockBufferService(Constants.COLS, Constants.ROWS, new MockOptionsService());
|
||||||
|
service = new DecorationService(new MockLogService(), bufferService);
|
||||||
|
registerSingleLineDecorations(service, bufferService, Constants.SINGLE_LINE_DECORATION_COUNT);
|
||||||
|
});
|
||||||
|
new RuntimeCase('', () => {
|
||||||
|
let totalHits = 0;
|
||||||
|
for (let i = 0; i < Constants.VIEWPORT_SCAN_ITERATIONS; i++) {
|
||||||
|
totalHits += scanVisibleGrid(service, Constants.ROWS, Constants.COLS);
|
||||||
|
}
|
||||||
|
return { payloadSize: Constants.VIEWPORT_SCAN_ITERATIONS * Constants.ROWS * Constants.COLS, totalHits };
|
||||||
|
}, { fork: false }).showAverageRuntime();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user