mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Merge branch 'master' into 1674_watch_addons
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# [](https://xtermjs.org)
|
||||
|
||||
[](https://xtermjs.visualstudio.com/xterm.js/_build/index?definitionId=1)
|
||||
[](https://dev.azure.com/xtermjs/xterm.js/_build/latest?definitionId=3)
|
||||
[](https://coveralls.io/github/xtermjs/xterm.js?branch=master)
|
||||
[](https://gitter.im/sourcelair/xterm.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
[](https://www.jsdelivr.com/package/npm/xterm)
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
# Node.js
|
||||
# Build a general Node.js application with npm.
|
||||
# Add steps that analyze code, save build artifacts, deploy, and more:
|
||||
# https://docs.microsoft.com/vsts/pipelines/languages/javascript
|
||||
|
||||
jobs:
|
||||
- job: Linux
|
||||
pool:
|
||||
vmImage: 'ubuntu-16.04'
|
||||
steps:
|
||||
- task: NodeTool@0
|
||||
inputs:
|
||||
versionSpec: '8.x'
|
||||
displayName: 'Install Node.js'
|
||||
- task: geeklearningio.gl-vsts-tasks-yarn.yarn-installer-task.YarnInstaller@2
|
||||
inputs:
|
||||
versionSpec: "1.9.4"
|
||||
displayName: 'Install Yarn'
|
||||
- script: |
|
||||
yarn
|
||||
displayName: 'Install dependencies and build'
|
||||
- script: |
|
||||
yarn mocha
|
||||
displayName: 'Test'
|
||||
- script: |
|
||||
yarn lint
|
||||
displayName: 'Lint'
|
||||
- script: |
|
||||
yarn test-coverage
|
||||
displayName: 'Generate and publish coverage'
|
||||
|
||||
- job: macOS
|
||||
pool:
|
||||
vmImage: 'xcode9-macos10.13'
|
||||
steps:
|
||||
- task: NodeTool@0
|
||||
inputs:
|
||||
versionSpec: '8.x'
|
||||
displayName: 'Install Node.js'
|
||||
- script: |
|
||||
yarn
|
||||
displayName: 'Install dependencies and build'
|
||||
- script: |
|
||||
yarn mocha
|
||||
displayName: 'Test'
|
||||
- script: |
|
||||
yarn lint
|
||||
displayName: 'Lint'
|
||||
|
||||
- job: Windows
|
||||
pool:
|
||||
vmImage: 'vs2017-win2016'
|
||||
steps:
|
||||
- task: NodeTool@0
|
||||
inputs:
|
||||
versionSpec: '8.x'
|
||||
displayName: 'Install Node.js'
|
||||
- script: |
|
||||
yarn
|
||||
displayName: 'Install dependencies and build'
|
||||
- script: |
|
||||
yarn mocha
|
||||
displayName: 'Test'
|
||||
- script: |
|
||||
yarn lint
|
||||
displayName: 'Lint'
|
||||
+10
-10
@@ -8,12 +8,12 @@
|
||||
/// <reference path="../typings/xterm.d.ts"/>
|
||||
|
||||
import { Terminal } from '../lib/public/Terminal';
|
||||
import * as attach from '../build/addons/attach/attach';
|
||||
import * as fit from '../build/addons/fit/fit';
|
||||
import * as fullscreen from '../build/addons/fullscreen/fullscreen';
|
||||
import * as search from '../build/addons/search/search';
|
||||
import * as webLinks from '../build/addons/webLinks/webLinks';
|
||||
import * as winptyCompat from '../build/addons/winptyCompat/winptyCompat';
|
||||
import * as attach from '../lib/addons/attach/attach';
|
||||
import * as fit from '../lib/addons/fit/fit';
|
||||
import * as fullscreen from '../lib/addons/fullscreen/fullscreen';
|
||||
import * as search from '../lib/addons/search/search';
|
||||
import * as webLinks from '../lib/addons/webLinks/webLinks';
|
||||
import * as winptyCompat from '../lib/addons/winptyCompat/winptyCompat';
|
||||
|
||||
// Pulling in the module's types relies on the <reference> above, it's looks a
|
||||
// little weird here as we're importing "this" module
|
||||
@@ -100,10 +100,10 @@ function createTerminal(): void {
|
||||
addDomListener(actionElements.findNext, 'keypress', (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
let searchOptions = {
|
||||
const searchOptions = {
|
||||
regex: (document.getElementById('regex') as HTMLInputElement).checked,
|
||||
wholeWord: false,
|
||||
caseSensitive: false
|
||||
caseSensitive: (document.getElementById('case-sensitive') as HTMLInputElement).checked
|
||||
};
|
||||
term.findNext(actionElements.findNext.value, searchOptions);
|
||||
}
|
||||
@@ -111,10 +111,10 @@ function createTerminal(): void {
|
||||
addDomListener(actionElements.findPrevious, 'keypress', (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
let searchOptions = {
|
||||
const searchOptions = {
|
||||
regex: (document.getElementById('regex') as HTMLInputElement).checked,
|
||||
wholeWord: false,
|
||||
caseSensitive: false
|
||||
caseSensitive: (document.getElementById('case-sensitive') as HTMLInputElement).checked
|
||||
};
|
||||
term.findPrevious(actionElements.findPrevious.value, searchOptions);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<label>Find next <input id="find-next"/></label>
|
||||
<label>Find previous <input id="find-previous"/></label>
|
||||
<label>Use regex<input type="checkbox" id="regex"/></label>
|
||||
<label>Case sensitive<input type="checkbox" id="case-sensitive"/></label>
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@
|
||||
"scripts": {
|
||||
"start": "node demo/start",
|
||||
"start-zmodem": "node demo/zmodem/app",
|
||||
"lint": "tslint 'src/**/*.ts'",
|
||||
"lint": "tslint 'src/**/*.ts' './demo/**/*.ts'",
|
||||
"test": "npm-run-all mocha lint",
|
||||
"test-debug": "node --inspect-brk node_modules/.bin/gulp test",
|
||||
"test-suite": "gulp mocha-suite --test",
|
||||
|
||||
@@ -100,28 +100,44 @@ export class SearchHelper implements ISearchHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches a line for a search term.
|
||||
* @param term The search term.
|
||||
* Searches a line for a search term. Takes the provided terminal line and searches the text line, which may contain
|
||||
* subsequent terminal lines if the text is wrapped. If the provided line number is part of a wrapped text line that
|
||||
* started on an earlier line then it is skipped since it will be properly searched when the terminal line that the
|
||||
* text starts on is searched.
|
||||
* @param term Tne search term.
|
||||
* @param y The line to search.
|
||||
* @param searchOptions Search options.
|
||||
* @return The search result if it was found.
|
||||
*/
|
||||
protected _findInLine(term: string, y: number, searchOptions: ISearchOptions = {}): ISearchResult {
|
||||
const lowerStringLine = this._terminal._core.buffer.translateBufferLineToString(y, true).toLowerCase();
|
||||
const lowerTerm = term.toLowerCase();
|
||||
if (this._terminal._core.buffer.lines.get(y).isWrapped) {
|
||||
return;
|
||||
}
|
||||
|
||||
const stringLine = this.translateBufferLineToStringWithWrap(y, true);
|
||||
const searchStringLine = searchOptions.caseSensitive ? stringLine : stringLine.toLowerCase();
|
||||
const searchTerm = searchOptions.caseSensitive ? term : term.toLowerCase();
|
||||
let searchIndex = -1;
|
||||
|
||||
if (searchOptions.regex) {
|
||||
const searchRegex = RegExp(lowerTerm, 'g');
|
||||
const foundTerm = searchRegex.exec(lowerStringLine);
|
||||
if (foundTerm) {
|
||||
const searchRegex = RegExp(searchTerm, 'g');
|
||||
const foundTerm = searchRegex.exec(searchStringLine);
|
||||
if (foundTerm && foundTerm[0].length > 0) {
|
||||
searchIndex = searchRegex.lastIndex - foundTerm[0].length;
|
||||
term = foundTerm[0];
|
||||
}
|
||||
} else {
|
||||
searchIndex = lowerStringLine.indexOf(lowerTerm);
|
||||
searchIndex = searchStringLine.indexOf(searchTerm);
|
||||
}
|
||||
|
||||
if (searchIndex >= 0) {
|
||||
// Adjust the row number and search index if needed since a "line" of text can span multiple rows
|
||||
if (searchIndex >= this._terminal.cols) {
|
||||
y += Math.floor(searchIndex / this._terminal.cols);
|
||||
searchIndex = searchIndex % this._terminal.cols;
|
||||
}
|
||||
const line = this._terminal._core.buffer.lines.get(y);
|
||||
|
||||
for (let i = 0; i < searchIndex; i++) {
|
||||
const charData = line.get(i);
|
||||
// Adjust the searchIndex to normalize emoji into single chars
|
||||
@@ -144,6 +160,28 @@ export class SearchHelper implements ISearchHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* function is useful for getting the actual text underneath the raw selection
|
||||
* position.
|
||||
* @param line The line being translated.
|
||||
* @param trimRight Whether to trim whitespace to the right.
|
||||
*/
|
||||
public translateBufferLineToStringWithWrap(lineIndex: number, trimRight: boolean): string {
|
||||
let lineString = '';
|
||||
let lineWrapsToNext: boolean;
|
||||
|
||||
do {
|
||||
const nextLine = this._terminal._core.buffer.lines.get(lineIndex + 1);
|
||||
lineWrapsToNext = nextLine ? nextLine.isWrapped : false;
|
||||
lineString += this._terminal._core.buffer.translateBufferLineToString(lineIndex, !lineWrapsToNext && trimRight);
|
||||
lineIndex++;
|
||||
} while (lineWrapsToNext);
|
||||
|
||||
return lineString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects and scrolls to a result.
|
||||
* @param result The result to select.
|
||||
|
||||
@@ -14,9 +14,11 @@ class MockTerminalPlain {}
|
||||
class MockTerminal {
|
||||
private _core: any;
|
||||
public searchHelper: TestSearchHelper;
|
||||
public cols: number;
|
||||
constructor(options: any) {
|
||||
this._core = new (require('../../../lib/Terminal').Terminal)(options);
|
||||
this.searchHelper = new TestSearchHelper(this as any);
|
||||
this.cols = options.cols;
|
||||
}
|
||||
get core(): any {
|
||||
return this._core;
|
||||
@@ -32,7 +34,7 @@ class TestSearchHelper extends SearchHelper {
|
||||
}
|
||||
}
|
||||
|
||||
describe('search addon', function(): void {
|
||||
describe('search addon', () => {
|
||||
describe('apply', () => {
|
||||
it('should register findNext and findPrevious', () => {
|
||||
search.apply(<any>MockTerminalPlain);
|
||||
@@ -40,45 +42,125 @@ describe('search addon', function(): void {
|
||||
assert.equal(typeof (<any>MockTerminalPlain).prototype.findPrevious, 'function');
|
||||
});
|
||||
});
|
||||
it('Searchhelper - should find correct position', function(): void {
|
||||
search.apply(<any>MockTerminal);
|
||||
const term = new MockTerminal({cols: 20, rows: 3});
|
||||
term.core.write('Hello World\r\ntest\n123....hello');
|
||||
term.pushWriteData();
|
||||
const hello0 = term.searchHelper.findInLine('Hello', 0);
|
||||
const hello1 = term.searchHelper.findInLine('Hello', 1);
|
||||
const hello2 = term.searchHelper.findInLine('Hello', 2);
|
||||
expect(hello0).eql({col: 0, row: 0, term: 'Hello'});
|
||||
expect(hello1).eql(undefined);
|
||||
expect(hello2).eql({col: 11, row: 2, term: 'Hello'});
|
||||
});
|
||||
it('should respect search regex', function(): void {
|
||||
search.apply(<any>MockTerminal);
|
||||
const term = new MockTerminal({cols: 10, rows: 4});
|
||||
term.core.write('abcdefghijklmnopqrstuvwxyz\r\n~/dev ');
|
||||
/*
|
||||
abcdefghij
|
||||
klmnopqrst
|
||||
uvwxyz
|
||||
~/dev
|
||||
*/
|
||||
term.pushWriteData();
|
||||
const searchOptions = {
|
||||
regex: true,
|
||||
wholeWord: false,
|
||||
caseSensitive: false
|
||||
};
|
||||
const hello0 = term.searchHelper.findInLine('dee*', 0, searchOptions);
|
||||
term.searchHelper.findInLine('jkk*', 0, searchOptions);
|
||||
term.searchHelper.findInLine('mnn*', 1, searchOptions);
|
||||
const tilda0 = term.searchHelper.findInLine('^~', 3, searchOptions);
|
||||
const tilda1 = term.searchHelper.findInLine('^[~]', 3, searchOptions);
|
||||
const tilda2 = term.searchHelper.findInLine('^\\~', 3, searchOptions);
|
||||
expect(hello0).eql({col: 3, row: 0, term: 'de'});
|
||||
// TODO: uncomment this test when line wrap search is checked in expect(hello1).eql({col: 9, row: 0, term: 'jk'});
|
||||
// TODO: uncomment this test when line wrap search is checked in expect(hello2).eql(undefined);
|
||||
expect(tilda0).eql({col: 0, row: 3, term: '~'});
|
||||
expect(tilda1).eql({col: 0, row: 3, term: '~'});
|
||||
expect(tilda2).eql({col: 0, row: 3, term: '~'});
|
||||
describe('find', () => {
|
||||
it('Searchhelper - should find correct position', () => {
|
||||
search.apply(<any>MockTerminal);
|
||||
const term = new MockTerminal({cols: 20, rows: 3});
|
||||
term.core.write('Hello World\r\ntest\n123....hello');
|
||||
term.pushWriteData();
|
||||
const hello0 = term.searchHelper.findInLine('Hello', 0);
|
||||
const hello1 = term.searchHelper.findInLine('Hello', 1);
|
||||
const hello2 = term.searchHelper.findInLine('Hello', 2);
|
||||
expect(hello0).eql({col: 0, row: 0, term: 'Hello'});
|
||||
expect(hello1).eql(undefined);
|
||||
expect(hello2).eql({col: 11, row: 2, term: 'Hello'});
|
||||
});
|
||||
it('should find search term accross line wrap', () => {
|
||||
search.apply(<any>MockTerminal);
|
||||
const term = new MockTerminal({cols: 10, rows: 5});
|
||||
term.core.write('texttextHellotext\r\n');
|
||||
term.core.write('texttexttextHellotext goodbye');
|
||||
term.pushWriteData();
|
||||
/*
|
||||
texttextHe
|
||||
llotext
|
||||
texttextte
|
||||
xtHellotex
|
||||
t (these spaces included intentionally)
|
||||
goodbye
|
||||
*/
|
||||
|
||||
const hello0 = (term.searchHelper as any)._findInLine('Hello', 0);
|
||||
const hello1 = (term.searchHelper as any)._findInLine('Hello', 1);
|
||||
const hello2 = (term.searchHelper as any)._findInLine('Hello', 2);
|
||||
const hello3 = (term.searchHelper as any)._findInLine('Hello', 3);
|
||||
const llo = (term.searchHelper as any)._findInLine('llo', 1);
|
||||
const goodbye = (term.searchHelper as any)._findInLine('goodbye', 2);
|
||||
expect(hello0).eql({col: 8, row: 0, term: 'Hello'});
|
||||
expect(hello1).eql(undefined);
|
||||
expect(hello2).eql({col: 2, row: 3, term: 'Hello'});
|
||||
expect(hello3).eql(undefined);
|
||||
expect(llo).eql(undefined);
|
||||
expect(goodbye).eql({col: 0, row: 5, term: 'goodbye'});
|
||||
});
|
||||
it('should respect search regex', () => {
|
||||
search.apply(<any>MockTerminal);
|
||||
const term = new MockTerminal({cols: 10, rows: 4});
|
||||
term.core.write('abcdefghijklmnopqrstuvwxyz\r\n~/dev ');
|
||||
/*
|
||||
abcdefghij
|
||||
klmnopqrst
|
||||
uvwxyz
|
||||
~/dev
|
||||
*/
|
||||
term.pushWriteData();
|
||||
const searchOptions = {
|
||||
regex: true,
|
||||
wholeWord: false,
|
||||
caseSensitive: false
|
||||
};
|
||||
const hello0 = term.searchHelper.findInLine('dee*', 0, searchOptions);
|
||||
const hello1 = term.searchHelper.findInLine('jkk*', 0, searchOptions);
|
||||
const hello2 = term.searchHelper.findInLine('mnn*', 1, searchOptions);
|
||||
const tilda0 = term.searchHelper.findInLine('^~', 3, searchOptions);
|
||||
const tilda1 = term.searchHelper.findInLine('^[~]', 3, searchOptions);
|
||||
const tilda2 = term.searchHelper.findInLine('^\\~', 3, searchOptions);
|
||||
expect(hello0).eql({col: 3, row: 0, term: 'de'});
|
||||
expect(hello1).eql({col: 9, row: 0, term: 'jk'});
|
||||
expect(hello2).eql(undefined);
|
||||
expect(tilda0).eql({col: 0, row: 3, term: '~'});
|
||||
expect(tilda1).eql({col: 0, row: 3, term: '~'});
|
||||
expect(tilda2).eql({col: 0, row: 3, term: '~'});
|
||||
});
|
||||
it('should not select empty lines', () => {
|
||||
search.apply(<any>MockTerminal);
|
||||
const term = new MockTerminal({cols: 20, rows: 3});
|
||||
term.core.write(' ');
|
||||
term.pushWriteData();
|
||||
const line = term.searchHelper.findInLine('^.*$', 0, { regex: true });
|
||||
expect(line).eql(undefined);
|
||||
});
|
||||
it('should respect case sensitive', function(): void {
|
||||
search.apply(<any>MockTerminal);
|
||||
const term = new MockTerminal({cols: 20, rows: 4});
|
||||
term.core.write('Hello World\r\n123....hello\r\nmoreTestHello');
|
||||
term.pushWriteData();
|
||||
const searchOptions = {
|
||||
regex: false,
|
||||
wholeWord: false,
|
||||
caseSensitive: true
|
||||
};
|
||||
const hello0 = (term.searchHelper as any)._findInLine('Hello', 0, searchOptions);
|
||||
const hello1 = (term.searchHelper as any)._findInLine('Hello', 1, searchOptions);
|
||||
const hello2 = (term.searchHelper as any)._findInLine('Hello', 2, searchOptions);
|
||||
expect(hello0).eql({col: 0, row: 0, term: 'Hello'});
|
||||
expect(hello1).eql(undefined);
|
||||
expect(hello2).eql({col: 8, row: 2, term: 'Hello'});
|
||||
});
|
||||
it('should respect case sensitive + regex', function(): void {
|
||||
search.apply(<any>MockTerminal);
|
||||
const term = new MockTerminal({cols: 20, rows: 4});
|
||||
term.core.write('hellohello\r\nHelloHello');
|
||||
term.pushWriteData();
|
||||
|
||||
/**
|
||||
* hellohello
|
||||
* HelloHello
|
||||
*/
|
||||
|
||||
const searchOptions = {
|
||||
regex: true,
|
||||
wholeWord: false,
|
||||
caseSensitive: true
|
||||
};
|
||||
const hello0 = (term.searchHelper as any)._findInLine('Hello', 0, searchOptions);
|
||||
const hello1 = (term.searchHelper as any)._findInLine('Hello$', 0, searchOptions);
|
||||
const hello2 = (term.searchHelper as any)._findInLine('Hello', 1, searchOptions);
|
||||
const hello3 = (term.searchHelper as any)._findInLine('Hello$', 1, searchOptions);
|
||||
expect(hello0).eql(undefined);
|
||||
expect(hello1).eql(undefined);
|
||||
expect(hello2).eql({col: 0, row: 1, term: 'Hello'});
|
||||
expect(hello3).eql({col: 5, row: 1, term: 'Hello'});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user