From b75ae0f7b13c28e8fa001cd403f2cb3ad6adc95c Mon Sep 17 00:00:00 2001 From: kumaran-14 Date: Fri, 14 Feb 2020 20:00:03 +0530 Subject: [PATCH 1/5] Support alt+Enter key signal by default --- src/InputHandler.ts | 6 ++++++ src/Terminal.ts | 2 +- src/common/TestUtils.test.ts | 1 + src/common/Types.d.ts | 1 + src/common/input/Keyboard.test.ts | 7 ++++++- src/common/input/Keyboard.ts | 8 +++++++- src/common/services/CoreService.ts | 1 + 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/InputHandler.ts b/src/InputHandler.ts index fb37f4ab1f..356f3b3da7 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1788,6 +1788,9 @@ export class InputHandler extends Disposable implements IInputHandler { case 25: // show cursor this._coreService.isCursorHidden = false; break; + case 1039: + this._coreService.decPrivateModes.altEnterMode = true; + break; case 1048: // alt screen cursor this.saveCursor(); break; @@ -2003,6 +2006,9 @@ export class InputHandler extends Disposable implements IInputHandler { case 25: // hide cursor this._coreService.isCursorHidden = true; break; + case 1039: + this._coreService.decPrivateModes.altEnterMode = false; + break; case 1048: // alt screen cursor this.restoreCursor(); break; diff --git a/src/Terminal.ts b/src/Terminal.ts index 1bcac1f056..0ca1b186d7 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -1222,7 +1222,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp return false; } - const result = evaluateKeyboardEvent(event, this._coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta); + const result = evaluateKeyboardEvent(event, this._coreService.decPrivateModes.altEnterMode, this._coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta); this.updateCursorStyle(event); diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index 4d9070cd8e..b4636ebf2b 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -59,6 +59,7 @@ export class MockCoreService implements ICoreService { isCursorHidden: boolean = false; isFocused: boolean = false; decPrivateModes: IDecPrivateModes = { + altEnterMode: true, applicationCursorKeys: false, applicationKeypad: false, origin: false, diff --git a/src/common/Types.d.ts b/src/common/Types.d.ts index b250b45eac..4df53bd42a 100644 --- a/src/common/Types.d.ts +++ b/src/common/Types.d.ts @@ -152,6 +152,7 @@ export interface IMarker extends IDisposable { } export interface IDecPrivateModes { + altEnterMode: boolean; applicationCursorKeys: boolean; applicationKeypad: boolean; origin: boolean; diff --git a/src/common/input/Keyboard.test.ts b/src/common/input/Keyboard.test.ts index a304923e8f..ce492f0c15 100644 --- a/src/common/input/Keyboard.test.ts +++ b/src/common/input/Keyboard.test.ts @@ -16,6 +16,7 @@ function testEvaluateKeyboardEvent(partialEvent: { key?: string; type?: string; }, partialOptions: { + altEnterMode?: boolean; applicationCursorMode?: boolean; isMac?: boolean; macOptionIsMeta?: boolean; @@ -30,11 +31,12 @@ function testEvaluateKeyboardEvent(partialEvent: { type: partialEvent.type || '' }; const options = { + altEnterMode: partialOptions.altEnterMode || true, applicationCursorMode: partialOptions.applicationCursorMode || false, isMac: partialOptions.isMac || false, macOptionIsMeta: partialOptions.macOptionIsMeta || false }; - return evaluateKeyboardEvent(event, options.applicationCursorMode, options.isMac, options.macOptionIsMeta); + return evaluateKeyboardEvent(event, options.altEnterMode, options.applicationCursorMode, options.isMac, options.macOptionIsMeta); } describe('Keyboard', () => { @@ -86,6 +88,9 @@ describe('Keyboard', () => { it('should return \\x1b[3;3~ for alt+delete', () => { assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 46 }).key, '\x1b[3;3~'); }); + it('should return \\x1b\\r for alt+enter', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 13 }).key, '\x1b\r'); + }); it('should return \\x1b[5D for ctrl+left', () => { assert.equal(testEvaluateKeyboardEvent({ ctrlKey: true, keyCode: 37 }).key, '\x1b[1;5D'); // CSI 5 D }); diff --git a/src/common/input/Keyboard.ts b/src/common/input/Keyboard.ts index 1bf378c171..34433deabe 100644 --- a/src/common/input/Keyboard.ts +++ b/src/common/input/Keyboard.ts @@ -37,6 +37,7 @@ const KEYCODE_KEY_MAPPINGS: { [key: number]: [string, string]} = { export function evaluateKeyboardEvent( ev: IKeyboardEvent, + altEnterMode: boolean, applicationCursorMode: boolean, isMac: boolean, macOptionIsMeta: boolean @@ -103,7 +104,12 @@ export function evaluateKeyboardEvent( break; case 13: // return/enter - result.key = C0.CR; + if (altEnterMode && modifiers === 2) { + result.key = C0.ESC + C0.CR; + } + else { + result.key = C0.CR; + } result.cancel = true; break; case 27: diff --git a/src/common/services/CoreService.ts b/src/common/services/CoreService.ts index df9161e9c7..1ae906cc30 100644 --- a/src/common/services/CoreService.ts +++ b/src/common/services/CoreService.ts @@ -9,6 +9,7 @@ import { IDecPrivateModes, ICharset } from 'common/Types'; import { clone } from 'common/Clone'; const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({ + altEnterMode: true, applicationCursorKeys: false, applicationKeypad: false, origin: false, From 5896a05ca664adacd5c391c72c64c8ce4cdd33f2 Mon Sep 17 00:00:00 2001 From: kumaran-14 Date: Thu, 20 Feb 2020 00:21:33 +0530 Subject: [PATCH 2/5] Change decset flag to altEscMode --- src/InputHandler.ts | 4 ++-- src/Terminal.ts | 2 +- src/common/TestUtils.test.ts | 2 +- src/common/Types.d.ts | 2 +- src/common/input/Keyboard.ts | 4 ++-- src/common/services/CoreService.ts | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 356f3b3da7..a651440a0e 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1789,7 +1789,7 @@ export class InputHandler extends Disposable implements IInputHandler { this._coreService.isCursorHidden = false; break; case 1039: - this._coreService.decPrivateModes.altEnterMode = true; + this._coreService.decPrivateModes.altEscMode = true; break; case 1048: // alt screen cursor this.saveCursor(); @@ -2007,7 +2007,7 @@ export class InputHandler extends Disposable implements IInputHandler { this._coreService.isCursorHidden = true; break; case 1039: - this._coreService.decPrivateModes.altEnterMode = false; + this._coreService.decPrivateModes.altEscMode = false; break; case 1048: // alt screen cursor this.restoreCursor(); diff --git a/src/Terminal.ts b/src/Terminal.ts index 0ca1b186d7..606466178f 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -1222,7 +1222,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp return false; } - const result = evaluateKeyboardEvent(event, this._coreService.decPrivateModes.altEnterMode, this._coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta); + const result = evaluateKeyboardEvent(event, this._coreService.decPrivateModes.altEscMode, this._coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta); this.updateCursorStyle(event); diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index b4636ebf2b..2257530c17 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -59,7 +59,7 @@ export class MockCoreService implements ICoreService { isCursorHidden: boolean = false; isFocused: boolean = false; decPrivateModes: IDecPrivateModes = { - altEnterMode: true, + altEscMode: true, applicationCursorKeys: false, applicationKeypad: false, origin: false, diff --git a/src/common/Types.d.ts b/src/common/Types.d.ts index 4df53bd42a..0a2d4252a5 100644 --- a/src/common/Types.d.ts +++ b/src/common/Types.d.ts @@ -152,7 +152,7 @@ export interface IMarker extends IDisposable { } export interface IDecPrivateModes { - altEnterMode: boolean; + altEscMode: boolean; applicationCursorKeys: boolean; applicationKeypad: boolean; origin: boolean; diff --git a/src/common/input/Keyboard.ts b/src/common/input/Keyboard.ts index 34433deabe..67b5ee44d6 100644 --- a/src/common/input/Keyboard.ts +++ b/src/common/input/Keyboard.ts @@ -37,7 +37,7 @@ const KEYCODE_KEY_MAPPINGS: { [key: number]: [string, string]} = { export function evaluateKeyboardEvent( ev: IKeyboardEvent, - altEnterMode: boolean, + altEscMode: boolean, applicationCursorMode: boolean, isMac: boolean, macOptionIsMeta: boolean @@ -104,7 +104,7 @@ export function evaluateKeyboardEvent( break; case 13: // return/enter - if (altEnterMode && modifiers === 2) { + if (altEscMode && modifiers === 2) { result.key = C0.ESC + C0.CR; } else { diff --git a/src/common/services/CoreService.ts b/src/common/services/CoreService.ts index 1ae906cc30..c8c77c7d1c 100644 --- a/src/common/services/CoreService.ts +++ b/src/common/services/CoreService.ts @@ -9,7 +9,7 @@ import { IDecPrivateModes, ICharset } from 'common/Types'; import { clone } from 'common/Clone'; const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({ - altEnterMode: true, + altEscMode: true, applicationCursorKeys: false, applicationKeypad: false, origin: false, From c9277c3c721d600aa5cfef72e4af9c6e37addc22 Mon Sep 17 00:00:00 2001 From: kumaran-14 Date: Fri, 21 Feb 2020 13:13:46 +0530 Subject: [PATCH 3/5] Remove altEscape DECSET mode and add support for alt+esc key --- src/InputHandler.ts | 6 ------ src/Terminal.ts | 2 +- src/common/TestUtils.test.ts | 1 - src/common/Types.d.ts | 1 - src/common/input/Keyboard.test.ts | 11 ++++++++--- src/common/input/Keyboard.ts | 6 ++++-- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/InputHandler.ts b/src/InputHandler.ts index a651440a0e..fb37f4ab1f 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1788,9 +1788,6 @@ export class InputHandler extends Disposable implements IInputHandler { case 25: // show cursor this._coreService.isCursorHidden = false; break; - case 1039: - this._coreService.decPrivateModes.altEscMode = true; - break; case 1048: // alt screen cursor this.saveCursor(); break; @@ -2006,9 +2003,6 @@ export class InputHandler extends Disposable implements IInputHandler { case 25: // hide cursor this._coreService.isCursorHidden = true; break; - case 1039: - this._coreService.decPrivateModes.altEscMode = false; - break; case 1048: // alt screen cursor this.restoreCursor(); break; diff --git a/src/Terminal.ts b/src/Terminal.ts index 606466178f..1bcac1f056 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -1222,7 +1222,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp return false; } - const result = evaluateKeyboardEvent(event, this._coreService.decPrivateModes.altEscMode, this._coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta); + const result = evaluateKeyboardEvent(event, this._coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta); this.updateCursorStyle(event); diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index 2257530c17..4d9070cd8e 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -59,7 +59,6 @@ export class MockCoreService implements ICoreService { isCursorHidden: boolean = false; isFocused: boolean = false; decPrivateModes: IDecPrivateModes = { - altEscMode: true, applicationCursorKeys: false, applicationKeypad: false, origin: false, diff --git a/src/common/Types.d.ts b/src/common/Types.d.ts index 0a2d4252a5..b250b45eac 100644 --- a/src/common/Types.d.ts +++ b/src/common/Types.d.ts @@ -152,7 +152,6 @@ export interface IMarker extends IDisposable { } export interface IDecPrivateModes { - altEscMode: boolean; applicationCursorKeys: boolean; applicationKeypad: boolean; origin: boolean; diff --git a/src/common/input/Keyboard.test.ts b/src/common/input/Keyboard.test.ts index ce492f0c15..0bb0e24c15 100644 --- a/src/common/input/Keyboard.test.ts +++ b/src/common/input/Keyboard.test.ts @@ -16,7 +16,6 @@ function testEvaluateKeyboardEvent(partialEvent: { key?: string; type?: string; }, partialOptions: { - altEnterMode?: boolean; applicationCursorMode?: boolean; isMac?: boolean; macOptionIsMeta?: boolean; @@ -31,12 +30,11 @@ function testEvaluateKeyboardEvent(partialEvent: { type: partialEvent.type || '' }; const options = { - altEnterMode: partialOptions.altEnterMode || true, applicationCursorMode: partialOptions.applicationCursorMode || false, isMac: partialOptions.isMac || false, macOptionIsMeta: partialOptions.macOptionIsMeta || false }; - return evaluateKeyboardEvent(event, options.altEnterMode, options.applicationCursorMode, options.isMac, options.macOptionIsMeta); + return evaluateKeyboardEvent(event, options.applicationCursorMode, options.isMac, options.macOptionIsMeta); } describe('Keyboard', () => { @@ -91,6 +89,9 @@ describe('Keyboard', () => { it('should return \\x1b\\r for alt+enter', () => { assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 13 }).key, '\x1b\r'); }); + it('should return \\x1b\\x1b for alt+esc', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 27 }).key, '\x1b\x1b'); + }); it('should return \\x1b[5D for ctrl+left', () => { assert.equal(testEvaluateKeyboardEvent({ ctrlKey: true, keyCode: 37 }).key, '\x1b[1;5D'); // CSI 5 D }); @@ -146,6 +147,10 @@ describe('Keyboard', () => { it('should return \\x1ba for alt+a', () => { assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 65 }, { isMac: true, macOptionIsMeta: true }).key, '\x1ba'); }); + + it('should return \\x1b\\x1b for alt+enter', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 13 }, { isMac: true, macOptionIsMeta: true }).key, '\x1b\r'); + }); }); it('should return \\x1b[5A for alt+up', () => { diff --git a/src/common/input/Keyboard.ts b/src/common/input/Keyboard.ts index 67b5ee44d6..d07ea6251d 100644 --- a/src/common/input/Keyboard.ts +++ b/src/common/input/Keyboard.ts @@ -37,7 +37,6 @@ const KEYCODE_KEY_MAPPINGS: { [key: number]: [string, string]} = { export function evaluateKeyboardEvent( ev: IKeyboardEvent, - altEscMode: boolean, applicationCursorMode: boolean, isMac: boolean, macOptionIsMeta: boolean @@ -104,7 +103,7 @@ export function evaluateKeyboardEvent( break; case 13: // return/enter - if (altEscMode && modifiers === 2) { + if (ev.altKey) { result.key = C0.ESC + C0.CR; } else { @@ -115,6 +114,9 @@ export function evaluateKeyboardEvent( case 27: // escape result.key = C0.ESC; + if (ev.altKey) { + result.key = C0.ESC + C0.ESC; + } result.cancel = true; break; case 37: From 3ef41f2b1d454fcb07d65ddb99944cc000905547 Mon Sep 17 00:00:00 2001 From: kumaran-14 Date: Fri, 10 Apr 2020 23:19:31 +0530 Subject: [PATCH 4/5] Remove decset modes from coreservices --- src/common/services/CoreService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/services/CoreService.ts b/src/common/services/CoreService.ts index c8c77c7d1c..df9161e9c7 100644 --- a/src/common/services/CoreService.ts +++ b/src/common/services/CoreService.ts @@ -9,7 +9,6 @@ import { IDecPrivateModes, ICharset } from 'common/Types'; import { clone } from 'common/Clone'; const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({ - altEscMode: true, applicationCursorKeys: false, applicationKeypad: false, origin: false, From ba0dc60b09bb5a8c5f34a33933b209466c2cc238 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 10 Apr 2020 12:53:02 -0700 Subject: [PATCH 5/5] Combine into ternary --- src/common/input/Keyboard.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/common/input/Keyboard.ts b/src/common/input/Keyboard.ts index d07ea6251d..fdb777b428 100644 --- a/src/common/input/Keyboard.ts +++ b/src/common/input/Keyboard.ts @@ -103,12 +103,7 @@ export function evaluateKeyboardEvent( break; case 13: // return/enter - if (ev.altKey) { - result.key = C0.ESC + C0.CR; - } - else { - result.key = C0.CR; - } + result.key = ev.altKey ? C0.ESC + C0.CR : C0.CR; result.cancel = true; break; case 27: