From b5fdd3b8d85c287624c7d569f9a11d2115ec3cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Sat, 7 Dec 2019 13:23:00 +0100 Subject: [PATCH] several fixes --- src/InputHandler.test.ts | 22 --------- src/InputHandler.ts | 14 ++---- src/Terminal.ts | 11 +---- src/common/Types.d.ts | 2 +- test/api/InputHandler.api.ts | 6 +-- typings/xterm.d.ts | 95 +++++++++++++++++++++++------------- 6 files changed, 69 insertions(+), 81 deletions(-) diff --git a/src/InputHandler.test.ts b/src/InputHandler.test.ts index 873998a6..f3238d02 100644 --- a/src/InputHandler.test.ts +++ b/src/InputHandler.test.ts @@ -1304,28 +1304,6 @@ describe('InputHandler', () => { term.writeSync('\x1b[18t'); assert.deepEqual(stack, ['\x1b[8;10;10t', '\x1b[8;20;50t']); }); - it('20 - GetIconTitle', () => { - const term = new TestTerminal({cols: 10, rows: 10, windowOptions: {getIconTitle: true}}); - const stack: string[] = []; - term.onData(data => stack.push(data)); - term.writeSync('\x1b]1;hello world!\x07'); - term.writeSync('\x1b[20t'); - assert.deepEqual(stack, ['\x1b]Lhello world!\x1b\\']); - term.writeSync('\x1b]1;some other\x07'); - term.writeSync('\x1b[20t'); - assert.deepEqual(stack, ['\x1b]Lhello world!\x1b\\', '\x1b]Lsome other\x1b\\']); - }); - it('21 - GetWinTitle', () => { - const term = new TestTerminal({cols: 10, rows: 10, windowOptions: {getWinTitle: true}}); - const stack: string[] = []; - term.onData(data => stack.push(data)); - term.writeSync('\x1b]2;hello world!\x07'); - term.writeSync('\x1b[21t'); - assert.deepEqual(stack, ['\x1b]lhello world!\x1b\\']); - term.writeSync('\x1b]2;some other\x07'); - term.writeSync('\x1b[21t'); - assert.deepEqual(stack, ['\x1b]lhello world!\x1b\\', '\x1b]lsome other\x1b\\']); - }); it('22/23 - PushTitle/PopTitle', () => { const term = new TestTerminal({cols: 10, rows: 10, windowOptions: {pushTitle: true, popTitle: true}}); const stack: string[] = []; diff --git a/src/InputHandler.ts b/src/InputHandler.ts index be66f95d..b98a6240 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -2146,20 +2146,14 @@ export class InputHandler extends Disposable implements IInputHandler { this._coreService.triggerDataEvent(`${C0.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`); } break; - case 20: // GetIconTitle, returns OSC L label ST - this._coreService.triggerDataEvent(`${C0.ESC}]L${this._iconName}${C0.ESC}\\`); - break; - case 21: // GetWinTitle, returns OSC l label ST - this._coreService.triggerDataEvent(`${C0.ESC}]l${this._windowTitle}${C0.ESC}\\`); - break; case 22: // PushTitle - if (!second || second === 2) { + if (second === 0 || second === 2) { this._windowTitleStack.push(this._windowTitle); if (this._windowTitleStack.length > STACK_LIMIT) { this._windowTitleStack.shift(); } } - if (!second || second === 1) { + if (second === 0 || second === 1) { this._iconNameStack.push(this._iconName); if (this._iconNameStack.length > STACK_LIMIT) { this._iconNameStack.shift(); @@ -2167,12 +2161,12 @@ export class InputHandler extends Disposable implements IInputHandler { } break; case 23: // PopTitle - if (!second || second === 2) { + if (second === 0 || second === 2) { if (this._windowTitleStack.length) { this.setTitle(this._windowTitleStack.pop()); } } - if (!second || second === 1) { + if (second === 0 || second === 1) { if (this._iconNameStack.length) { this.setIconName(this._iconNameStack.pop()); } diff --git a/src/Terminal.ts b/src/Terminal.ts index d402eab6..255a8101 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -127,13 +127,9 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp public mouseEvents: CoreMouseEventType = CoreMouseEventType.NONE; public sendFocus: boolean; - // misc public curAttrData: IAttributeData; private _eraseAttrData: IAttributeData; - public params: (string | number)[]; - public currentParam: string | number; - // write buffer private _writeBuffer: WriteBuffer; @@ -268,9 +264,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp this.curAttrData = DEFAULT_ATTR_DATA.clone(); this._eraseAttrData = DEFAULT_ATTR_DATA.clone(); - this.params = []; - this.currentParam = 0; - this._userScrolling = false; // Register input handler and refire/handle events @@ -1430,9 +1423,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp // Sync the scroll area to make sure scroll events don't fire and scroll the viewport to an // invalid location - if (this.viewport) { - this.viewport.syncScrollArea(true); - } + this.viewport?.syncScrollArea(true); this.refresh(0, this.rows - 1); this._onResize.fire({ cols: x, rows: y }); diff --git a/src/common/Types.d.ts b/src/common/Types.d.ts index 851a8ce8..a06a33cf 100644 --- a/src/common/Types.d.ts +++ b/src/common/Types.d.ts @@ -256,7 +256,7 @@ export interface ICoreMouseProtocol { export type CoreMouseEncoding = (event: ICoreMouseEvent) => string; /** - * WindowOption settings. + * windowOptions */ export interface IWindowOptions { restoreWin?: boolean; diff --git a/test/api/InputHandler.api.ts b/test/api/InputHandler.api.ts index eb928b67..ad30a51c 100644 --- a/test/api/InputHandler.api.ts +++ b/test/api/InputHandler.api.ts @@ -443,11 +443,7 @@ async function getCursor(): Promise<{col: number, row: number}> { } async function getDimensions(): Promise { - const dim = await page.evaluate(` - (function() { - return term._core._renderService.dimensions; - })(); - `); + const dim = await page.evaluate(`term._core._renderService.dimensions`); return { cellWidth: dim.actualCellWidth.toFixed(0), cellHeight: dim.actualCellHeight.toFixed(0), diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 05cff40c..21f41276 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -383,45 +383,63 @@ declare module 'xterm' { /** * Enable various window manipulation and report features (CSI Ps ; Ps ; Ps t). * - * Note that most settings have no default implementation, as they heavily - * rely on the embedding environment. + * Most settings have no default implementation, as they heavily rely on + * the embedding environment. * - * To implement a features, create a custom CSI hook like this: - * ```Typescript + * To implement a feature, create a custom CSI hook like this: + * ```ts * term.parser.addCsiHandler({final: 't'}, params => { * const ps = params[0]; * switch (ps) { * case XY: - * ... // your implementation + * ... // your implementation for option XY * return true; // signal Ps=XY was handled * } * return false; // any Ps that was not handled * }); * ``` * - * All features are disabled by default for security reasons. - * All custom implementations are guarded by the boolean values automatically. + * Note on security: + * Most features are meant to deal with some information of the host machine + * where the terminal runs on. This is seen as a security risk possibly leaking + * sensitive data of the host to the program in the terminal. Therefore all options + * (even those without a default implementation) are guarded by the boolean flag + * and disabled by default. */ export interface IWindowOptions { - /** Ps=1 De-iconify window. */ + /** + * Ps=1 De-iconify window. + * No default implementation. + */ restoreWin?: boolean; - /** Ps=2 Iconify window. */ + /** + * Ps=2 Iconify window. + * No default implementation. + */ minimizeWin?: boolean; /** * Ps=3 ; x ; y - * Move window to [x, y]. + * Move window to [x, y]. + * No default implementation. */ setWinPosition?: boolean; /** * Ps = 4 ; height ; width * Resize the window to given `height` and `width` in pixels. * Omitted parameters should reuse the current height or width. - * Zero parameters should use the display's height or width. + * Zero parameters should use the display's height or width. + * No default implementation. */ setWinSizePixels?: boolean; - /** Ps=5 Raise the window to the front of the stacking order. */ + /** + * Ps=5 Raise the window to the front of the stacking order. + * No default implementation. + */ raiseWin?: boolean; - /** Ps=6 Lower the xterm window to the bottom of the stacking order. */ + /** + * Ps=6 Lower the xterm window to the bottom of the stacking order. + * No default implementation. + */ lowerWin?: boolean; /** Ps=7 Refresh the window. */ refreshWin?: boolean; @@ -429,78 +447,89 @@ declare module 'xterm' { * Ps = 8 ; height ; width * Resize the text area to given height and width in characters. * Omitted parameters should reuse the current height or width. - * Zero parameters use the display's height or width. + * Zero parameters use the display's height or width. + * No default implementation. */ setWinSizeChars?: boolean; /** * Ps=9 ; 0 Restore maximized window. * Ps=9 ; 1 Maximize window (i.e., resize to screen size). * Ps=9 ; 2 Maximize window vertically. - * Ps=9 ; 3 Maximize window horizontally. + * Ps=9 ; 3 Maximize window horizontally. + * No default implementation. */ maximizeWin?: boolean; /** * Ps=10 ; 0 Undo full-screen mode. * Ps=10 ; 1 Change to full-screen. - * Ps=10 ; 2 Toggle full-screen. + * Ps=10 ; 2 Toggle full-screen. + * No default implementation. */ fullscreenWin?: boolean; /** Ps=11 Report xterm window state. * If the xterm window is non-iconified, it returns "CSI 1 t". - * If the xterm window is iconified, it returns "CSI 2 t". + * If the xterm window is iconified, it returns "CSI 2 t". + * No default implementation. */ getWinState?: boolean; /** * Ps=13 Report xterm window position. Result is "CSI 3 ; x ; y t". - * Ps=13 ; 2 Report xterm text-area position. Result is "CSI 3 ; x ; y t". + * Ps=13 ; 2 Report xterm text-area position. Result is "CSI 3 ; x ; y t". + * No default implementation. */ getWinPosition?: boolean; /** * Ps=14 Report xterm text area size in pixels. Result is "CSI 4 ; height ; width t". - * Ps=14 ; 2 Report xterm window size in pixels. Result is "CSI 4 ; height ; width t". - * Ps=14 has a default implementation (also handles Ps=14 ; 2 if not overwritten by custom implementation). + * Ps=14 ; 2 Report xterm window size in pixels. Result is "CSI 4 ; height ; width t". + * Has a default implementation. */ getWinSizePixels?: boolean; - /** Ps=15 Report size of the screen in pixels. Result is "CSI 5 ; height ; width t". */ + /** + * Ps=15 Report size of the screen in pixels. Result is "CSI 5 ; height ; width t". + * No default implementation. + */ getScreenSizePixels?: boolean; /** - * Ps=16 Report xterm character cell size in pixels. Result is "CSI 6 ; height ; width t". - * Implemented by default. + * Ps=16 Report xterm character cell size in pixels. Result is "CSI 6 ; height ; width t". + * Has a default implementation. */ getCellSizePixels?: boolean; /** - * Ps=18 Report the size of the text area in characters. Result is "CSI 8 ; height ; width t". - * Implemented by default. + * Ps=18 Report the size of the text area in characters. Result is "CSI 8 ; height ; width t". + * Has a default implementation. */ getWinSizeChars?: boolean; - /** Ps=19 Report the size of the screen in characters. Result is "CSI 9 ; height ; width t". */ + /** + * Ps=19 Report the size of the screen in characters. Result is "CSI 9 ; height ; width t". + * No default implementation. + */ getScreenSizeChars?: boolean; /** - * Ps=20 Report xterm window's icon label. Result is "OSC L label ST". - * Implemented by default. + * Ps=20 Report xterm window's icon label. Result is "OSC L label ST". + * No default implementation. */ getIconTitle?: boolean; /** - * Ps=21 Report xterm window's title. Result is "OSC l label ST". - * Implemented by default. + * Ps=21 Report xterm window's title. Result is "OSC l label ST". + * No default implementation. */ getWinTitle?: boolean; /** * Ps=22 ; 0 Save xterm icon and window title on stack. * Ps=22 ; 1 Save xterm icon title on stack. - * Ps=22 ; 2 Save xterm window title on stack. + * Ps=22 ; 2 Save xterm window title on stack. * All variants have a default implementation. */ pushTitle?: boolean; /** * Ps=23 ; 0 Restore xterm icon and window title from stack. * Ps=23 ; 1 Restore xterm icon title from stack. - * Ps=23 ; 2 Restore xterm window title from stack. + * Ps=23 ; 2 Restore xterm window title from stack. * All variants have a default implementation. */ popTitle?: boolean; /** - * Ps>=24 Resize to Ps lines (DECSLPP). + * Ps>=24 Resize to Ps lines (DECSLPP). * DECSLPP is not implemented. This settings is also used to * enable / disable DECCOLM (earlier variant of DECSLPP). */