diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 194d2e84c..7d1b767d7 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1299,7 +1299,7 @@ export class InputHandler extends Disposable implements IInputHandler { } else if (collect === '?') { switch (params[0]) { case 1: - this._terminal.applicationCursor = true; + this._coreService.decPrivateModes.applicationCursorKeys = true; break; case 2: this._terminal.setgCharset(0, DEFAULT_CHARSET); @@ -1504,7 +1504,7 @@ export class InputHandler extends Disposable implements IInputHandler { } else if (collect === '?') { switch (params[0]) { case 1: - this._terminal.applicationCursor = false; + this._coreService.decPrivateModes.applicationCursorKeys = false; break; case 3: if (this._terminal.cols === 132 && this._terminal.savedCols) { @@ -1852,7 +1852,7 @@ export class InputHandler extends Disposable implements IInputHandler { if (this._terminal.viewport) { this._terminal.viewport.syncScrollArea(); } - this._terminal.applicationCursor = false; + this._coreService.decPrivateModes.applicationCursorKeys = false; this._terminal.buffer.scrollTop = 0; this._terminal.buffer.scrollBottom = this._terminal.rows - 1; this._terminal.curAttrData = DEFAULT_ATTR_DATA.clone(); diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 700238367..381ddcca0 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -665,7 +665,7 @@ export class SelectionManager implements ISelectionManager { false ); if (coordinates && coordinates[0] !== undefined && coordinates[1] !== undefined) { - const sequence = moveToCellSequence(coordinates[0] - 1, coordinates[1] - 1, this._bufferService, this._terminal.applicationCursor); + const sequence = moveToCellSequence(coordinates[0] - 1, coordinates[1] - 1, this._bufferService, this._coreService.decPrivateModes.applicationCursorKeys); this._coreService.triggerDataEvent(sequence, true); } } diff --git a/src/Terminal.ts b/src/Terminal.ts index a9f11b4b7..7f1c77532 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -118,7 +118,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp // modes public applicationKeypad: boolean; - public applicationCursor: boolean; public originMode: boolean; public insertMode: boolean; public wraparoundMode: boolean; // defaults: xterm - true, vt100 - false @@ -269,7 +268,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp // modes this.applicationKeypad = false; - this.applicationCursor = false; this.originMode = false; this.insertMode = false; this.wraparoundMode = true; // defaults: xterm - true, vt100 - false @@ -1013,7 +1011,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp } // Construct and send sequences - const sequence = C0.ESC + (this.applicationCursor ? 'O' : '[') + ( ev.deltaY < 0 ? 'A' : 'B'); + const sequence = C0.ESC + (this._coreService.decPrivateModes.applicationCursorKeys ? 'O' : '[') + ( ev.deltaY < 0 ? 'A' : 'B'); let data = ''; for (let i = 0; i < Math.abs(amount); i++) { data += sequence; @@ -1555,7 +1553,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp return false; } - const result = evaluateKeyboardEvent(event, this.applicationCursor, this.browser.isMac, this.options.macOptionIsMeta); + const result = evaluateKeyboardEvent(event, this._coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta); this.updateCursorStyle(event); @@ -1885,6 +1883,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp this._setup(); this._bufferService.reset(); + this._coreService.reset(); // reattach this._customKeyEventHandler = customKeyEventHandler; diff --git a/src/Types.d.ts b/src/Types.d.ts index 20e6c0828..cd4ad2d0a 100644 --- a/src/Types.d.ts +++ b/src/Types.d.ts @@ -33,7 +33,6 @@ export interface IInputHandlingTerminal { glevel: number; charsets: ICharset[]; applicationKeypad: boolean; - applicationCursor: boolean; originMode: boolean; insertMode: boolean; wraparoundMode: boolean; @@ -206,7 +205,6 @@ export interface ITerminal extends IPublicTerminal, IElementAccessor, IBufferAcc isFocused: boolean; viewport: IViewport; bracketedPasteMode: boolean; - applicationCursor: boolean; optionsService: IOptionsService; // TODO: We should remove options once components adopt optionsService options: ITerminalOptions; diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index 86098d33a..e3a6c9b9a 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -9,6 +9,7 @@ import { clone } from 'common/Clone'; import { DEFAULT_OPTIONS } from 'common/services/OptionsService'; import { IBufferSet, IBuffer } from 'common/buffer/Types'; import { BufferSet } from 'common/buffer/BufferSet'; +import { IDecPrivateModes } from 'common/Types'; export class MockBufferService implements IBufferService { public get buffer(): IBuffer { return this.buffers.active; } @@ -28,8 +29,10 @@ export class MockBufferService implements IBufferService { } export class MockCoreService implements ICoreService { + decPrivateModes: IDecPrivateModes = {} as any; onData: IEvent = new EventEmitter().event; onUserInput: IEvent = new EventEmitter().event; + reset(): void {} triggerDataEvent(data: string, wasUserInput?: boolean): void {} } diff --git a/src/common/Types.d.ts b/src/common/Types.d.ts index 97bd60293..320aaeb8b 100644 --- a/src/common/Types.d.ts +++ b/src/common/Types.d.ts @@ -149,3 +149,7 @@ export interface IMarker extends IDisposable { readonly isDisposed: boolean; readonly line: number; } + +export interface IDecPrivateModes { + applicationCursorKeys: boolean; +} diff --git a/src/common/services/CoreService.ts b/src/common/services/CoreService.ts index bd731e8dc..56133a1b9 100644 --- a/src/common/services/CoreService.ts +++ b/src/common/services/CoreService.ts @@ -5,8 +5,16 @@ import { ICoreService, IOptionsService, IBufferService } from 'common/services/Services'; import { EventEmitter, IEvent } from 'common/EventEmitter'; +import { IDecPrivateModes } from 'common/Types'; +import { clone } from 'common/Clone'; + +const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({ + applicationCursorKeys: false +}); export class CoreService implements ICoreService { + public decPrivateModes: IDecPrivateModes; + private _onData = new EventEmitter(); public get onData(): IEvent { return this._onData.event; } private _onUserInput = new EventEmitter(); @@ -18,6 +26,11 @@ export class CoreService implements ICoreService { private readonly _bufferService: IBufferService, private readonly _optionsService: IOptionsService ) { + this.decPrivateModes = clone(DEFAULT_DEC_PRIVATE_MODES); + } + + public reset(): void { + } public triggerDataEvent(data: string, wasUserInput: boolean = false): void { diff --git a/src/common/services/Services.d.ts b/src/common/services/Services.d.ts index d9903e70a..08263b49c 100644 --- a/src/common/services/Services.d.ts +++ b/src/common/services/Services.d.ts @@ -5,6 +5,7 @@ import { IEvent } from 'common/EventEmitter'; import { IBuffer, IBufferSet } from 'common/buffer/Types'; +import { IDecPrivateModes } from 'common/Types'; export interface IBufferService { readonly cols: number; @@ -19,9 +20,13 @@ export interface IBufferService { } export interface ICoreService { + readonly decPrivateModes: IDecPrivateModes; + readonly onData: IEvent; readonly onUserInput: IEvent; + reset(): void; + /** * Triggers the onData event in the public API. * @param data The data that is being emitted.