Support reporting XTVERSION

Fixes #5342
This commit is contained in:
Daniel Imms
2025-12-26 11:06:55 -08:00
parent 79621a4e3f
commit d8a93b757a
4 changed files with 63 additions and 2 deletions
+22
View File
@@ -1582,6 +1582,28 @@ describe('InputHandler', () => {
assert.equal(bufferService.cols, 132);
});
});
describe('XTVERSION (CSI > q, CSI > 0 q)', () => {
it('should report xterm.js version', async () => {
const stack: string[] = [];
coreService.onData(data => stack.push(data));
await inputHandler.parseP('\x1b[>q');
assert.strictEqual(stack.length, 1);
assert.ok(stack[0].match(/^\x1bP>\|xterm\.js\(\d+\.\d+\.\d+(-beta\.\d+)?\)\x1b\\/));
});
it('should report xterm.js version for CSI > 0 q', async () => {
const stack: string[] = [];
coreService.onData(data => stack.push(data));
await inputHandler.parseP('\x1b[>0q');
assert.strictEqual(stack.length, 1);
assert.ok(stack[0].match(/^\x1bP>\|xterm\.js\(\d+\.\d+\.\d+(-beta\.\d+)?\)\x1b\\/));
});
it('should not report for CSI > 1 q', async () => {
const stack: string[] = [];
coreService.onData(data => stack.push(data));
await inputHandler.parseP('\x1b[>1q');
assert.strictEqual(stack.length, 0);
});
});
describe('should correctly reset cells taken by wide chars', () => {
beforeEach(async () => {
bufferService.resize(10, 5);
+18
View File
@@ -22,6 +22,7 @@ import { DcsHandler } from 'common/parser/DcsParser';
import { IBuffer } from 'common/buffer/Types';
import { parseColor } from 'common/input/XParseColor';
import { Emitter } from 'vs/base/common/event';
import { XTERM_VERSION } from 'common/Version';
/**
* Map collect to glevel. Used in `selectCharset`.
@@ -256,6 +257,7 @@ export class InputHandler extends Disposable implements IInputHandler {
this._parser.registerCsiHandler({ final: 'n' }, params => this.deviceStatus(params));
this._parser.registerCsiHandler({ prefix: '?', final: 'n' }, params => this.deviceStatusPrivate(params));
this._parser.registerCsiHandler({ intermediates: '!', final: 'p' }, params => this.softReset(params));
this._parser.registerCsiHandler({ prefix: '>', final: 'q' }, params => this.sendXtVersion(params));
this._parser.registerCsiHandler({ intermediates: ' ', final: 'q' }, params => this.setCursorStyle(params));
this._parser.registerCsiHandler({ final: 'r' }, params => this.setScrollRegion(params));
this._parser.registerCsiHandler({ final: 's' }, params => this.saveCursor(params));
@@ -1721,6 +1723,22 @@ export class InputHandler extends Disposable implements IInputHandler {
return true;
}
/**
* CSI > Ps q
* Ps = 0 => Report xterm name and version (XTVERSION).
*
* The response is a DCS sequence identifying the version: DCS > | text ST
*
* @vt: #Y CSI XTVERSION "Report Xterm Version" "CSI > q" "Report the terminal name and version."
*/
public sendXtVersion(params: IParams): boolean {
if (params.params[0] > 0) {
return true;
}
this._coreService.triggerDataEvent(`${C0.ESC}P>|xterm.js(${XTERM_VERSION})${C0.ESC}\\`);
return true;
}
/**
* Evaluate if the current terminal is the given argument.
* @param term The terminal name to evaluate
+9
View File
@@ -0,0 +1,9 @@
/**
* Copyright (c) 2025 The xterm.js authors. All rights reserved.
* @license MIT
*/
/**
* The xterm.js version. This is updated by the publish script from package.json.
*/
export const XTERM_VERSION = '6.0.0';