未验证 提交 1afae050 编写于 作者: D Daniel Imms 提交者: GitHub

Merge pull request #52463 from Microsoft/tyriar/xterm_update

Update xterm
......@@ -670,19 +670,38 @@ declare module 'vscode-xterm' {
// Modifications to official .d.ts below
declare module 'vscode-xterm' {
interface Terminal {
interface TerminalCore {
buffer: {
y: number;
ybase: number;
ydisp: number;
x: number;
lines: any[];
translateBufferLineToString(lineIndex: number, trimRight: boolean): string;
};
send(text: string): void;
/**
* Emit an event on the terminal.
*/
emit(type: string, data: any): void;
charMeasure?: { height: number, width: number };
renderer: {
_renderLayers: any[];
onIntersectionChange: any;
};
}
interface Terminal {
_core: TerminalCore;
webLinksInit(handler?: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): void;
winptyCompatInit(): void;
/**
* Find the next instance of the term, then scroll to and select it. If it
* doesn't exist, do nothing.
......@@ -698,9 +717,5 @@ declare module 'vscode-xterm' {
* @return Whether a result was found.
*/
findPrevious(term: string): boolean;
webLinksInit(handler?: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): void;
winptyCompatInit(): void;
charMeasure?: { height: number, width: number };
}
}
......@@ -13,6 +13,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { getTopLeftOffset, getClientArea } from 'vs/base/browser/dom';
import * as electron from 'electron';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { Terminal } from 'vscode-xterm';
function serializeElement(element: Element, recursive: boolean): IElement {
const attributes = Object.create(null);
......@@ -172,7 +173,7 @@ class WindowDriver implements IWindowDriver {
throw new Error('Terminal not found: ' + selector);
}
const xterm = (element as any).xterm;
const xterm: Terminal = (element as any).xterm;
if (!xterm) {
throw new Error('Xterm not found: ' + selector);
......@@ -180,8 +181,8 @@ class WindowDriver implements IWindowDriver {
const lines: string[] = [];
for (let i = 0; i < xterm.buffer.lines.length; i++) {
lines.push(xterm.buffer.translateBufferLineToString(i, true));
for (let i = 0; i < xterm._core.buffer.lines.length; i++) {
lines.push(xterm._core.buffer.translateBufferLineToString(i, true));
}
return lines;
......@@ -194,13 +195,13 @@ class WindowDriver implements IWindowDriver {
throw new Error('Element not found');
}
const xterm = (element as any).xterm;
const xterm: Terminal = (element as any).xterm;
if (!xterm) {
throw new Error('Xterm not found');
}
xterm.send(text);
xterm._core.send(text);
}
async openDevTools(): TPromise<void> {
......
......@@ -137,14 +137,14 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
// Get the character dimensions from xterm if it's available
if (xterm) {
if (xterm.charMeasure && xterm.charMeasure.width && xterm.charMeasure.height) {
if (xterm._core.charMeasure && xterm._core.charMeasure.width && xterm._core.charMeasure.height) {
return {
fontFamily,
fontSize,
letterSpacing,
lineHeight,
charHeight: xterm.charMeasure.height,
charWidth: xterm.charMeasure.width
charHeight: xterm._core.charMeasure.height,
charWidth: xterm._core.charMeasure.width
};
}
}
......
......@@ -232,7 +232,7 @@ export class TerminalInstance implements ITerminalInstance {
// it gets removed and then added back to the DOM (resetting scrollTop to 0).
// Upstream issue: https://github.com/sourcelair/xterm.js/issues/291
if (this._xterm) {
this._xterm.emit('scroll', this._xterm.buffer.ydisp);
this._xterm.emit('scroll', this._xterm._core.buffer.ydisp);
}
}
......@@ -460,7 +460,7 @@ export class TerminalInstance implements ITerminalInstance {
private _measureRenderTime(): void {
const frameTimes: number[] = [];
const textRenderLayer = (<any>this._xterm).renderer._renderLayers[0];
const textRenderLayer = this._xterm._core.renderer._renderLayers[0];
const originalOnGridChanged = textRenderLayer.onGridChanged;
const evaluateCanvasRenderer = () => {
......@@ -575,7 +575,7 @@ export class TerminalInstance implements ITerminalInstance {
this._xtermElement = null;
}
if (this._xterm) {
const buffer = (<any>this._xterm.buffer);
const buffer = (<any>this._xterm._core.buffer);
this._sendLineData(buffer, buffer.ybase + buffer.y);
this._xterm.dispose();
this._xterm = null;
......@@ -648,7 +648,7 @@ export class TerminalInstance implements ITerminalInstance {
// necessary if the number of rows in the terminal has decreased while it was in the
// background since scrollTop changes take no effect but the terminal's position does
// change since the number of visible rows decreases.
this._xterm.emit('scroll', this._xterm.buffer.ydisp);
this._xterm.emit('scroll', this._xterm._core.buffer.ydisp);
if (this._container && this._container.parentElement) {
// Force a layout when the instance becomes invisible. This is particularly important
// for ensuring that terminals that are created in the background by an extension will
......@@ -848,7 +848,7 @@ export class TerminalInstance implements ITerminalInstance {
}
private _onLineFeed(): void {
const buffer = (<any>this._xterm.buffer);
const buffer = (<any>this._xterm._core.buffer);
const newLine = buffer.lines.get(buffer.ybase + buffer.y);
if (!newLine.isWrapped) {
this._sendLineData(buffer, buffer.ybase + buffer.y - 1);
......@@ -974,7 +974,7 @@ export class TerminalInstance implements ITerminalInstance {
// on Winodws/Linux would fire an event saying that the terminal was not visible.
// This should only force a refresh if one is needed.
if (this._xterm.getOption('rendererType') === 'canvas') {
(<any>this._xterm).renderer.onIntersectionChange({ intersectionRatio: 1 });
this._xterm._core.renderer.onIntersectionChange({ intersectionRatio: 1 });
}
}
}
......
......@@ -49,7 +49,7 @@ export class TerminalCommandTracker implements ITerminalCommandTracker, IDisposa
}
private _onEnter(): void {
if (this._xterm.buffer.x >= MINIMUM_PROMPT_LENGTH) {
if (this._xterm._core.buffer.x >= MINIMUM_PROMPT_LENGTH) {
this._xterm.addMarker(0);
}
}
......@@ -176,7 +176,7 @@ export class TerminalCommandTracker implements ITerminalCommandTracker, IDisposa
private _getLine(marker: IMarker | Boundary): number {
// Use the _second last_ row as the last row is likely the prompt
if (marker === Boundary.Bottom) {
return this._xterm.buffer.ybase + this._xterm.rows - 1;
return this._xterm._core.buffer.ybase + this._xterm.rows - 1;
}
if (marker === Boundary.Top) {
......@@ -236,10 +236,10 @@ export class TerminalCommandTracker implements ITerminalCommandTracker, IDisposa
if (this._currentMarker === Boundary.Bottom) {
return 0;
} else if (this._currentMarker === Boundary.Top) {
return 0 - (this._xterm.buffer.ybase + this._xterm.buffer.y);
return 0 - (this._xterm._core.buffer.ybase + this._xterm._core.buffer.y);
} else {
let offset = this._getLine(this._currentMarker);
offset -= this._xterm.buffer.ybase + this._xterm.buffer.y;
offset -= this._xterm._core.buffer.ybase + this._xterm._core.buffer.y;
return offset;
}
}
......
......@@ -4,19 +4,23 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { Terminal } from 'vscode-xterm';
import { Terminal, TerminalCore } from 'vscode-xterm';
import { TerminalCommandTracker } from 'vs/workbench/parts/terminal/node/terminalCommandTracker';
import { isWindows } from 'vs/base/common/platform';
interface TestTerminal extends Terminal {
interface TestTerminalCore extends TerminalCore {
writeBuffer: string[];
_innerWrite(): void;
}
interface TestTerminal extends Terminal {
_core: TestTerminalCore;
}
function syncWrite(term: TestTerminal, data: string): void {
// Terminal.write is asynchronous
term.writeBuffer.push(data);
term._innerWrite();
term._core.writeBuffer.push(data);
term._core._innerWrite();
}
const ROWS = 10;
......@@ -62,24 +66,24 @@ suite('Workbench - TerminalCommandTracker', () => {
for (let i = 0; i < 20; i++) {
syncWrite(xterm, `\r\n`);
}
assert.equal(xterm.buffer.ybase, 20);
assert.equal(xterm.buffer.ydisp, 20);
assert.equal(xterm._core.buffer.ybase, 20);
assert.equal(xterm._core.buffer.ydisp, 20);
// Scroll to marker
commandTracker.scrollToPreviousCommand();
assert.equal(xterm.buffer.ydisp, 9);
assert.equal(xterm._core.buffer.ydisp, 9);
// Scroll to top boundary
commandTracker.scrollToPreviousCommand();
assert.equal(xterm.buffer.ydisp, 0);
assert.equal(xterm._core.buffer.ydisp, 0);
// Scroll to marker
commandTracker.scrollToNextCommand();
assert.equal(xterm.buffer.ydisp, 9);
assert.equal(xterm._core.buffer.ydisp, 9);
// Scroll to bottom boundary
commandTracker.scrollToNextCommand();
assert.equal(xterm.buffer.ydisp, 20);
assert.equal(xterm._core.buffer.ydisp, 20);
});
test('should select to the next and previous commands', () => {
(<any>window).matchMedia = () => {
......@@ -98,8 +102,8 @@ suite('Workbench - TerminalCommandTracker', () => {
assert.equal(xterm.markers[1].line, 11);
syncWrite(xterm, '\n\r3');
assert.equal(xterm.buffer.ybase, 3);
assert.equal(xterm.buffer.ydisp, 3);
assert.equal(xterm._core.buffer.ybase, 3);
assert.equal(xterm._core.buffer.ydisp, 3);
assert.equal(xterm.getSelection(), '');
commandTracker.selectToPreviousCommand();
......@@ -128,8 +132,8 @@ suite('Workbench - TerminalCommandTracker', () => {
assert.equal(xterm.markers[1].line, 11);
syncWrite(xterm, '\n\r3');
assert.equal(xterm.buffer.ybase, 3);
assert.equal(xterm.buffer.ydisp, 3);
assert.equal(xterm._core.buffer.ybase, 3);
assert.equal(xterm._core.buffer.ydisp, 3);
assert.equal(xterm.getSelection(), '');
commandTracker.selectToPreviousLine();
......
......@@ -6253,9 +6253,9 @@ vscode-textmate@^4.0.0-next.2:
fast-plist "^0.1.2"
oniguruma "^7.0.0"
vscode-xterm@3.5.0-beta13:
version "3.5.0-beta13"
resolved "https://registry.yarnpkg.com/vscode-xterm/-/vscode-xterm-3.5.0-beta13.tgz#8fc24f6d7509e6119d8ec0deb07070e1ed86ddbc"
vscode-xterm@3.5.0-beta14:
version "3.5.0-beta14"
resolved "https://registry.yarnpkg.com/vscode-xterm/-/vscode-xterm-3.5.0-beta14.tgz#3d55256e68b822cb528e64c281a786d2ac9db369"
vso-node-api@^6.1.2-preview:
version "6.1.2-preview"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册