diff --git a/README.md b/README.md index f5bd1c7a..e0a26f17 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Xterm.js is used in several world-class applications to provide great terminal e - [**Terminal for Atom**](https://github.com/jsmecham/atom-terminal-tab): A simple terminal for the Atom text editor. - [**Eclipse Orion**](https://orionhub.org): A modern, open source software development environment that runs in the cloud. Code, deploy and run in the cloud. - [**Gravitational Teleport**](https://github.com/gravitational/teleport): Gravitational Teleport is a modern SSH server for remotely accessing clusters of Linux servers via SSH or HTTPS. +- [**Hexlet**](https://en.hexlet.io): Practical programming courses (JavaScript, PHP, Unix, databases, functional programming). A steady path from the first line of code to the first job. Do you use xterm.js in your application as well? Please [open a Pull Request](https://github.com/sourcelair/xterm.js/pulls) to include it here. We would love to have it in our list. diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index ef8d501c..f13549b2 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -178,6 +178,7 @@ export class SelectionManager extends EventEmitter { */ public setBuffer(buffer: CircularList): void { this._buffer = buffer; + this.clearSelection(); } /** @@ -233,7 +234,7 @@ export class SelectionManager extends EventEmitter { // and joining the array into a multi-line string. const formattedResult = result.map(line => { return line.replace(ALL_NON_BREAKING_SPACE_REGEX, ' '); - }).join('\n'); + }).join(Browser.isMSWindows ? '\r\n' : '\n'); return formattedResult; } diff --git a/src/test/test.js b/src/test/test.js index cad1dfc4..5e18397a 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -55,6 +55,11 @@ describe('xterm.js', function() { it('should throw when setting a non-existant option', function() { assert.throws(xterm.setOption.bind(xterm, 'fake', true)); }); + it('should not allow scrollback less than number of rows', function() { + let setOptionCall = xterm.setOption.bind(xterm, 'scrollback', xterm.rows - 1); + + assert.equal(setOptionCall(), false); + }); }); describe('clear', function() { diff --git a/src/xterm.js b/src/xterm.js index a16a4ac7..f81085e7 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -419,6 +419,15 @@ Terminal.prototype.setOption = function(key, value) { } switch (key) { case 'scrollback': + if (value < this.rows) { + let msg = 'Setting the scrollback value less than the number of rows '; + + msg += `(${this.rows}) is not allowed.`; + + console.warn(msg); + return false; + } + if (this.options[key] !== value) { if (this.lines.length > value) { const amountToTrim = this.lines.length - value; @@ -652,7 +661,6 @@ Terminal.prototype.open = function(parent, focus) { this.element.classList.add('xterm-theme-' + this.theme); this.setCursorBlinking(this.options.cursorBlink); - this.element.style.height; this.element.setAttribute('tabindex', 0); this.viewportElement = document.createElement('div'); @@ -1127,7 +1135,7 @@ Terminal.prototype.queueLinkification = function(start, end) { this.linkifier.linkifyRow(i); } } -} +}; /** * Display the cursor element @@ -1238,25 +1246,25 @@ Terminal.prototype.scrollDisp = function(disp, suppressScrollEvent) { */ Terminal.prototype.scrollPages = function(pageCount) { this.scrollDisp(pageCount * (this.rows - 1)); -} +}; /** * Scrolls the display of the terminal to the top. */ Terminal.prototype.scrollToTop = function() { this.scrollDisp(-this.ydisp); -} +}; /** * Scrolls the display of the terminal to the bottom. */ Terminal.prototype.scrollToBottom = function() { this.scrollDisp(this.ybase - this.ydisp); -} +}; /** * Writes text to the terminal. - * @param {string} text The text to write to the terminal. + * @param {string} data The text to write to the terminal. */ Terminal.prototype.write = function(data) { this.writeBuffer.push(data); @@ -1280,7 +1288,7 @@ Terminal.prototype.write = function(data) { self.innerWrite(); }); } -} +}; Terminal.prototype.innerWrite = function() { var writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE); @@ -1322,7 +1330,7 @@ Terminal.prototype.innerWrite = function() { /** * Writes text to the terminal, followed by a break line character (\n). - * @param {string} text The text to write to the terminal. + * @param {string} data The text to write to the terminal. */ Terminal.prototype.writeln = function(data) { this.write(data + '\r\n'); @@ -1338,25 +1346,25 @@ Terminal.prototype.attachCustomKeydownHandler = function(customKeydownHandler) { let 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 * should not. - * @param {function} customKeypressHandler The custom KeyboardEvent handler to attach. This is a + * @param {function} customKeyEventHandler 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. */ Terminal.prototype.attachCustomKeyEventHandler = function(customKeyEventHandler) { this.customKeyEventHandler = customKeyEventHandler; -} +}; /** * Attaches a http(s) link handler, forcing web links to behave differently to * regular tags. This will trigger a refresh as links potentially need to be * reconstructed. Calling this with null will remove the handler. - * @param {LinkHandler} handler The handler callback function. + * @param {LinkMatcherHandler} handler The handler callback function. */ Terminal.prototype.setHypertextLinkHandler = function(handler) { if (!this.linkifier) { @@ -1365,7 +1373,7 @@ Terminal.prototype.setHypertextLinkHandler = function(handler) { this.linkifier.setHypertextLinkHandler(handler); // Refresh to force links to refresh this.refresh(0, this.rows - 1); -} +}; /** * Attaches a validation callback for hypertext links. This is useful to use @@ -1373,14 +1381,14 @@ Terminal.prototype.setHypertextLinkHandler = function(handler) { * @param {LinkMatcherValidationCallback} callback The callback to use, this can * be cleared with null. */ -Terminal.prototype.setHypertextValidationCallback = function(handler) { +Terminal.prototype.setHypertextValidationCallback = function(callback) { if (!this.linkifier) { throw new Error('Cannot attach a hypertext validation callback before Terminal.open is called'); } - this.linkifier.setHypertextValidationCallback(handler); + this.linkifier.setHypertextValidationCallback(callback); // Refresh to force links to refresh this.refresh(0, this.rows - 1); -} +}; /** * Registers a link matcher, allowing custom link patterns to be matched and @@ -1388,7 +1396,7 @@ Terminal.prototype.setHypertextValidationCallback = function(handler) { * @param {RegExp} regex The regular expression to search for, specifically * this searches the textContent of the rows. You will want to use \s to match * a space ' ' character for example. - * @param {LinkHandler} handler The callback when the link is called. + * @param {LinkMatcherHandler} handler The callback when the link is called. * @param {LinkMatcherOptions} [options] Options for the link matcher. * @return {number} The ID of the new matcher, this can be used to deregister. */ @@ -1398,7 +1406,7 @@ Terminal.prototype.registerLinkMatcher = function(regex, handler, options) { this.refresh(0, this.rows - 1); return matcherId; } -} +}; /** * Deregisters a link matcher if it has been registered. @@ -1410,14 +1418,14 @@ Terminal.prototype.deregisterLinkMatcher = function(matcherId) { this.refresh(0, this.rows - 1); } } -} +}; /** * Gets whether the terminal has an active selection. */ Terminal.prototype.hasSelection = function() { return this.selectionManager.hasSelection; -} +}; /** * Gets the terminal's current selection, this is useful for implementing copy @@ -1425,21 +1433,21 @@ Terminal.prototype.hasSelection = function() { */ Terminal.prototype.getSelection = function() { return this.selectionManager.selectionText; -} +}; /** * Clears the current terminal selection. */ Terminal.prototype.clearSelection = function() { this.selectionManager.clearSelection(); -} +}; /** * Selects all text within the terminal. */ Terminal.prototype.selectAll = function() { this.selectionManager.selectAll(); -} +}; /** * Handle a keydown event @@ -1948,7 +1956,7 @@ Terminal.prototype.resize = function(x, y) { // There is room above the buffer and there are no empty elements below the line, // scroll up this.ybase--; - addToY++ + addToY++; if (this.ydisp > 0) { // Viewport is at the top of the buffer, must increase downwards this.ydisp--;