Merge remote-tracking branch 'ups/v3' into 847_proper_scrollback_value

This commit is contained in:
Daniel Imms
2017-08-08 19:05:24 -07:00
180 changed files with 1297 additions and 1248 deletions
+41 -57
View File
@@ -8,6 +8,15 @@
* has been extended to include xterm CSI codes, among
* other features.
* @license MIT
*
* Terminal Emulation References:
* http://vt100.net/
* http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt
* http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
* http://invisible-island.net/vttest/
* http://www.inwap.com/pdp10/ansicode.txt
* http://linux.die.net/man/4/console_codes
* http://linux.die.net/man/7/urxvt
*/
import { BufferSet } from './BufferSet';
@@ -28,9 +37,8 @@ import * as Browser from './utils/Browser';
import * as Mouse from './utils/Mouse';
import { CHARSETS } from './Charsets';
import { getRawByteCoords } from './utils/Mouse';
import { translateBufferLineToString } from './utils/BufferLine';
import { CustomKeyEventHandler, Charset, LinkMatcherHandler, LinkMatcherValidationCallback, CharData, LineData, Option, StringOption, BooleanOption, StringArrayOption, NumberOption, GeometryOption, HandlerOption } from './Types';
import { ITerminal, IBrowser, ITerminalOptions, IInputHandlingTerminal, ILinkMatcherOptions } from './Interfaces';
import { ITerminal, IBrowser, ITerminalOptions, IInputHandlingTerminal, ILinkMatcherOptions, IViewport, ICompositionHelper } from './Interfaces';
// Declare for RequireJS in loadAddon
declare var define: any;
@@ -260,8 +268,8 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
private linkifier: Linkifier;
public buffers: BufferSet;
public buffer: Buffer;
public viewport: Viewport;
private compositionHelper: CompositionHelper;
public viewport: IViewport;
private compositionHelper: ICompositionHelper;
public charMeasure: CharMeasure;
public cols: number;
@@ -379,7 +387,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
// Ensure the selection manager has the correct buffer
if (this.selectionManager) {
this.selectionManager.setBuffer(this.buffer.lines);
this.selectionManager.setBuffer(this.buffer);
}
this.setupStops();
@@ -438,6 +446,12 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
throw new Error('No option with key "' + key + '"');
}
switch (key) {
case 'tabStopWidth':
if (value < 1) {
console.warn(`tabStopWidth cannot be less than 1, value: ${value}`);
return;
}
break;
case 'scrollback':
if (this.options[key] !== value) {
const newBufferLength = this.rows + value;
@@ -590,14 +604,14 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
if (document.activeElement !== this) {
return;
}
self.keyDown(ev);
self._keyDown(ev);
}, true);
on(this.element, 'keypress', function (ev: KeyboardEvent): void {
if (document.activeElement !== this) {
return;
}
self.keyPress(ev);
self._keyPress(ev);
}, true);
on(this.element, 'keyup', (ev: KeyboardEvent) => {
@@ -607,19 +621,19 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
}, true);
on(this.textarea, 'keydown', (ev: KeyboardEvent) => {
this.keyDown(ev);
this._keyDown(ev);
}, true);
on(this.textarea, 'keypress', (ev: KeyboardEvent) => {
this.keyPress(ev);
this._keyPress(ev);
// Truncate the textarea's value, since it is not needed
this.textarea.value = '';
}, true);
on(this.textarea, 'compositionstart', this.compositionHelper.compositionstart.bind(this.compositionHelper));
on(this.textarea, 'compositionupdate', this.compositionHelper.compositionupdate.bind(this.compositionHelper));
on(this.textarea, 'compositionend', this.compositionHelper.compositionend.bind(this.compositionHelper));
this.on('refresh', this.compositionHelper.updateCompositionElements.bind(this.compositionHelper));
on(this.textarea, 'compositionstart', () => this.compositionHelper.compositionstart());
on(this.textarea, 'compositionupdate', (e: CompositionEvent) => this.compositionHelper.compositionupdate(e));
on(this.textarea, 'compositionend', () => this.compositionHelper.compositionend());
this.on('refresh', () => this.compositionHelper.updateCompositionElements());
this.on('refresh', (data) => this.queueLinkification(data.start, data.end));
}
@@ -643,9 +657,8 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
* Opens the terminal within an element.
*
* @param {HTMLElement} parent The element to create the terminal within.
* @param {boolean} focus Focus the terminal, after it gets instantiated in the DOM
*/
private open(parent: HTMLElement, focus?: boolean): void {
public open(parent: HTMLElement): void {
let i = 0;
let div;
@@ -732,7 +745,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
this.viewport = new Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasure);
this.renderer = new Renderer(this);
this.selectionManager = new SelectionManager(this, this.buffer.lines, this.rowContainer, this.charMeasure);
this.selectionManager = new SelectionManager(this, this.buffer, this.rowContainer, this.charMeasure);
this.selectionManager.on('refresh', data => {
this.renderer.refreshSelection(data.start, data.end);
});
@@ -753,24 +766,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
// Initialize global actions that need to be taken on the document.
this.initGlobal();
/**
* Automatic focus functionality.
* TODO: Default to `false` starting with xterm.js 3.0.
*/
if (typeof focus === 'undefined') {
let message = 'You did not pass the `focus` argument in `Terminal.prototype.open()`.\n';
message += 'The `focus` argument now defaults to `true` but starting with xterm.js 3.0 ';
message += 'it will default to `false`.';
console.warn(message);
focus = true;
}
if (focus) {
this.focus();
}
// Listen for mouse events and translate
// them into terminal mouse protocols.
this.bindMouse();
@@ -1094,7 +1089,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
if (!this.mouseEvents) return;
if (this.x10Mouse || this.vt300Mouse || this.decLocator) return;
sendButton(ev);
return this.cancel(ev);
ev.preventDefault();
});
// allow wheel scrolling in
@@ -1351,18 +1346,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
this.write(data + '\r\n');
}
/**
* DEPRECATED: only for backward compatibility. Please use attachCustomKeyEventHandler() instead.
* @param {function} customKeydownHandler The custom KeyboardEvent handler to attach. This is a
* function that takes a KeyboardEvent, allowing consumers to stop propogation and/or prevent
* the default action. The function returns whether the event should be processed by xterm.js.
*/
public attachCustomKeydownHandler(customKeydownHandler: CustomKeyEventHandler): void {
const message = 'attachCustomKeydownHandler() is DEPRECATED and will be removed soon. Please use attachCustomKeyEventHandler() instead.';
console.warn(message);
this.attachCustomKeyEventHandler(customKeydownHandler);
}
/**
* Attaches a custom key event handler which is run before keys are processed, giving consumers of
* xterm.js ultimate control as to what keys should be processed by the terminal and what keys
@@ -1474,21 +1457,21 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
* - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
* @param {KeyboardEvent} ev The keydown event to be handled.
*/
private keyDown(ev: KeyboardEvent): boolean {
protected _keyDown(ev: KeyboardEvent): boolean {
if (this.customKeyEventHandler && this.customKeyEventHandler(ev) === false) {
return false;
}
this.restartCursorBlinking();
if (!this.compositionHelper.keydown.bind(this.compositionHelper)(ev)) {
if (!this.compositionHelper.keydown(ev)) {
if (this.buffer.ybase !== this.buffer.ydisp) {
this.scrollToBottom();
}
return false;
}
const result = this.evaluateKeyEscapeSequence(ev);
const result = this._evaluateKeyEscapeSequence(ev);
if (result.key === C0.DC3) { // XOFF
this.writeStopped = true;
@@ -1501,7 +1484,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
return this.cancel(ev, true);
}
if (isThirdLevelShift(ev)) {
if (isThirdLevelShift(this.browser, ev)) {
return true;
}
@@ -1529,7 +1512,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
* Reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
* @param ev The keyboard event to be translated to key escape sequence.
*/
private evaluateKeyEscapeSequence(ev: KeyboardEvent): {cancel: boolean, key: string, scrollDisp: number} {
protected _evaluateKeyEscapeSequence(ev: KeyboardEvent): {cancel: boolean, key: string, scrollDisp: number} {
const result: {cancel: boolean, key: string, scrollDisp: number} = {
// Whether to cancel event propogation (NOTE: this may not be needed since the event is
// canceled at the end of keyDown
@@ -1836,7 +1819,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
* - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
* @param {KeyboardEvent} ev The keypress event to be handled.
*/
private keyPress(ev: KeyboardEvent): boolean {
protected _keyPress(ev: KeyboardEvent): boolean {
let key;
if (this.customKeyEventHandler && this.customKeyEventHandler(ev) === false) {
@@ -1856,7 +1839,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
}
if (!key || (
(ev.altKey || ev.ctrlKey || ev.metaKey) && !isThirdLevelShift(ev)
(ev.altKey || ev.ctrlKey || ev.metaKey) && !isThirdLevelShift(this.browser, ev)
)) {
return false;
}
@@ -2236,6 +2219,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
this.buffer.tabs[this.buffer.x] = true;
}
// TODO: Remove cancel function and cancelEvents option
public cancel(ev: Event, force?: boolean): boolean {
if (!this.options.cancelEvents && !force) {
return;
@@ -2305,10 +2289,10 @@ function off(el: any, type: string, handler: (event: Event) => any, capture: boo
el.removeEventListener(type, handler, capture);
}
function isThirdLevelShift(ev: KeyboardEvent): boolean {
function isThirdLevelShift(browser: IBrowser, ev: KeyboardEvent): boolean {
const thirdLevelKey =
(Browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) ||
(Browser.isMSWindows && ev.altKey && ev.ctrlKey && !ev.metaKey);
(browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) ||
(browser.isMSWindows && ev.altKey && ev.ctrlKey && !ev.metaKey);
if (ev.type === 'keypress') {
return thirdLevelKey;