Update xterm.js to 4.16.0

* Update xterm.js to 4.16.0 and its search addon to 0.8.2
* Improve hack for using addon despite ES6 modules support still missing
This commit is contained in:
Martchus 2022-01-23 20:43:22 +01:00
parent 1c820fc2f6
commit ea00c9ca10
9 changed files with 29 additions and 295 deletions

View File

@ -19,7 +19,7 @@ set(JAVA_SCRIPT_FILES
static/js/terminal.js
static/js/utils.js
static/node_modules/xterm/lib/xterm.js
static/node_modules/xterm-addon-search/out/SearchAddon.js)
static/node_modules/xterm-addon-search/lib/xterm-addon-search.js)
set(CSS_FILES static/css/basics.css static/css/genericrendering.css static/css/layout.css static/css/log.css
static/css/specifics.css static/node_modules/xterm/css/xterm.css)
set(IMG_FILES

View File

@ -8,16 +8,17 @@
<meta name="author" content="Martchus" />
<meta name="keywords" content="pacman, Arch Linux, build, service" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<!-- include xterm.js -->
<link rel="stylesheet" type="text/css" href="node_modules/xterm/css/xterm.css" />
<script type="text/javascript">window.exports = {} // hack for xtermjs exports as it does not support ES6 modules yet</script>
<script src="node_modules/xterm/lib/xterm.js"></script>
<script src="node_modules/xterm-addon-search/lib/xterm-addon-search.js"></script>
<!-- include custom styles and scripts -->
<link rel="stylesheet" type="text/css" href="css/basics.css" />
<link rel="stylesheet" type="text/css" href="css/layout.css" />
<link rel="stylesheet" type="text/css" href="css/genericrendering.css" />
<link rel="stylesheet" type="text/css" href="css/specifics.css" />
<script type="module" src="js/main.js"></script>
<!-- include xterm.js -->
<link rel="stylesheet" type="text/css" href="node_modules/xterm/css/xterm.css" />
<script src="node_modules/xterm/lib/xterm.js"></script>
<script src="node_modules/xterm-addon-search/out/SearchAddon.js"></script>
</head>
<body>
<header>

View File

@ -1,5 +1,9 @@
import * as AjaxHelper from './ajaxhelper.js';
// workaround xtermjs not supporting ES6 modules yet (see https://github.com/xtermjs/xterm.js/issues/2878)
const Terminal = exports.Terminal;
const SearchAddon = exports.SearchAddon.SearchAddon;
/// \brief Returns a new terminal created via xterm.js.
export function makeTerminal()
{
@ -16,11 +20,6 @@ export function makeTerminal()
export function addSearchToTerminal(terminal, targetElement)
{
const searchAddon = new SearchAddon();
// FIXME: import the search addon correctly
//import('../node_modules/xterm-addon-search/lib/xterm-addon-search.js').then(function(module) {
// const searchAddon = new module.SearchAddon();
// terminal.loadAddon(searchAddon);
//});
terminal.loadAddon(searchAddon);
const searchInput = document.createElement('input');

View File

@ -8,13 +8,15 @@
<meta name="author" content="Martchus" />
<meta name="keywords" content="pacman, Arch Linux, build, service" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<!-- include xterm.js -->
<link rel="stylesheet" type="text/css" href="node_modules/xterm/css/xterm.css" />
<script type="text/javascript">window.exports = {} // hack for xtermjs exports as it does not support ES6 modules yet</script>
<script src="node_modules/xterm/lib/xterm.js"></script>
<script src="node_modules/xterm-addon-search/lib/xterm-addon-search.js"></script>
<!-- include custom styles and scripts -->
<link rel="stylesheet" type="text/css" href="css/basics.css" />
<link rel="stylesheet" type="text/css" href="css/log.css" />
<script type="module" src="js/log.js"></script>
<!-- 3rd party libraries -->
<link rel="stylesheet" type="text/css" href="node_modules/xterm/css/xterm.css" />
<script type="application/javascript" src="node_modules/xterm/lib/xterm.js"></script>
<script type="application/javascript" src="node_modules/xterm-addon-search/out/SearchAddon.js"></script>
</head>
<body><main id="log-container"></main></body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -1,260 +0,0 @@
"use strict";
var NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\;:"\',./<>?';
var LINES_CACHE_TIME_TO_LIVE = 15 * 1000;
function SearchAddon() {
this._linesCacheTimeoutId = 0;
}
SearchAddon.prototype.activate = function (terminal) {
this._terminal = terminal;
};
SearchAddon.prototype.dispose = function () { };
SearchAddon.prototype.findNext = function (term, searchOptions) {
if (!this._terminal) {
throw new Error('Cannot use addon until it has been loaded');
}
if (!term || term.length === 0) {
this._terminal.clearSelection();
return false;
}
var startCol = 0;
var startRow = 0;
var currentSelection;
if (this._terminal.hasSelection()) {
var incremental = searchOptions ? searchOptions.incremental : false;
currentSelection = this._terminal.getSelectionPosition();
startRow = incremental ? currentSelection.startRow : currentSelection.endRow;
startCol = incremental ? currentSelection.startColumn : currentSelection.endColumn;
}
this._initLinesCache();
var searchPosition = {
startRow: startRow,
startCol: startCol
};
var result = this._findInLine(term, searchPosition, searchOptions);
if (!result) {
for (var y = startRow + 1; y < this._terminal.buffer.active.baseY + this._terminal.rows; y++) {
searchPosition.startRow = y;
searchPosition.startCol = 0;
result = this._findInLine(term, searchPosition, searchOptions);
if (result) {
break;
}
}
}
if (!result && startRow !== 0) {
for (var y = 0; y < startRow; y++) {
searchPosition.startRow = y;
searchPosition.startCol = 0;
result = this._findInLine(term, searchPosition, searchOptions);
if (result) {
break;
}
}
}
if (!result && currentSelection)
return true;
return this._selectResult(result);
};
SearchAddon.prototype.findPrevious = function (term, searchOptions) {
if (!this._terminal) {
throw new Error('Cannot use addon until it has been loaded');
}
if (!term || term.length === 0) {
this._terminal.clearSelection();
return false;
}
var isReverseSearch = true;
var startRow = this._terminal.buffer.active.baseY + this._terminal.rows;
var startCol = this._terminal.cols;
var result;
var incremental = searchOptions ? searchOptions.incremental : false;
var currentSelection;
if (this._terminal.hasSelection()) {
currentSelection = this._terminal.getSelectionPosition();
startRow = currentSelection.startRow;
startCol = currentSelection.startColumn;
}
this._initLinesCache();
var searchPosition = {
startRow: startRow,
startCol: startCol
};
if (incremental) {
result = this._findInLine(term, searchPosition, searchOptions, false);
if (!(result && result.row === startRow && result.col === startCol)) {
result = this._findInLine(term, searchPosition, searchOptions, true);
}
}
else {
result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch);
}
if (!result) {
searchPosition.startCol = Math.max(searchPosition.startCol, this._terminal.cols);
for (var y = startRow - 1; y >= 0; y--) {
searchPosition.startRow = y;
result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch);
if (result) {
break;
}
}
}
if (!result && startRow !== (this._terminal.buffer.active.baseY + this._terminal.rows)) {
for (var y = (this._terminal.buffer.active.baseY + this._terminal.rows); y > startRow; y--) {
searchPosition.startRow = y;
result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch);
if (result) {
break;
}
}
}
if (!result && currentSelection)
return true;
return this._selectResult(result);
};
SearchAddon.prototype._initLinesCache = function () {
var _this = this;
var terminal = this._terminal;
if (!this._linesCache) {
this._linesCache = new Array(terminal.buffer.active.length);
this._cursorMoveListener = terminal.onCursorMove(function () { return _this._destroyLinesCache(); });
this._resizeListener = terminal.onResize(function () { return _this._destroyLinesCache(); });
}
window.clearTimeout(this._linesCacheTimeoutId);
this._linesCacheTimeoutId = window.setTimeout(function () { return _this._destroyLinesCache(); }, LINES_CACHE_TIME_TO_LIVE);
};
SearchAddon.prototype._destroyLinesCache = function () {
this._linesCache = undefined;
if (this._cursorMoveListener) {
this._cursorMoveListener.dispose();
this._cursorMoveListener = undefined;
}
if (this._resizeListener) {
this._resizeListener.dispose();
this._resizeListener = undefined;
}
if (this._linesCacheTimeoutId) {
window.clearTimeout(this._linesCacheTimeoutId);
this._linesCacheTimeoutId = 0;
}
};
SearchAddon.prototype._isWholeWord = function (searchIndex, line, term) {
return (((searchIndex === 0) || (NON_WORD_CHARACTERS.indexOf(line[searchIndex - 1]) !== -1)) &&
(((searchIndex + term.length) === line.length) || (NON_WORD_CHARACTERS.indexOf(line[searchIndex + term.length]) !== -1)));
};
SearchAddon.prototype._findInLine = function (term, searchPosition, searchOptions, isReverseSearch) {
if (searchOptions === void 0) { searchOptions = {}; }
if (isReverseSearch === void 0) { isReverseSearch = false; }
var terminal = this._terminal;
var row = searchPosition.startRow;
var col = searchPosition.startCol;
var firstLine = terminal.buffer.active.getLine(row);
if (firstLine && firstLine.isWrapped) {
if (isReverseSearch) {
searchPosition.startCol += terminal.cols;
return;
}
searchPosition.startRow--;
searchPosition.startCol += terminal.cols;
return this._findInLine(term, searchPosition, searchOptions);
}
var stringLine = this._linesCache ? this._linesCache[row] : void 0;
if (stringLine === void 0) {
stringLine = this._translateBufferLineToStringWithWrap(row, true);
if (this._linesCache) {
this._linesCache[row] = stringLine;
}
}
var searchTerm = searchOptions.caseSensitive ? term : term.toLowerCase();
var searchStringLine = searchOptions.caseSensitive ? stringLine : stringLine.toLowerCase();
var resultIndex = -1;
if (searchOptions.regex) {
var searchRegex = RegExp(searchTerm, 'g');
var foundTerm = void 0;
if (isReverseSearch) {
while (foundTerm = searchRegex.exec(searchStringLine.slice(0, col))) {
resultIndex = searchRegex.lastIndex - foundTerm[0].length;
term = foundTerm[0];
searchRegex.lastIndex -= (term.length - 1);
}
}
else {
foundTerm = searchRegex.exec(searchStringLine.slice(col));
if (foundTerm && foundTerm[0].length > 0) {
resultIndex = col + (searchRegex.lastIndex - foundTerm[0].length);
term = foundTerm[0];
}
}
}
else {
if (isReverseSearch) {
if (col - searchTerm.length >= 0) {
resultIndex = searchStringLine.lastIndexOf(searchTerm, col - searchTerm.length);
}
}
else {
resultIndex = searchStringLine.indexOf(searchTerm, col);
}
}
if (resultIndex >= 0) {
if (resultIndex >= terminal.cols) {
row += Math.floor(resultIndex / terminal.cols);
resultIndex = resultIndex % terminal.cols;
}
if (searchOptions.wholeWord && !this._isWholeWord(resultIndex, searchStringLine, term)) {
return;
}
var line = terminal.buffer.active.getLine(row);
if (line) {
for (var i = 0; i < resultIndex; i++) {
var cell = line.getCell(i);
if (!cell) {
break;
}
var char = cell.getChars();
if (char.length > 1) {
resultIndex -= char.length - 1;
}
var charWidth = cell.getWidth();
if (charWidth === 0) {
resultIndex++;
}
}
}
return {
term: term,
col: resultIndex,
row: row
};
}
};
SearchAddon.prototype._translateBufferLineToStringWithWrap = function (lineIndex, trimRight) {
var terminal = this._terminal;
var lineString = '';
var lineWrapsToNext;
do {
var nextLine = terminal.buffer.active.getLine(lineIndex + 1);
lineWrapsToNext = nextLine ? nextLine.isWrapped : false;
var line = terminal.buffer.active.getLine(lineIndex);
if (!line) {
break;
}
lineString += line.translateToString(!lineWrapsToNext && trimRight).substring(0, terminal.cols);
lineIndex++;
} while (lineWrapsToNext);
return lineString;
};
SearchAddon.prototype._selectResult = function (result) {
var terminal = this._terminal;
if (!result) {
terminal.clearSelection();
return false;
}
terminal.select(result.col, result.row, result.term.length);
if (result.row >= (terminal.buffer.active.viewportY + terminal.rows) || result.row < terminal.buffer.active.viewportY) {
var scroll_1 = result.row - terminal.buffer.active.viewportY;
scroll_1 = scroll_1 - Math.floor(terminal.rows / 2);
terminal.scrollLines(scroll_1);
}
return true;
};

