Merge branch 'master' into parser_inner_loops
This commit is contained in:
@@ -14,7 +14,6 @@ npm-debug.log
|
|||||||
.env
|
.env
|
||||||
build/
|
build/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
fixtures/typings-test/*.js
|
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
|
||||||
# Keep bundled code out of Git
|
# Keep bundled code out of Git
|
||||||
|
|||||||
@@ -18,54 +18,24 @@ export interface ISearchResult {
|
|||||||
row: number;
|
row: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This is temporary, link to xtem when new version is published
|
|
||||||
interface INewTerminal extends Terminal {
|
|
||||||
buffer: IBuffer;
|
|
||||||
select(column: number, row: number, length: number): void;
|
|
||||||
getSelectionPosition(): ISelectionPosition | undefined;
|
|
||||||
}
|
|
||||||
interface IBuffer {
|
|
||||||
readonly cursorY: number;
|
|
||||||
readonly cursorX: number;
|
|
||||||
readonly viewportY: number;
|
|
||||||
readonly baseY: number;
|
|
||||||
readonly length: number;
|
|
||||||
getLine(y: number): IBufferLine | undefined;
|
|
||||||
}
|
|
||||||
interface IBufferLine {
|
|
||||||
readonly isWrapped: boolean;
|
|
||||||
getCell(x: number): IBufferCell;
|
|
||||||
translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
|
|
||||||
}
|
|
||||||
interface IBufferCell {
|
|
||||||
readonly char: string;
|
|
||||||
readonly width: number;
|
|
||||||
}
|
|
||||||
interface ISelectionPosition {
|
|
||||||
startColumn: number;
|
|
||||||
startRow: number;
|
|
||||||
endColumn: number;
|
|
||||||
endRow: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\;:"\',./<>?';
|
const NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\;:"\',./<>?';
|
||||||
const LINES_CACHE_TIME_TO_LIVE = 15 * 1000; // 15 secs
|
const LINES_CACHE_TIME_TO_LIVE = 15 * 1000; // 15 secs
|
||||||
|
|
||||||
export class SearchAddon implements ITerminalAddon {
|
export class SearchAddon implements ITerminalAddon {
|
||||||
private _terminal: INewTerminal;
|
private _terminal: Terminal | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* translateBufferLineToStringWithWrap is a fairly expensive call.
|
* translateBufferLineToStringWithWrap is a fairly expensive call.
|
||||||
* We memoize the calls into an array that has a time based ttl.
|
* We memoize the calls into an array that has a time based ttl.
|
||||||
* _linesCache is also invalidated when the terminal cursor moves.
|
* _linesCache is also invalidated when the terminal cursor moves.
|
||||||
*/
|
*/
|
||||||
private _linesCache: string[] = null;
|
private _linesCache: string[] | undefined;
|
||||||
private _linesCacheTimeoutId = 0;
|
private _linesCacheTimeoutId = 0;
|
||||||
private _cursorMoveListener: IDisposable | undefined;
|
private _cursorMoveListener: IDisposable | undefined;
|
||||||
private _resizeListener: IDisposable | undefined;
|
private _resizeListener: IDisposable | undefined;
|
||||||
|
|
||||||
public activate(terminal: Terminal): void {
|
public activate(terminal: Terminal): void {
|
||||||
this._terminal = <any>terminal;
|
this._terminal = terminal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public dispose(): void {}
|
public dispose(): void {}
|
||||||
@@ -78,8 +48,9 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
* @return Whether a result was found.
|
* @return Whether a result was found.
|
||||||
*/
|
*/
|
||||||
public findNext(term: string, searchOptions?: ISearchOptions): boolean {
|
public findNext(term: string, searchOptions?: ISearchOptions): boolean {
|
||||||
const {incremental} = searchOptions;
|
if (!this._terminal) {
|
||||||
let result: ISearchResult;
|
throw new Error('Cannot use addon until it has been loaded');
|
||||||
|
}
|
||||||
|
|
||||||
if (!term || term.length === 0) {
|
if (!term || term.length === 0) {
|
||||||
this._terminal.clearSelection();
|
this._terminal.clearSelection();
|
||||||
@@ -90,9 +61,10 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
let startRow = this._terminal.buffer.viewportY;
|
let startRow = this._terminal.buffer.viewportY;
|
||||||
|
|
||||||
if (this._terminal.hasSelection()) {
|
if (this._terminal.hasSelection()) {
|
||||||
|
const incremental = searchOptions ? searchOptions.incremental : false;
|
||||||
// Start from the selection end if there is a selection
|
// Start from the selection end if there is a selection
|
||||||
// For incremental search, use existing row
|
// For incremental search, use existing row
|
||||||
const currentSelection = this._terminal.getSelectionPosition();
|
const currentSelection = this._terminal.getSelectionPosition()!;
|
||||||
startRow = incremental ? currentSelection.startRow : currentSelection.endRow;
|
startRow = incremental ? currentSelection.startRow : currentSelection.endRow;
|
||||||
startCol = incremental ? currentSelection.startColumn : currentSelection.endColumn;
|
startCol = incremental ? currentSelection.startColumn : currentSelection.endColumn;
|
||||||
}
|
}
|
||||||
@@ -105,13 +77,14 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
let cumulativeCols = startCol;
|
let cumulativeCols = startCol;
|
||||||
// If startRow is wrapped row, scan for unwrapped row above.
|
// If startRow is wrapped row, scan for unwrapped row above.
|
||||||
// So we can start matching on wrapped line from long unwrapped line.
|
// So we can start matching on wrapped line from long unwrapped line.
|
||||||
while (this._terminal.buffer.getLine(findingRow).isWrapped) {
|
let currentLine = this._terminal.buffer.getLine(findingRow);
|
||||||
findingRow--;
|
while (currentLine && currentLine.isWrapped) {
|
||||||
cumulativeCols += this._terminal.cols;
|
cumulativeCols += this._terminal.cols;
|
||||||
|
currentLine = this._terminal.buffer.getLine(--findingRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search startRow
|
// Search startRow
|
||||||
result = this._findInLine(term, findingRow, cumulativeCols, searchOptions);
|
let result = this._findInLine(term, findingRow, cumulativeCols, searchOptions);
|
||||||
|
|
||||||
// Search from startRow + 1 to end
|
// Search from startRow + 1 to end
|
||||||
if (!result) {
|
if (!result) {
|
||||||
@@ -150,7 +123,9 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
* @return Whether a result was found.
|
* @return Whether a result was found.
|
||||||
*/
|
*/
|
||||||
public findPrevious(term: string, searchOptions?: ISearchOptions): boolean {
|
public findPrevious(term: string, searchOptions?: ISearchOptions): boolean {
|
||||||
let result: ISearchResult;
|
if (!this._terminal) {
|
||||||
|
throw new Error('Cannot use addon until it has been loaded');
|
||||||
|
}
|
||||||
|
|
||||||
if (!term || term.length === 0) {
|
if (!term || term.length === 0) {
|
||||||
this._terminal.clearSelection();
|
this._terminal.clearSelection();
|
||||||
@@ -163,7 +138,7 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
|
|
||||||
if (this._terminal.hasSelection()) {
|
if (this._terminal.hasSelection()) {
|
||||||
// Start from the selection start if there is a selection
|
// Start from the selection start if there is a selection
|
||||||
const currentSelection = this._terminal.getSelectionPosition();
|
const currentSelection = this._terminal.getSelectionPosition()!;
|
||||||
startRow = currentSelection.startRow;
|
startRow = currentSelection.startRow;
|
||||||
startCol = currentSelection.startColumn;
|
startCol = currentSelection.startColumn;
|
||||||
}
|
}
|
||||||
@@ -171,14 +146,14 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
this._initLinesCache();
|
this._initLinesCache();
|
||||||
|
|
||||||
// Search startRow
|
// Search startRow
|
||||||
result = this._findInLine(term, startRow, startCol, searchOptions, isReverseSearch);
|
let result = this._findInLine(term, startRow, startCol, searchOptions, isReverseSearch);
|
||||||
|
|
||||||
// Search from startRow - 1 to top
|
// Search from startRow - 1 to top
|
||||||
if (!result) {
|
if (!result) {
|
||||||
// If the line is wrapped line, increase number of columns that is needed to be scanned
|
// If the line is wrapped line, increase number of columns that is needed to be scanned
|
||||||
// Se we can scan on wrapped line from unwrapped line
|
// Se we can scan on wrapped line from unwrapped line
|
||||||
let cumulativeCols = this._terminal.cols;
|
let cumulativeCols = this._terminal.cols;
|
||||||
if (this._terminal.buffer.getLine(startRow).isWrapped) {
|
if (this._terminal.buffer.getLine(startRow)!.isWrapped) {
|
||||||
cumulativeCols += startCol;
|
cumulativeCols += startCol;
|
||||||
}
|
}
|
||||||
for (let y = startRow - 1; y >= 0; y--) {
|
for (let y = startRow - 1; y >= 0; y--) {
|
||||||
@@ -188,7 +163,8 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
}
|
}
|
||||||
// If the current line is wrapped line, increase scanning range,
|
// If the current line is wrapped line, increase scanning range,
|
||||||
// preparing for scanning on unwrapped line
|
// preparing for scanning on unwrapped line
|
||||||
if (this._terminal.buffer.getLine(y).isWrapped) {
|
const line = this._terminal.buffer.getLine(y);
|
||||||
|
if (line && line.isWrapped) {
|
||||||
cumulativeCols += this._terminal.cols;
|
cumulativeCols += this._terminal.cols;
|
||||||
} else {
|
} else {
|
||||||
cumulativeCols = this._terminal.cols;
|
cumulativeCols = this._terminal.cols;
|
||||||
@@ -206,7 +182,8 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
if (result) {
|
if (result) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this._terminal.buffer.getLine(y).isWrapped) {
|
const line = this._terminal.buffer.getLine(y);
|
||||||
|
if (line && line.isWrapped) {
|
||||||
cumulativeCols += this._terminal.cols;
|
cumulativeCols += this._terminal.cols;
|
||||||
} else {
|
} else {
|
||||||
cumulativeCols = this._terminal.cols;
|
cumulativeCols = this._terminal.cols;
|
||||||
@@ -222,10 +199,11 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
* Sets up a line cache with a ttl
|
* Sets up a line cache with a ttl
|
||||||
*/
|
*/
|
||||||
private _initLinesCache(): void {
|
private _initLinesCache(): void {
|
||||||
|
const terminal = this._terminal!;
|
||||||
if (!this._linesCache) {
|
if (!this._linesCache) {
|
||||||
this._linesCache = new Array(this._terminal.buffer.length);
|
this._linesCache = new Array(terminal.buffer.length);
|
||||||
this._cursorMoveListener = this._terminal.onCursorMove(() => this._destroyLinesCache());
|
this._cursorMoveListener = terminal.onCursorMove(() => this._destroyLinesCache());
|
||||||
this._resizeListener = this._terminal.onResize(() => this._destroyLinesCache());
|
this._resizeListener = terminal.onResize(() => this._destroyLinesCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
window.clearTimeout(this._linesCacheTimeoutId);
|
window.clearTimeout(this._linesCacheTimeoutId);
|
||||||
@@ -233,7 +211,7 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _destroyLinesCache(): void {
|
private _destroyLinesCache(): void {
|
||||||
this._linesCache = null;
|
this._linesCache = undefined;
|
||||||
if (this._cursorMoveListener) {
|
if (this._cursorMoveListener) {
|
||||||
this._cursorMoveListener.dispose();
|
this._cursorMoveListener.dispose();
|
||||||
this._cursorMoveListener = undefined;
|
this._cursorMoveListener = undefined;
|
||||||
@@ -270,15 +248,17 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
* @param searchOptions Search options.
|
* @param searchOptions Search options.
|
||||||
* @return The search result if it was found.
|
* @return The search result if it was found.
|
||||||
*/
|
*/
|
||||||
protected _findInLine(term: string, row: number, col: number, searchOptions: ISearchOptions = {}, isReverseSearch: boolean = false): ISearchResult {
|
protected _findInLine(term: string, row: number, col: number, searchOptions: ISearchOptions = {}, isReverseSearch: boolean = false): ISearchResult | undefined {
|
||||||
|
const terminal = this._terminal!;
|
||||||
|
|
||||||
// Ignore wrapped lines, only consider on unwrapped line (first row of command string).
|
// Ignore wrapped lines, only consider on unwrapped line (first row of command string).
|
||||||
if (this._terminal.buffer.getLine(row).isWrapped) {
|
const firstLine = terminal.buffer.getLine(row);
|
||||||
|
if (firstLine && firstLine.isWrapped) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let stringLine = this._linesCache ? this._linesCache[row] : void 0;
|
let stringLine = this._linesCache ? this._linesCache[row] : void 0;
|
||||||
if (stringLine === void 0) {
|
if (stringLine === void 0) {
|
||||||
stringLine = this.translateBufferLineToStringWithWrap(row, true);
|
stringLine = this._translateBufferLineToStringWithWrap(row, true);
|
||||||
if (this._linesCache) {
|
if (this._linesCache) {
|
||||||
this._linesCache[row] = stringLine;
|
this._linesCache[row] = stringLine;
|
||||||
}
|
}
|
||||||
@@ -290,7 +270,7 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
let resultIndex = -1;
|
let resultIndex = -1;
|
||||||
if (searchOptions.regex) {
|
if (searchOptions.regex) {
|
||||||
const searchRegex = RegExp(searchTerm, 'g');
|
const searchRegex = RegExp(searchTerm, 'g');
|
||||||
let foundTerm: RegExpExecArray;
|
let foundTerm: RegExpExecArray | null;
|
||||||
if (isReverseSearch) {
|
if (isReverseSearch) {
|
||||||
// This loop will get the resultIndex of the _last_ regex match in the range 0..col
|
// This loop will get the resultIndex of the _last_ regex match in the range 0..col
|
||||||
while (foundTerm = searchRegex.exec(searchStringLine.slice(0, col))) {
|
while (foundTerm = searchRegex.exec(searchStringLine.slice(0, col))) {
|
||||||
@@ -317,28 +297,33 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
|
|
||||||
if (resultIndex >= 0) {
|
if (resultIndex >= 0) {
|
||||||
// Adjust the row number and search index if needed since a "line" of text can span multiple rows
|
// Adjust the row number and search index if needed since a "line" of text can span multiple rows
|
||||||
if (resultIndex >= this._terminal.cols) {
|
if (resultIndex >= terminal.cols) {
|
||||||
row += Math.floor(resultIndex / this._terminal.cols);
|
row += Math.floor(resultIndex / terminal.cols);
|
||||||
resultIndex = resultIndex % this._terminal.cols;
|
resultIndex = resultIndex % terminal.cols;
|
||||||
}
|
}
|
||||||
if (searchOptions.wholeWord && !this._isWholeWord(resultIndex, searchStringLine, term)) {
|
if (searchOptions.wholeWord && !this._isWholeWord(resultIndex, searchStringLine, term)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const line = this._terminal.buffer.getLine(row);
|
const line = terminal.buffer.getLine(row);
|
||||||
|
|
||||||
for (let i = 0; i < resultIndex; i++) {
|
if (line) {
|
||||||
const cell = line.getCell(i);
|
for (let i = 0; i < resultIndex; i++) {
|
||||||
// Adjust the searchIndex to normalize emoji into single chars
|
const cell = line.getCell(i);
|
||||||
const char = cell.char;
|
if (!cell) {
|
||||||
if (char.length > 1) {
|
break;
|
||||||
resultIndex -= char.length - 1;
|
}
|
||||||
}
|
// Adjust the searchIndex to normalize emoji into single chars
|
||||||
// Adjust the searchIndex for empty characters following wide unicode
|
const char = cell.char;
|
||||||
// chars (eg. CJK)
|
if (char.length > 1) {
|
||||||
const charWidth = cell.width;
|
resultIndex -= char.length - 1;
|
||||||
if (charWidth === 0) {
|
}
|
||||||
resultIndex++;
|
// Adjust the searchIndex for empty characters following wide unicode
|
||||||
|
// chars (eg. CJK)
|
||||||
|
const charWidth = cell.width;
|
||||||
|
if (charWidth === 0) {
|
||||||
|
resultIndex++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -348,6 +333,7 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates a buffer line to a string, including subsequent lines if they are wraps.
|
* Translates a buffer line to a string, including subsequent lines if they are wraps.
|
||||||
* Wide characters will count as two columns in the resulting string. This
|
* Wide characters will count as two columns in the resulting string. This
|
||||||
@@ -356,14 +342,19 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
* @param line The line being translated.
|
* @param line The line being translated.
|
||||||
* @param trimRight Whether to trim whitespace to the right.
|
* @param trimRight Whether to trim whitespace to the right.
|
||||||
*/
|
*/
|
||||||
public translateBufferLineToStringWithWrap(lineIndex: number, trimRight: boolean): string {
|
private _translateBufferLineToStringWithWrap(lineIndex: number, trimRight: boolean): string {
|
||||||
|
const terminal = this._terminal!;
|
||||||
let lineString = '';
|
let lineString = '';
|
||||||
let lineWrapsToNext: boolean;
|
let lineWrapsToNext: boolean;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
const nextLine = this._terminal.buffer.getLine(lineIndex + 1);
|
const nextLine = terminal.buffer.getLine(lineIndex + 1);
|
||||||
lineWrapsToNext = nextLine ? nextLine.isWrapped : false;
|
lineWrapsToNext = nextLine ? nextLine.isWrapped : false;
|
||||||
lineString += this._terminal.buffer.getLine(lineIndex).translateToString(!lineWrapsToNext && trimRight).substring(0, this._terminal.cols);
|
const line = terminal.buffer.getLine(lineIndex);
|
||||||
|
if (!line) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
lineString += line.translateToString(!lineWrapsToNext && trimRight).substring(0, terminal.cols);
|
||||||
lineIndex++;
|
lineIndex++;
|
||||||
} while (lineWrapsToNext);
|
} while (lineWrapsToNext);
|
||||||
|
|
||||||
@@ -375,13 +366,14 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
* @param result The result to select.
|
* @param result The result to select.
|
||||||
* @return Whethera result was selected.
|
* @return Whethera result was selected.
|
||||||
*/
|
*/
|
||||||
private _selectResult(result: ISearchResult): boolean {
|
private _selectResult(result: ISearchResult | undefined): boolean {
|
||||||
|
const terminal = this._terminal!;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
this._terminal.clearSelection();
|
terminal.clearSelection();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this._terminal.select(result.col, result.row, result.term.length);
|
terminal.select(result.col, result.row, result.term.length);
|
||||||
this._terminal.scrollLines(result.row - this._terminal.buffer.viewportY);
|
terminal.scrollLines(result.row - terminal.buffer.viewportY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
"outDir": "../lib",
|
"outDir": "../lib",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"removeComments": true
|
"removeComments": true,
|
||||||
|
"strict": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./**/*",
|
"./**/*",
|
||||||
|
|||||||
+1
-2
@@ -14,8 +14,7 @@ let testFiles = [
|
|||||||
'./out/*test.js',
|
'./out/*test.js',
|
||||||
'./out/**/*test.js',
|
'./out/**/*test.js',
|
||||||
'./out/*integration.js',
|
'./out/*integration.js',
|
||||||
'./out/**/*integration.js',
|
'./out/**/*integration.js'
|
||||||
'./lib/**/*test.js'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// ability to inject particular test files via
|
// ability to inject particular test files via
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"files": [
|
|
||||||
"typings-test.ts"
|
|
||||||
],
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "commonjs",
|
|
||||||
"target": "es5",
|
|
||||||
"lib": [
|
|
||||||
"dom",
|
|
||||||
"es6"
|
|
||||||
],
|
|
||||||
"noEmit": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,249 +0,0 @@
|
|||||||
/**
|
|
||||||
* @license MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// <reference path="../../typings/xterm.d.ts" />
|
|
||||||
|
|
||||||
import { Terminal, IDisposable } from 'xterm';
|
|
||||||
|
|
||||||
namespace constructor {
|
|
||||||
{
|
|
||||||
new Terminal();
|
|
||||||
new Terminal({});
|
|
||||||
new Terminal({
|
|
||||||
cols: 1,
|
|
||||||
rows: 1
|
|
||||||
});
|
|
||||||
new Terminal({
|
|
||||||
'cols': 1,
|
|
||||||
'cursorBlink': true,
|
|
||||||
'cursorStyle': 'block',
|
|
||||||
'disableStdin': false,
|
|
||||||
'rows': 1,
|
|
||||||
'scrollback': 10,
|
|
||||||
'tabStopWidth': 2
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace properties {
|
|
||||||
{
|
|
||||||
const t: Terminal = new Terminal();
|
|
||||||
const element: HTMLElement = t.element;
|
|
||||||
const textarea: HTMLTextAreaElement = t.textarea;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace static_methods {
|
|
||||||
{
|
|
||||||
Terminal.applyAddon({});
|
|
||||||
Terminal.applyAddon({});
|
|
||||||
Terminal.applyAddon({});
|
|
||||||
Terminal.applyAddon({});
|
|
||||||
Terminal.applyAddon({});
|
|
||||||
Terminal.applyAddon({});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace methods_core {
|
|
||||||
{
|
|
||||||
const t: Terminal = new Terminal();
|
|
||||||
t.blur();
|
|
||||||
t.focus();
|
|
||||||
t.clear();
|
|
||||||
t.refresh(0, 1);
|
|
||||||
t.reset();
|
|
||||||
t.resize(1, 1);
|
|
||||||
t.write('foo');
|
|
||||||
t.writeln('foo');
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const t: Terminal = new Terminal();
|
|
||||||
// no arg
|
|
||||||
t.on('blur', () => {});
|
|
||||||
t.on('focus', () => {});
|
|
||||||
t.on('linefeed', () => {});
|
|
||||||
t.on('selection', () => {});
|
|
||||||
// args
|
|
||||||
t.on('data', () => {});
|
|
||||||
t.on('data', (data: string) => console.log(data));
|
|
||||||
t.on('key', () => {});
|
|
||||||
t.on('key', (key: string) => console.log(key, event));
|
|
||||||
t.on('key', (key: string, event: KeyboardEvent) => console.log(key, event));
|
|
||||||
t.on('keydown', () => {});
|
|
||||||
t.on('keydown', (event: KeyboardEvent) => console.log(event));
|
|
||||||
t.on('keypress', () => {});
|
|
||||||
t.on('keypress', (event: KeyboardEvent) => console.log(event));
|
|
||||||
t.on('refresh', () => {});
|
|
||||||
t.on('refresh', (data: {start: number, end: number}) => console.log(data));
|
|
||||||
t.on('resize', () => {});
|
|
||||||
t.on('resize', (data: {cols: number, rows: number}) => console.log(data));
|
|
||||||
t.on('scroll', () => {});
|
|
||||||
t.on('scroll', (ydisp: number) => console.log(ydisp));
|
|
||||||
t.on('title', () => {});
|
|
||||||
t.on('title', (title: string) => console.log(title));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const t: Terminal = new Terminal();
|
|
||||||
// no arg
|
|
||||||
t.off('blur', () => {});
|
|
||||||
t.off('focus', () => {});
|
|
||||||
t.off('linefeed', () => {});
|
|
||||||
t.off('selection', () => {});
|
|
||||||
// args
|
|
||||||
t.off('data', () => {});
|
|
||||||
t.off('data', (data: string) => console.log(data));
|
|
||||||
t.off('key', () => {});
|
|
||||||
t.off('key', (key: string) => console.log(key, event));
|
|
||||||
t.off('key', (key: string, event: KeyboardEvent) => console.log(key, event));
|
|
||||||
t.off('keydown', () => {});
|
|
||||||
t.off('keydown', (event: KeyboardEvent) => console.log(event));
|
|
||||||
t.off('keypress', () => {});
|
|
||||||
t.off('keypress', (event: KeyboardEvent) => console.log(event));
|
|
||||||
t.off('refresh', () => {});
|
|
||||||
t.off('refresh', (data: {element: HTMLElement, start: number, end: number}) => console.log(data));
|
|
||||||
t.off('resize', () => {});
|
|
||||||
t.off('resize', (data: {terminal: Terminal, cols: number, rows: number}) => console.log(data));
|
|
||||||
t.off('scroll', () => {});
|
|
||||||
t.off('scroll', (ydisp: number) => console.log(ydisp));
|
|
||||||
t.off('title', () => {});
|
|
||||||
t.off('title', (title: string) => console.log(title));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const t: Terminal = new Terminal();
|
|
||||||
const e: HTMLElement = null;
|
|
||||||
t.open(e);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const t: Terminal = new Terminal();
|
|
||||||
t.attachCustomKeyEventHandler((e: KeyboardEvent) => true);
|
|
||||||
t.attachCustomKeyEventHandler((e: KeyboardEvent) => false);
|
|
||||||
const d1: IDisposable = t.addCsiHandler('x',
|
|
||||||
(params: number[], collect: string): boolean => params[0] === 1);
|
|
||||||
d1.dispose();
|
|
||||||
const d2: IDisposable = t.addOscHandler(199,
|
|
||||||
(data: string): boolean => true);
|
|
||||||
d2.dispose();
|
|
||||||
}
|
|
||||||
namespace options {
|
|
||||||
{
|
|
||||||
const t: Terminal = new Terminal();
|
|
||||||
const r01: string = t.getOption('cursorStyle');
|
|
||||||
const r02: string = t.getOption('termName');
|
|
||||||
const r03: boolean = t.getOption('cancelEvents');
|
|
||||||
const r04: boolean = t.getOption('convertEol');
|
|
||||||
const r05: boolean = t.getOption('cursorBlink');
|
|
||||||
const r06: boolean = t.getOption('debug');
|
|
||||||
const r07: boolean = t.getOption('disableStdin');
|
|
||||||
const r08: boolean = t.getOption('popOnBell');
|
|
||||||
const r09: boolean = t.getOption('screenKeys');
|
|
||||||
const r10: boolean = t.getOption('useFlowControl');
|
|
||||||
const r11: boolean = t.getOption('visualBell');
|
|
||||||
const r12: string[] = t.getOption('colors');
|
|
||||||
const r13: number = t.getOption('cols');
|
|
||||||
const r14: number = t.getOption('rows');
|
|
||||||
const r15: number = t.getOption('tabStopWidth');
|
|
||||||
const r16: number = t.getOption('scrollback');
|
|
||||||
const r18: (data: string) => void = t.getOption('handler');
|
|
||||||
const r19: string = t.getOption('bellSound');
|
|
||||||
const r20: string = t.getOption('bellStyle');
|
|
||||||
const r22: number = t.getOption('letterSpacing');
|
|
||||||
const r23: boolean = t.getOption('macOptionIsMeta');
|
|
||||||
const r24: string = t.getOption('fontWeight');
|
|
||||||
const r25: string = t.getOption('fontWeightBold');
|
|
||||||
const r26: boolean = t.getOption('allowTransparency');
|
|
||||||
const r27: boolean = t.getOption('rightClickSelectsWord');
|
|
||||||
const r28: boolean = t.getOption('windowsMode');
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const t: Terminal = new Terminal();
|
|
||||||
t.setOption('cursorStyle', 'bar');
|
|
||||||
t.setOption('cursorStyle', 'block');
|
|
||||||
t.setOption('cursorStyle', 'underline');
|
|
||||||
t.setOption('termName', 'foo');
|
|
||||||
t.setOption('cancelEvents', true);
|
|
||||||
t.setOption('convertEol', true);
|
|
||||||
t.setOption('cursorBlink', true);
|
|
||||||
t.setOption('debug', true);
|
|
||||||
t.setOption('disableStdin', true);
|
|
||||||
t.setOption('fontWeight', 'normal');
|
|
||||||
t.setOption('fontWeight', 'bold');
|
|
||||||
t.setOption('fontWeightBold', 'normal');
|
|
||||||
t.setOption('fontWeightBold', 'bold');
|
|
||||||
t.setOption('popOnBell', true);
|
|
||||||
t.setOption('screenKeys', true);
|
|
||||||
t.setOption('useFlowControl', true);
|
|
||||||
t.setOption('allowTransparency', true);
|
|
||||||
t.setOption('visualBell', true);
|
|
||||||
t.setOption('windowsMode', true);
|
|
||||||
t.setOption('colors', ['a', 'b']);
|
|
||||||
t.setOption('letterSpacing', 1);
|
|
||||||
t.setOption('cols', 1);
|
|
||||||
t.setOption('rows', 1);
|
|
||||||
t.setOption('tabStopWidth', 1);
|
|
||||||
t.setOption('scrollback', 1);
|
|
||||||
t.setOption('handler', (data: string) => console.log(data));
|
|
||||||
t.setOption('bellSound', 'foo');
|
|
||||||
t.setOption('bellStyle', 'none');
|
|
||||||
// t.setOption('bellStyle', 'visual');
|
|
||||||
t.setOption('bellStyle', 'sound');
|
|
||||||
// t.setOption('bellStyle', 'both');
|
|
||||||
t.setOption('fontSize', 1);
|
|
||||||
t.setOption('lineHeight', 1);
|
|
||||||
t.setOption('fontFamily', 'foo');
|
|
||||||
t.setOption('theme', {background: '#ff0000'});
|
|
||||||
t.setOption('macOptionIsMeta', true);
|
|
||||||
t.setOption('rightClickSelectsWord', false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
namespace scrolling {
|
|
||||||
{
|
|
||||||
const t: Terminal = new Terminal();
|
|
||||||
t.scrollLines(-1);
|
|
||||||
t.scrollLines(1);
|
|
||||||
t.scrollLines(-1);
|
|
||||||
t.scrollLines(1);
|
|
||||||
t.scrollToTop();
|
|
||||||
t.scrollToBottom();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
namespace selection {
|
|
||||||
{
|
|
||||||
const t: Terminal = new Terminal();
|
|
||||||
const r1: boolean = t.hasSelection();
|
|
||||||
const r2: string = t.getSelection();
|
|
||||||
t.clearSelection();
|
|
||||||
t.selectAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace methods_experimental {
|
|
||||||
{
|
|
||||||
const t: Terminal = new Terminal();
|
|
||||||
t.registerLinkMatcher(/foo/, () => {});
|
|
||||||
t.registerLinkMatcher(new RegExp('foo'), () => {});
|
|
||||||
t.registerLinkMatcher(/foo/, () => {}, {});
|
|
||||||
t.registerLinkMatcher(/foo/, (event: MouseEvent, uri: string) => {
|
|
||||||
console.log(event, uri);
|
|
||||||
return void 0;
|
|
||||||
}, {});
|
|
||||||
t.registerLinkMatcher(/foo/, () => true, {});
|
|
||||||
t.registerLinkMatcher(/foo/, () => false, {});
|
|
||||||
t.registerLinkMatcher(/foo/, () => true, {
|
|
||||||
matchIndex: 1
|
|
||||||
});
|
|
||||||
t.registerLinkMatcher(/foo/, () => true, {
|
|
||||||
matchIndex: 1,
|
|
||||||
priority: 1,
|
|
||||||
validationCallback: (uri: string, callback: (isValid: boolean) => void) => {
|
|
||||||
console.log(uri, callback);
|
|
||||||
},
|
|
||||||
tooltipCallback: (e: MouseEvent, uri: string) => {
|
|
||||||
console.log(e, uri);
|
|
||||||
},
|
|
||||||
leaveCallback: () => {}
|
|
||||||
});
|
|
||||||
t.deregisterLinkMatcher(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,13 +5,11 @@
|
|||||||
* This file contains integration tests for xterm.js.
|
* This file contains integration tests for xterm.js.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as cp from 'child_process';
|
|
||||||
import * as glob from 'glob';
|
import * as glob from 'glob';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as pty from 'node-pty';
|
import * as pty from 'node-pty';
|
||||||
import { assert } from 'chai';
|
|
||||||
import { Terminal } from './Terminal';
|
import { Terminal } from './Terminal';
|
||||||
import { IViewport } from './Types';
|
import { IViewport } from './Types';
|
||||||
import { CellData, WHITESPACE_CELL_CHAR } from 'core/buffer/BufferLine';
|
import { CellData, WHITESPACE_CELL_CHAR } from 'core/buffer/BufferLine';
|
||||||
@@ -154,16 +152,3 @@ if (os.platform() !== 'win32') {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('typings', () => {
|
|
||||||
it('should throw no compile errors', function (): void {
|
|
||||||
this.timeout(20000);
|
|
||||||
let tsc = path.join(__dirname, '..', 'node_modules', '.bin', 'tsc');
|
|
||||||
if (process.platform === 'win32') {
|
|
||||||
tsc += '.cmd';
|
|
||||||
}
|
|
||||||
const fixtureDir = path.join(__dirname, '..', 'fixtures', 'typings-test');
|
|
||||||
const result = cp.spawnSync(tsc, { cwd: fixtureDir });
|
|
||||||
assert.equal(result.status, 0, `build did not succeed:\nstdout: ${result.stdout.toString()}\nstderr: ${result.stderr.toString()}\n`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user