Mac OSX: altIsMeta support

* Support for altIsMeta option
* Instead of providing third-level shift characters
* Sample demo application using new altIsMeta option
This commit is contained in:
Saad Malik
2018-01-19 12:10:39 -08:00
parent 2f5029205d
commit 891fbd6b80
5 changed files with 2650 additions and 3 deletions
+1
View File
@@ -87,6 +87,7 @@ function createTerminal() {
terminalContainer.removeChild(terminalContainer.children[0]); terminalContainer.removeChild(terminalContainer.children[0]);
} }
term = new Terminal({ term = new Terminal({
altIsMeta: true,
cursorBlink: optionElements.cursorBlink.checked, cursorBlink: optionElements.cursorBlink.checked,
scrollback: parseInt(optionElements.scrollback.value, 10), scrollback: parseInt(optionElements.scrollback.value, 10),
tabStopWidth: parseInt(optionElements.tabstopwidth.value, 10) tabStopWidth: parseInt(optionElements.tabstopwidth.value, 10)
+2612
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -128,6 +128,7 @@ export interface IInputHandlingTerminal extends IEventEmitter {
} }
export interface ITerminalOptions { export interface ITerminalOptions {
altIsMeta?: boolean;
bellSound?: string; bellSound?: string;
bellStyle?: string; bellStyle?: string;
cancelEvents?: boolean; cancelEvents?: boolean;
+32
View File
@@ -503,6 +503,9 @@ describe('term.js addons', () => {
it('should return \\x1b[5C for alt+right', () => { it('should return \\x1b[5C for alt+right', () => {
assert.equal(term.evaluateKeyEscapeSequence({ altKey: true, keyCode: 39 }).key, '\x1b[1;5C'); // CSI 5 C assert.equal(term.evaluateKeyEscapeSequence({ altKey: true, keyCode: 39 }).key, '\x1b[1;5C'); // CSI 5 C
}); });
it('should return \\x1ba for alt+a', () => {
assert.equal(term.evaluateKeyEscapeSequence({ altKey: true, keyCode: 65 }).key, '\x1ba');
});
}); });
describe('On macOS platforms', () => { describe('On macOS platforms', () => {
@@ -515,6 +518,19 @@ describe('term.js addons', () => {
it('should return \\x1bf for alt+right', () => { it('should return \\x1bf for alt+right', () => {
assert.equal(term.evaluateKeyEscapeSequence({ altKey: true, keyCode: 39 }).key, '\x1bf'); // CSI 5 C assert.equal(term.evaluateKeyEscapeSequence({ altKey: true, keyCode: 39 }).key, '\x1bf'); // CSI 5 C
}); });
it('should return undefined for alt+a', () => {
assert.strictEqual(term.evaluateKeyEscapeSequence({ altKey: true, keyCode: 65 }).key, undefined);
});
});
describe('with altIsMeta', () => {
beforeEach(() => {
term.browser.isMac = true;
term.setOption('altIsMeta', true);
});
it('should return \\x1ba for alt+a', () => {
assert.equal(term.evaluateKeyEscapeSequence({ altKey: true, keyCode: 65 }).key, '\x1ba');
});
}); });
it('should return \\x1b[5A for alt+up', () => { it('should return \\x1b[5A for alt+up', () => {
@@ -597,6 +613,22 @@ describe('term.js addons', () => {
}; };
}); });
describe('with altIsMeta', () => {
beforeEach(() => {
term.browser.isMac = true;
term.setOption('altIsMeta', true);
});
it('should interfere with the alt key on keyDown', () => {
evKeyDown.altKey = true;
evKeyDown.keyCode = 81;
assert.equal(term.keyDown(evKeyDown), false);
evKeyDown.altKey = true;
evKeyDown.keyCode = 192;
assert.equal(term.keyDown(evKeyDown), false);
});
});
describe('On Mac OS', () => { describe('On Mac OS', () => {
beforeEach(() => { beforeEach(() => {
term.browser.isMac = true; term.browser.isMac = true;
+4 -3
View File
@@ -80,6 +80,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = {
scrollback: 1000, scrollback: 1000,
screenKeys: false, screenKeys: false,
debug: false, debug: false,
altIsMeta: false,
cancelEvents: false, cancelEvents: false,
disableStdin: false, disableStdin: false,
useFlowControl: false, useFlowControl: false,
@@ -1373,7 +1374,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
return this.cancel(ev, true); return this.cancel(ev, true);
} }
if (isThirdLevelShift(this.browser, ev)) { if (!this.options.altIsMeta && isThirdLevelShift(this.browser, ev)) {
return true; return true;
} }
@@ -1698,8 +1699,8 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
// ^] - Operating System Command (OSC) // ^] - Operating System Command (OSC)
result.key = String.fromCharCode(29); result.key = String.fromCharCode(29);
} }
} else if (!this.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) { } else if ((!this.browser.isMac || this.options.altIsMeta) && ev.altKey && !ev.ctrlKey && !ev.metaKey) {
// On Mac this is a third level shift. Use <Esc> instead. // On Mac this is a third level shift. Use <Esc> instead if !altIsMeta
if (ev.keyCode >= 65 && ev.keyCode <= 90) { if (ev.keyCode >= 65 && ev.keyCode <= 90) {
result.key = C0.ESC + String.fromCharCode(ev.keyCode + 32); result.key = C0.ESC + String.fromCharCode(ev.keyCode + 32);
} else if (ev.keyCode === 192) { } else if (ev.keyCode === 192) {