View File

@ -36,7 +36,6 @@
*/
.xterm {
font-feature-settings: "liga" 0;
position: relative;
user-select: none;
-ms-user-select: none;
@ -59,10 +58,10 @@
}
.xterm .xterm-helper-textarea {
/*
* HACK: to fix IE's blinking cursor
* Move textarea out of the screen to the far left, so that the cursor is not visible.
*/
padding: 0;
border: 0;
margin: 0;
/* Move textarea out of the screen to the far left, so that the cursor is not visible */
position: absolute;
opacity: 0;
left: -9999em;
@ -134,7 +133,8 @@
cursor: default;
}
.xterm.xterm-cursor-pointer {
.xterm.xterm-cursor-pointer,
.xterm .xterm-cursor-pointer {
cursor: pointer;
}
@ -169,3 +169,7 @@
.xterm-underline {
text-decoration: underline;
}
.xterm-strikethrough {
text-decoration: line-through;
}

File diff suppressed because one or more lines are too long

View File

@ -1,14 +0,0 @@
{
"extends": "../tsconfig-library-base",
"compilerOptions": {
"lib": [
"es2015"
],
"outDir": "../../out",
"types": [
"../../node_modules/@types/mocha"
],
"baseUrl": ".."
},
"include": [ "./**/*" ]
}