From 645a5920da704ab2e50fb922b8e3003c625881f9 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 27 Jun 2017 10:13:16 -0700 Subject: [PATCH 1/7] Drop selection when the active buffer changes Fixes #732 --- src/SelectionManager.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index b3316ae6..eb9e2bb5 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(); } /** From cfe22e6fd23944a4f7e1f0135d9ac2431fb810d5 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 29 Jun 2017 07:37:40 -0700 Subject: [PATCH 2/7] Use crlf when copying on Windows Fixes #737 --- src/SelectionManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index b3316ae6..1e501e93 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -233,7 +233,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; } From 16f865987dd9baf1a4790bbd9b869670048c2d9f Mon Sep 17 00:00:00 2001 From: Oleksandr Andriienko Date: Thu, 29 Jun 2017 23:36:07 +0300 Subject: [PATCH 3/7] Little code clean up. --- src/xterm.js | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/xterm.js b/src/xterm.js index a16a4ac7..c2785291 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -652,7 +652,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 +1126,7 @@ Terminal.prototype.queueLinkification = function(start, end) { this.linkifier.linkifyRow(i); } } -} +}; /** * Display the cursor element @@ -1238,25 +1237,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 +1279,7 @@ Terminal.prototype.write = function(data) { self.innerWrite(); }); } -} +}; Terminal.prototype.innerWrite = function() { var writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE); @@ -1322,7 +1321,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 +1337,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 {handler} handler The handler callback function. */ Terminal.prototype.setHypertextLinkHandler = function(handler) { if (!this.linkifier) { @@ -1365,12 +1364,12 @@ 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 * validation logic or to do something with the link's element and url. - * @param {LinkMatcherValidationCallback} callback The callback to use, this can + * @param {LinkMatcherValidationCallback} handler The callback to use, this can * be cleared with null. */ Terminal.prototype.setHypertextValidationCallback = function(handler) { @@ -1380,7 +1379,7 @@ Terminal.prototype.setHypertextValidationCallback = function(handler) { this.linkifier.setHypertextValidationCallback(handler); // 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 +1387,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 {handler} 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 +1397,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 +1409,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 +1424,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 +1947,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--; From d1712424c87434c9342adbe60bfaafc8d42a4358 Mon Sep 17 00:00:00 2001 From: Aleksandr Andriienko Date: Fri, 30 Jun 2017 09:57:24 +0300 Subject: [PATCH 4/7] Fix docs. --- src/xterm.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/xterm.js b/src/xterm.js index c2785291..743ae7c5 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -1355,7 +1355,7 @@ Terminal.prototype.attachCustomKeyEventHandler = function(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 {handler} handler The handler callback function. + * @param {LinkMatcherHandler} handler The handler callback function. */ Terminal.prototype.setHypertextLinkHandler = function(handler) { if (!this.linkifier) { @@ -1369,14 +1369,14 @@ Terminal.prototype.setHypertextLinkHandler = function(handler) { /** * Attaches a validation callback for hypertext links. This is useful to use * validation logic or to do something with the link's element and url. - * @param {LinkMatcherValidationCallback} handler The callback to use, this can + * @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); }; @@ -1387,7 +1387,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 {handler} 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. */ From 57f4ae53201da675af1bed986c86c45afcf99170 Mon Sep 17 00:00:00 2001 From: Artem Arbatskiy Date: Fri, 30 Jun 2017 18:30:02 +0700 Subject: [PATCH 5/7] Add hexlet.io to the users list --- README.md | 1 + 1 file changed, 1 insertion(+) 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. From 35d26f1d271b226d03e37faf4628e22ca6899f55 Mon Sep 17 00:00:00 2001 From: irokas Date: Sun, 2 Jul 2017 14:22:24 +0300 Subject: [PATCH 6/7] Fix issue with small scrollback value. Closes #506 --- src/xterm.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/xterm.js b/src/xterm.js index 743ae7c5..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; From 3180a6f6ec24b2ecebfb6ab013f370f2397b1742 Mon Sep 17 00:00:00 2001 From: irokas Date: Sun, 2 Jul 2017 14:34:19 +0300 Subject: [PATCH 7/7] Add test for scrollback fix --- src/test/test.js | 5 +++++ 1 file changed, 5 insertions(+) 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() {