Merge branch 'master' into ctrl-alt-sequences

This commit is contained in:
Saad Malik
2018-02-08 12:03:38 -08:00
committed by GitHub
24 changed files with 3762 additions and 79 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
FROM node:6 FROM node:8
MAINTAINER Paris Kasidiaris <paris@sourcelair.com> MAINTAINER Paris Kasidiaris <paris@sourcelair.com>
# Set the working directory # Set the working directory
+1
View File
@@ -1 +1,2 @@
web: npm start web: npm start
webpack: npm run watch
+42 -9
View File
@@ -24,7 +24,7 @@ It enables applications to provide fully featured terminals to their users and c
First you need to install the module, we ship exclusively through [npm](https://www.npmjs.com/) so you need that installed and then add xterm.js as a dependency by running: First you need to install the module, we ship exclusively through [npm](https://www.npmjs.com/) so you need that installed and then add xterm.js as a dependency by running:
``` ```
npm install npm install xterm
``` ```
To start using xterm.js on your browser, add the `xterm.js` and `xterm.css` to the head of your html page. Then create a `<div id="terminal"></div>` onto which xterm can attach itself. To start using xterm.js on your browser, add the `xterm.js` and `xterm.css` to the head of your html page. Then create a `<div id="terminal"></div>` onto which xterm can attach itself.
@@ -131,27 +131,60 @@ Do you use xterm.js in your application as well? Please [open a Pull Request](ht
## Demo ## Demo
### Linux or macOS Xterm.js ships with a barebones demo implementation, designed for the development and evaluation of the library only. Exposing the demo to the public as is would introduce security risks for the host.
First, be sure that a C++ compiler such as GCC-C++ or Clang is installed, then run these commands: Below you can find instructions on how to run the demo on different platforms.
### SourceLair
SourceLair will run the demo and builder in parallel automatically. Just make sure to choose the "Node.js" project type, when cloning the xterm.js repo (or just use this shortcut; https://lair.io/xtermjs/xtermjs).
Then open your project's [Public URL](https://help.sourcelair.com/projects/the-public-url/) to access the demo.
### Docker
First, make sure you have Docker Engine 1.13.0 (or newer) and Docker Compose 1.10.0 (or newer). To run the demo and builder in parallel, run the following command in your terminal:
```
docker-compose up
```
Then open http://0.0.0.0:3000 in a web browser to access the demo. If you prefer a different port than `3000` to access the xterm.js demo, then set the `XTERMJS_PORT` environment variable to the desired port.
### Foreman (or other Procfile runner)
First, be sure that a C++ compiler such as GCC-C++ or Clang is installed, then run the following commands in your terminal:
``` ```
npm install npm install
npm start foreman start # Replace foreman with "honcho", "forego" etc. depending on your runner
``` ```
Then open http://0.0.0.0:3000 in a web browser. Then open http://0.0.0.0:3000 in a web browser to access the demo.
### Linux or macOS
First, be sure that a C++ compiler such as GCC-C++ or Clang is installed, then run the following commands in your terminal:
```
npm install
npm start # Run this in its own terminal
npm run watch # Run this in its own terminal
```
Then open http://0.0.0.0:3000 in a web browser to access the demo.
### Windows ### Windows
First, ensure [node-gyp](https://github.com/nodejs/node-gyp) is installed and configured correctly, then run these commands. First, ensure [node-gyp](https://github.com/nodejs/node-gyp) is installed and configured correctly, then run the following commands in your terminal:
``` ```
npm install npm install
npm start npm start # Run this in its own terminal
npm run watch # Run this in its own terminal
``` ```
Then open http://127.0.0.1:3000 in a web browser. Then open http://127.0.0.1:3000 in a web browser to access the demo.
*Note: Do not use ConEmu, as it seems to break the demo for some reason.* *Note: Do not use ConEmu, as it seems to break the demo for some reason.*
@@ -175,6 +208,6 @@ To contribute either code, documentation or issues to xterm.js please read the [
If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license. You are also implicitly verifying that all code is your original work. If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license. You are also implicitly verifying that all code is your original work.
Copyright (c) 2017-2018, [The xterm.js authors](https://github.com/xtermjs/xterm.js/graphs/contributors) (MIT License)
Copyright (c) 2014-2017, SourceLair, Private Company ([www.sourcelair.com](https://www.sourcelair.com/home)) (MIT License) Copyright (c) 2014-2017, SourceLair, Private Company ([www.sourcelair.com](https://www.sourcelair.com/home)) (MIT License)
Copyright (c) 2012-2013, Christopher Jeffrey (MIT License) Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
+5 -1
View File
@@ -64,10 +64,14 @@
<label for="rows">Rows</label> <label for="rows">Rows</label>
<input type="number" id="rows" /> <input type="number" id="rows" />
</div> </div>
<div style="display: inline-block; margin-right: 16px;">
<label for="padding">Padding</label>
<input type="number" id="padding" />
</div>
</div> </div>
</div> </div>
</div> </div>
<p><strong>Attention:</strong> The demo is a barebones implementation and is designed for xterm.js evaluation purposes only. Exposing the demo to the public as is would introduce security risks for the host.</p> <p><strong>Attention:</strong> The demo is a barebones implementation and is designed for the development and evaluation of xterm.js only. Exposing the demo to the public as is would introduce security risks for the host.</p>
<script src="dist/bundle.js" defer ></script> <script src="dist/bundle.js" defer ></script>
</body> </body>
</html> </html>
+11 -6
View File
@@ -33,23 +33,27 @@ var terminalContainer = document.getElementById('terminal-container'),
bellStyle: document.querySelector('#option-bell-style') bellStyle: document.querySelector('#option-bell-style')
}, },
colsElement = document.getElementById('cols'), colsElement = document.getElementById('cols'),
rowsElement = document.getElementById('rows'); rowsElement = document.getElementById('rows'),
paddingElement = document.getElementById('padding');
function setTerminalSize() { function setTerminalSize() {
var cols = parseInt(colsElement.value, 10); var cols = parseInt(colsElement.value, 10);
var rows = parseInt(rowsElement.value, 10); var rows = parseInt(rowsElement.value, 10);
var viewportElement = document.querySelector('.xterm-viewport'); var width = (cols * term.renderer.dimensions.actualCellWidth + term.viewport.scrollBarWidth).toString() + 'px';
var scrollBarWidth = viewportElement.offsetWidth - viewportElement.clientWidth;
var width = (cols * term.renderer.dimensions.actualCellWidth + 20 /*room for scrollbar*/).toString() + 'px';
var height = (rows * term.renderer.dimensions.actualCellHeight).toString() + 'px'; var height = (rows * term.renderer.dimensions.actualCellHeight).toString() + 'px';
terminalContainer.style.width = width; terminalContainer.style.width = width;
terminalContainer.style.height = height; terminalContainer.style.height = height;
term.resize(cols, rows); term.fit();
}
function setPadding() {
term.element.style.padding = parseInt(paddingElement.value, 10).toString() + 'px';
term.fit();
} }
colsElement.addEventListener('change', setTerminalSize); colsElement.addEventListener('change', setTerminalSize);
rowsElement.addEventListener('change', setTerminalSize); rowsElement.addEventListener('change', setTerminalSize);
paddingElement.addEventListener('change', setPadding);
actionElements.findNext.addEventListener('keypress', function (e) { actionElements.findNext.addEventListener('keypress', function (e) {
if (e.key === "Enter") { if (e.key === "Enter") {
@@ -119,6 +123,7 @@ function createTerminal() {
setTimeout(function () { setTimeout(function () {
colsElement.value = term.cols; colsElement.value = term.cols;
rowsElement.value = term.rows; rowsElement.value = term.rows;
paddingElement.value = 0;
// Set terminal size again to set the specific dimensions on the demo // Set terminal size again to set the specific dimensions on the demo
setTerminalSize(); setTerminalSize();
+7
View File
@@ -7,3 +7,10 @@ services:
- ./:/usr/src/app - ./:/usr/src/app
ports: ports:
- ${XTERMJS_PORT:3000}:3000 - ${XTERMJS_PORT:3000}:3000
command: ["npm", "start"]
watch:
build: .
volumes:
- ./:/usr/src/app
command: ["npm", "run", "watch"]
+2
View File
@@ -148,6 +148,7 @@ namespace methods_core {
const r24: string = t.getOption('fontWeight'); const r24: string = t.getOption('fontWeight');
const r25: string = t.getOption('fontWeightBold'); const r25: string = t.getOption('fontWeightBold');
const r26: boolean = t.getOption('allowTransparency'); const r26: boolean = t.getOption('allowTransparency');
const r27: boolean = t.getOption('rightClickSelectsWord');
} }
{ {
const t: Terminal = new Terminal(); const t: Terminal = new Terminal();
@@ -187,6 +188,7 @@ namespace methods_core {
t.setOption('fontFamily', 'foo'); t.setOption('fontFamily', 'foo');
t.setOption('theme', {background: '#ff0000'}); t.setOption('theme', {background: '#ff0000'});
t.setOption('macOptionIsMeta', true); t.setOption('macOptionIsMeta', true);
t.setOption('rightClickSelectsWord', false);
} }
} }
namespace scrolling { namespace scrolling {
+4
View File
@@ -192,6 +192,10 @@ gulp.task('webpack', ['build'], function() {
.pipe(gulp.dest('demo/dist/')); .pipe(gulp.dest('demo/dist/'));
}); });
gulp.task('watch', ['webpack'], () => {
gulp.watch(['./src/*', './src/**/*'], ['webpack']);
});
/** /**
* Submit coverage results to coveralls.io * Submit coverage results to coveralls.io
*/ */
+3522 -4
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -67,7 +67,7 @@
"nodemon": "1.10.2", "nodemon": "1.10.2",
"sorcery": "^0.10.0", "sorcery": "^0.10.0",
"tslint": "^5.9.1", "tslint": "^5.9.1",
"typescript": "~2.4.0", "typescript": "~2.7.1",
"vinyl-buffer": "^1.0.0", "vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0", "vinyl-source-stream": "^1.1.0",
"webpack": "^3.10.0", "webpack": "^3.10.0",
@@ -75,7 +75,6 @@
"zmodem.js": "^0.1.5" "zmodem.js": "^0.1.5"
}, },
"scripts": { "scripts": {
"prestart": "gulp webpack",
"start": "node demo/app", "start": "node demo/app",
"prestart-zmodem": "npm run build", "prestart-zmodem": "npm run build",
"start-zmodem": "node build/addons/zmodem/demo/app", "start-zmodem": "node build/addons/zmodem/demo/app",
@@ -86,7 +85,8 @@
"build": "gulp build", "build": "gulp build",
"prepublish": "npm run build", "prepublish": "npm run build",
"coveralls": "gulp coveralls", "coveralls": "gulp coveralls",
"webpack": "gulp webpack" "webpack": "gulp webpack",
"watch": "gulp watch"
}, },
"dependencies": {} "dependencies": {}
} }
+7
View File
@@ -150,6 +150,7 @@ export class Linkifier extends EventEmitter implements ILinkifier {
validationCallback: options.validationCallback, validationCallback: options.validationCallback,
hoverTooltipCallback: options.tooltipCallback, hoverTooltipCallback: options.tooltipCallback,
hoverLeaveCallback: options.leaveCallback, hoverLeaveCallback: options.leaveCallback,
willLinkActivate: options.willLinkActivate,
priority: options.priority || 0 priority: options.priority || 0
}; };
this._addLinkMatcherToList(matcher); this._addLinkMatcherToList(matcher);
@@ -290,6 +291,12 @@ export class Linkifier extends EventEmitter implements ILinkifier {
if (matcher.hoverLeaveCallback) { if (matcher.hoverLeaveCallback) {
matcher.hoverLeaveCallback(); matcher.hoverLeaveCallback();
} }
},
e => {
if (matcher.willLinkActivate) {
return matcher.willLinkActivate(e, uri);
}
return true;
} }
)); ));
} }
+1 -1
View File
@@ -28,7 +28,7 @@ class TestSelectionManager extends SelectionManager {
public get model(): SelectionModel { return this._model; } public get model(): SelectionModel { return this._model; }
public selectLineAt(line: number): void { this._selectLineAt(line); } public selectLineAt(line: number): void { this._selectLineAt(line); }
public selectWordAt(coords: [number, number]): void { this._selectWordAt(coords); } public selectWordAt(coords: [number, number]): void { this._selectWordAt(coords, true); }
// Disable DOM interaction // Disable DOM interaction
public enable(): void {} public enable(): void {}
+43 -7
View File
@@ -253,6 +253,37 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
this.emit('refresh', { start: this._model.finalSelectionStart, end: this._model.finalSelectionEnd }); this.emit('refresh', { start: this._model.finalSelectionStart, end: this._model.finalSelectionEnd });
} }
/**
* Checks if the current click was inside the current selection
* @param event The mouse event
*/
public isClickInSelection(event: MouseEvent): boolean {
const coords = this._getMouseBufferCoords(event);
const start = this._model.finalSelectionStart;
const end = this._model.finalSelectionEnd;
if (!start || !end) {
return false;
}
return (coords[1] > start[1] && coords[1] < end[1]) ||
(start[1] === end[1] && coords[1] === start[1] && coords[0] > start[0] && coords[0] < end[0]) ||
(start[1] < end[1] && coords[1] === end[1] && coords[0] < end[0]);
}
/**
* Selects word at the current mouse event coordinates.
* @param event The mouse event.
*/
public selectWordAtCursor(event: MouseEvent): void {
const coords = this._getMouseBufferCoords(event);
if (coords) {
this._selectWordAt(coords, false);
this._model.selectionEnd = null;
this.refresh(true);
}
}
/** /**
* Selects all text within the terminal. * Selects all text within the terminal.
*/ */
@@ -278,7 +309,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
* @param event The mouse event. * @param event The mouse event.
*/ */
private _getMouseBufferCoords(event: MouseEvent): [number, number] { private _getMouseBufferCoords(event: MouseEvent): [number, number] {
const coords = this._terminal.mouseHelper.getCoords(event, this._terminal.element, this._charMeasure, this._terminal.options.lineHeight, this._terminal.cols, this._terminal.rows, true); const coords = this._terminal.mouseHelper.getCoords(event, this._terminal.screenElement, this._charMeasure, this._terminal.options.lineHeight, this._terminal.cols, this._terminal.rows, true);
if (!coords) { if (!coords) {
return null; return null;
} }
@@ -298,7 +329,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
* @param event The mouse event. * @param event The mouse event.
*/ */
private _getMouseEventScrollAmount(event: MouseEvent): number { private _getMouseEventScrollAmount(event: MouseEvent): number {
let offset = MouseHelper.getCoordsRelativeToElement(event, this._terminal.element)[1]; let offset = MouseHelper.getCoordsRelativeToElement(event, this._terminal.screenElement)[1];
const terminalHeight = this._terminal.rows * Math.ceil(this._charMeasure.height * this._terminal.options.lineHeight); const terminalHeight = this._terminal.rows * Math.ceil(this._charMeasure.height * this._terminal.options.lineHeight);
if (offset >= 0 && offset <= terminalHeight) { if (offset >= 0 && offset <= terminalHeight) {
return 0; return 0;
@@ -445,7 +476,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
const coords = this._getMouseBufferCoords(event); const coords = this._getMouseBufferCoords(event);
if (coords) { if (coords) {
this._activeSelectionMode = SelectionMode.WORD; this._activeSelectionMode = SelectionMode.WORD;
this._selectWordAt(coords); this._selectWordAt(coords, true);
} }
} }
@@ -602,7 +633,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
* Gets positional information for the word at the coordinated specified. * Gets positional information for the word at the coordinated specified.
* @param coords The coordinates to get the word at. * @param coords The coordinates to get the word at.
*/ */
private _getWordAt(coords: [number, number]): IWordPosition { private _getWordAt(coords: [number, number], allowWhitespaceOnlySelection: boolean): IWordPosition {
const bufferLine = this._buffer.lines.get(coords[1]); const bufferLine = this._buffer.lines.get(coords[1]);
if (!bufferLine) { if (!bufferLine) {
return null; return null;
@@ -708,15 +739,20 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
- leftLongCharOffset // The number of additional chars left of the initial char added by columns with strings longer than 1 (emojis) - leftLongCharOffset // The number of additional chars left of the initial char added by columns with strings longer than 1 (emojis)
- rightLongCharOffset); // The number of additional chars right of the initial char (inclusive) added by columns with strings longer than 1 (emojis) - rightLongCharOffset); // The number of additional chars right of the initial char (inclusive) added by columns with strings longer than 1 (emojis)
if (!allowWhitespaceOnlySelection && line.slice(startIndex, endIndex).trim() === '') {
return null;
}
return { start, length }; return { start, length };
} }
/** /**
* Selects the word at the coordinates specified. * Selects the word at the coordinates specified.
* @param coords The coordinates to get the word at. * @param coords The coordinates to get the word at.
* @param allowWhitespaceOnlySelection If whitespace should be selected
*/ */
protected _selectWordAt(coords: [number, number]): void { protected _selectWordAt(coords: [number, number], allowWhitespaceOnlySelection: boolean): void {
const wordPosition = this._getWordAt(coords); const wordPosition = this._getWordAt(coords, allowWhitespaceOnlySelection);
if (wordPosition) { if (wordPosition) {
this._model.selectionStart = [wordPosition.start, coords[1]]; this._model.selectionStart = [wordPosition.start, coords[1]];
this._model.selectionStartLength = wordPosition.length; this._model.selectionStartLength = wordPosition.length;
@@ -728,7 +764,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
* @param coords The coordinates to get the word at. * @param coords The coordinates to get the word at.
*/ */
private _selectToWordAt(coords: [number, number]): void { private _selectToWordAt(coords: [number, number]): void {
const wordPosition = this._getWordAt(coords); const wordPosition = this._getWordAt(coords, true);
if (wordPosition) { if (wordPosition) {
this._model.selectionEnd = [this._model.areSelectionValuesReversed() ? wordPosition.start : (wordPosition.start + wordPosition.length), coords[1]]; this._model.selectionEnd = [this._model.areSelectionValuesReversed() ? wordPosition.start : (wordPosition.start + wordPosition.length), coords[1]];
} }
+15 -14
View File
@@ -115,7 +115,8 @@ const DEFAULT_OPTIONS: ITerminalOptions = {
useFlowControl: false, useFlowControl: false,
allowTransparency: false, allowTransparency: false,
tabStopWidth: 8, tabStopWidth: 8,
theme: null theme: null,
rightClickSelectsWord: Browser.isMac
// programFeatures: false, // programFeatures: false,
// focusKeys: false, // focusKeys: false,
}; };
@@ -123,6 +124,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = {
export class Terminal extends EventEmitter implements ITerminal, IInputHandlingTerminal { export class Terminal extends EventEmitter implements ITerminal, IInputHandlingTerminal {
public textarea: HTMLTextAreaElement; public textarea: HTMLTextAreaElement;
public element: HTMLElement; public element: HTMLElement;
public screenElement: HTMLElement;
/** /**
* The HTMLElement that the terminal is created in, set by Terminal.open. * The HTMLElement that the terminal is created in, set by Terminal.open.
@@ -534,12 +536,12 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
// Firefox doesn't appear to fire the contextmenu event on right click // Firefox doesn't appear to fire the contextmenu event on right click
on(this.element, 'mousedown', (event: MouseEvent) => { on(this.element, 'mousedown', (event: MouseEvent) => {
if (event.button === 2) { if (event.button === 2) {
rightClickHandler(event, this.textarea, this.selectionManager); rightClickHandler(event, this.textarea, this.selectionManager, this.options.rightClickSelectsWord);
} }
}); });
} else { } else {
on(this.element, 'contextmenu', (event: MouseEvent) => { on(this.element, 'contextmenu', (event: MouseEvent) => {
rightClickHandler(event, this.textarea, this.selectionManager); rightClickHandler(event, this.textarea, this.selectionManager, this.options.rightClickSelectsWord);
}); });
} }
@@ -636,15 +638,18 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
this.viewportScrollArea.classList.add('xterm-scroll-area'); this.viewportScrollArea.classList.add('xterm-scroll-area');
this.viewportElement.appendChild(this.viewportScrollArea); this.viewportElement.appendChild(this.viewportScrollArea);
this._mouseZoneManager = new MouseZoneManager(this); this.screenElement = document.createElement('div');
this.on('scroll', () => this._mouseZoneManager.clearAll()); this.screenElement.classList.add('xterm-screen');
this.linkifier.attachToDom(this._mouseZoneManager);
// Create the container that will hold helpers like the textarea for // Create the container that will hold helpers like the textarea for
// capturing DOM Events. Then produce the helpers. // capturing DOM Events. Then produce the helpers.
this.helperContainer = document.createElement('div'); this.helperContainer = document.createElement('div');
this.helperContainer.classList.add('xterm-helpers'); this.helperContainer.classList.add('xterm-helpers');
fragment.appendChild(this.helperContainer); this.screenElement.appendChild(this.helperContainer);
fragment.appendChild(this.screenElement);
this._mouseZoneManager = new MouseZoneManager(this);
this.on('scroll', () => this._mouseZoneManager.clearAll());
this.linkifier.attachToDom(this._mouseZoneManager);
this.textarea = document.createElement('textarea'); this.textarea = document.createElement('textarea');
this.textarea.classList.add('xterm-helper-textarea'); this.textarea.classList.add('xterm-helper-textarea');
@@ -762,7 +767,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
button = getButton(ev); button = getButton(ev);
// get mouse coordinates // get mouse coordinates
pos = self.mouseHelper.getRawByteCoords(ev, self.element, self.charMeasure, self.options.lineHeight, self.cols, self.rows); pos = self.mouseHelper.getRawByteCoords(ev, self.screenElement, self.charMeasure, self.options.lineHeight, self.cols, self.rows);
if (!pos) return; if (!pos) return;
sendEvent(button, pos); sendEvent(button, pos);
@@ -788,7 +793,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
// ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7< // ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
function sendMove(ev: MouseEvent): void { function sendMove(ev: MouseEvent): void {
let button = pressed; let button = pressed;
let pos = self.mouseHelper.getRawByteCoords(ev, self.element, self.charMeasure, self.options.lineHeight, self.cols, self.rows); let pos = self.mouseHelper.getRawByteCoords(ev, self.screenElement, self.charMeasure, self.options.lineHeight, self.cols, self.rows);
if (!pos) return; if (!pos) return;
// buttons marked as motions // buttons marked as motions
@@ -1631,8 +1636,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
// page up // page up
if (ev.shiftKey) { if (ev.shiftKey) {
result.scrollLines = -(this.rows - 1); result.scrollLines = -(this.rows - 1);
} else if (modifiers) {
result.key = C0.ESC + '[5;' + (modifiers + 1) + '~';
} else { } else {
result.key = C0.ESC + '[5~'; result.key = C0.ESC + '[5~';
} }
@@ -1641,8 +1644,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
// page down // page down
if (ev.shiftKey) { if (ev.shiftKey) {
result.scrollLines = this.rows - 1; result.scrollLines = this.rows - 1;
} else if (modifiers) {
result.key = C0.ESC + '[6;' + (modifiers + 1) + '~';
} else { } else {
result.key = C0.ESC + '[6~'; result.key = C0.ESC + '[6~';
} }
+13
View File
@@ -85,6 +85,7 @@ export interface IInputHandlingTerminal extends IEventEmitter {
} }
export interface IViewport { export interface IViewport {
scrollBarWidth: number;
syncScrollArea(): void; syncScrollArea(): void;
onWheel(ev: WheelEvent): void; onWheel(ev: WheelEvent): void;
onTouchStart(ev: TouchEvent): void; onTouchStart(ev: TouchEvent): void;
@@ -161,6 +162,7 @@ export interface ILinkMatcher {
matchIndex?: number; matchIndex?: number;
validationCallback?: LinkMatcherValidationCallback; validationCallback?: LinkMatcherValidationCallback;
priority?: number; priority?: number;
willLinkActivate?: (event: MouseEvent, uri: string) => boolean;
} }
export interface ICharset { export interface ICharset {
@@ -174,6 +176,7 @@ export interface ILinkHoverEvent {
} }
export interface ITerminal extends PublicTerminal, IElementAccessor, IBufferAccessor, ILinkifierAccessor { export interface ITerminal extends PublicTerminal, IElementAccessor, IBufferAccessor, ILinkifierAccessor {
screenElement: HTMLElement;
selectionManager: ISelectionManager; selectionManager: ISelectionManager;
charMeasure: ICharMeasure; charMeasure: ICharMeasure;
renderer: IRenderer; renderer: IRenderer;
@@ -187,6 +190,7 @@ export interface ITerminal extends PublicTerminal, IElementAccessor, IBufferAcce
buffers: IBufferSet; buffers: IBufferSet;
isFocused: boolean; isFocused: boolean;
mouseHelper: IMouseHelper; mouseHelper: IMouseHelper;
viewport: IViewport;
bracketedPasteMode: boolean; bracketedPasteMode: boolean;
applicationCursor: boolean; applicationCursor: boolean;
@@ -285,6 +289,8 @@ export interface ISelectionManager {
disable(): void; disable(): void;
enable(): void; enable(): void;
setSelection(row: number, col: number, length: number): void; setSelection(row: number, col: number, length: number): void;
isClickInSelection(event: MouseEvent): boolean;
selectWordAtCursor(event: MouseEvent): void;
} }
export interface ILinkifier extends IEventEmitter { export interface ILinkifier extends IEventEmitter {
@@ -321,6 +327,13 @@ export interface ILinkMatcherOptions {
* default value is 0. * default value is 0.
*/ */
priority?: number; priority?: number;
/**
* A callback that fires when the mousedown and click events occur that
* determines whether a link will be activated upon click. This enables
* only activating a link when a certain modifier is held down, if not the
* mouse event will continue propagation (eg. double click to select word).
*/
willLinkActivate?: (event: MouseEvent, uri: string) => boolean;
} }
export interface IBrowser { export interface IBrowser {
+15 -7
View File
@@ -7,11 +7,14 @@ import { IColorSet } from './renderer/Types';
import { ITerminal, IViewport } from './Types'; import { ITerminal, IViewport } from './Types';
import { CharMeasure } from './utils/CharMeasure'; import { CharMeasure } from './utils/CharMeasure';
const FALLBACK_SCROLL_BAR_WIDTH = 15;
/** /**
* Represents the viewport of a terminal, the visible area within the larger buffer of output. * Represents the viewport of a terminal, the visible area within the larger buffer of output.
* Logic for the virtual scroll bar is included in this object. * Logic for the virtual scroll bar is included in this object.
*/ */
export class Viewport implements IViewport { export class Viewport implements IViewport {
public scrollBarWidth: number = 0;
private currentRowHeight: number = 0; private currentRowHeight: number = 0;
private lastRecordedBufferLength: number = 0; private lastRecordedBufferLength: number = 0;
private lastRecordedViewportHeight: number = 0; private lastRecordedViewportHeight: number = 0;
@@ -31,6 +34,10 @@ export class Viewport implements IViewport {
private scrollArea: HTMLElement, private scrollArea: HTMLElement,
private charMeasure: CharMeasure private charMeasure: CharMeasure
) { ) {
// Measure the width of the scrollbar. If it is 0 we can assume it's an OSX overlay scrollbar.
// Unfortunately the overlay scrollbar would be hidden underneath the screen element in that case,
// therefore we account for a standard amount to make it visible
this.scrollBarWidth = (this.viewportElement.offsetWidth - this.scrollArea.offsetWidth) || FALLBACK_SCROLL_BAR_WIDTH;
this.viewportElement.addEventListener('scroll', this.onScroll.bind(this)); this.viewportElement.addEventListener('scroll', this.onScroll.bind(this));
// Perform this async to ensure the CharMeasure is ready. // Perform this async to ensure the CharMeasure is ready.
@@ -48,13 +55,8 @@ export class Viewport implements IViewport {
private refresh(): void { private refresh(): void {
if (this.charMeasure.height > 0) { if (this.charMeasure.height > 0) {
this.currentRowHeight = this.terminal.renderer.dimensions.scaledCellHeight / window.devicePixelRatio; this.currentRowHeight = this.terminal.renderer.dimensions.scaledCellHeight / window.devicePixelRatio;
this.lastRecordedViewportHeight = this.viewportElement.offsetHeight;
if (this.lastRecordedViewportHeight !== this.terminal.renderer.dimensions.canvasHeight) { const newBufferHeight = Math.round(this.currentRowHeight * this.lastRecordedBufferLength) + (this.lastRecordedViewportHeight - this.terminal.renderer.dimensions.canvasHeight);
this.lastRecordedViewportHeight = this.terminal.renderer.dimensions.canvasHeight;
this.viewportElement.style.height = this.lastRecordedViewportHeight + 'px';
}
const newBufferHeight = Math.round(this.currentRowHeight * this.lastRecordedBufferLength);
if (this.lastRecordedBufferHeight !== newBufferHeight) { if (this.lastRecordedBufferHeight !== newBufferHeight) {
this.lastRecordedBufferHeight = newBufferHeight; this.lastRecordedBufferHeight = newBufferHeight;
this.scrollArea.style.height = this.lastRecordedBufferHeight + 'px'; this.scrollArea.style.height = this.lastRecordedBufferHeight + 'px';
@@ -93,6 +95,12 @@ export class Viewport implements IViewport {
* @param ev The scroll event. * @param ev The scroll event.
*/ */
private onScroll(ev: Event): void { private onScroll(ev: Event): void {
// Don't attempt to scroll if the element is not visible, otherwise scrollTop will be corrupt
// which causes the terminal to scroll the buffer to the top
if (!this.viewportElement.offsetParent) {
return;
}
const newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight); const newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight);
const diff = newRow - this.terminal.buffer.ydisp; const diff = newRow - this.terminal.buffer.ydisp;
this.terminal.scrollLines(diff, true); this.terminal.scrollLines(diff, true);
+10 -5
View File
@@ -28,17 +28,22 @@ export function proposeGeometry(term: Terminal): IGeometry {
} }
const parentElementStyle = window.getComputedStyle(term.element.parentElement); const parentElementStyle = window.getComputedStyle(term.element.parentElement);
const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')); const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));
const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')) - 17); const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')));
const elementStyle = window.getComputedStyle(term.element); const elementStyle = window.getComputedStyle(term.element);
const elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')); const elementPadding = {
const elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left')); top: parseInt(elementStyle.getPropertyValue('padding-top')),
bottom: parseInt(elementStyle.getPropertyValue('padding-bottom')),
right: parseInt(elementStyle.getPropertyValue('padding-right')),
left: parseInt(elementStyle.getPropertyValue('padding-left'))
};
const elementPaddingVer = elementPadding.top + elementPadding.bottom;
const elementPaddingHor = elementPadding.right + elementPadding.left;
const availableHeight = parentElementHeight - elementPaddingVer; const availableHeight = parentElementHeight - elementPaddingVer;
const availableWidth = parentElementWidth - elementPaddingHor; const availableWidth = parentElementWidth - elementPaddingHor - (<any>term).viewport.scrollBarWidth;
const geometry = { const geometry = {
cols: Math.floor(availableWidth / (<any>term).renderer.dimensions.actualCellWidth), cols: Math.floor(availableWidth / (<any>term).renderer.dimensions.actualCellWidth),
rows: Math.floor(availableHeight / (<any>term).renderer.dimensions.actualCellHeight) rows: Math.floor(availableHeight / (<any>term).renderer.dimensions.actualCellHeight)
}; };
return geometry; return geometry;
} }
+6 -1
View File
@@ -116,10 +116,15 @@ export function moveTextAreaUnderMouseCursor(ev: MouseEvent, textarea: HTMLTextA
* @param ev The original right click event to be handled. * @param ev The original right click event to be handled.
* @param textarea The terminal's textarea. * @param textarea The terminal's textarea.
* @param selectionManager The terminal's selection manager. * @param selectionManager The terminal's selection manager.
* @param shouldSelectWord If true and there is no selection the current word will be selected
*/ */
export function rightClickHandler(ev: MouseEvent, textarea: HTMLTextAreaElement, selectionManager: ISelectionManager): void { export function rightClickHandler(ev: MouseEvent, textarea: HTMLTextAreaElement, selectionManager: ISelectionManager, shouldSelectWord: boolean): void {
moveTextAreaUnderMouseCursor(ev, textarea); moveTextAreaUnderMouseCursor(ev, textarea);
if (shouldSelectWord && !selectionManager.isClickInSelection(ev)) {
selectionManager.selectWordAtCursor(ev);
}
// Get textarea ready to copy from the context menu // Get textarea ready to copy from the context menu
textarea.value = selectionManager.selectionText; textarea.value = selectionManager.selectionText;
textarea.select(); textarea.select();
+9 -8
View File
@@ -151,10 +151,10 @@ export class MouseZoneManager implements IMouseZoneManager {
// components from handling the mouse event. // components from handling the mouse event.
const zone = this._findZoneEventAt(e); const zone = this._findZoneEventAt(e);
if (zone) { if (zone) {
// TODO: When link modifier support is added, the event should only be if (zone.willLinkActivate(e)) {
// cancelled when the modifier is held (see #1021) e.preventDefault();
e.preventDefault(); e.stopImmediatePropagation();
e.stopImmediatePropagation(); }
} }
} }
@@ -169,7 +169,7 @@ export class MouseZoneManager implements IMouseZoneManager {
} }
private _findZoneEventAt(e: MouseEvent): IMouseZone { private _findZoneEventAt(e: MouseEvent): IMouseZone {
const coords = this._terminal.mouseHelper.getCoords(e, this._terminal.element, this._terminal.charMeasure, this._terminal.options.lineHeight, this._terminal.cols, this._terminal.rows); const coords = this._terminal.mouseHelper.getCoords(e, this._terminal.screenElement, this._terminal.charMeasure, this._terminal.options.lineHeight, this._terminal.cols, this._terminal.rows);
if (!coords) { if (!coords) {
return null; return null;
} }
@@ -189,9 +189,10 @@ export class MouseZone implements IMouseZone {
public x2: number, public x2: number,
public y: number, public y: number,
public clickCallback: (e: MouseEvent) => any, public clickCallback: (e: MouseEvent) => any,
public hoverCallback?: (e: MouseEvent) => any, public hoverCallback: (e: MouseEvent) => any,
public tooltipCallback?: (e: MouseEvent) => any, public tooltipCallback: (e: MouseEvent) => any,
public leaveCallback?: () => void public leaveCallback: () => void,
public willLinkActivate: (e: MouseEvent) => boolean
) { ) {
} }
} }
+4 -3
View File
@@ -13,7 +13,8 @@ export interface IMouseZone {
x2: number; x2: number;
y: number; y: number;
clickCallback: (e: MouseEvent) => any; clickCallback: (e: MouseEvent) => any;
hoverCallback?: (e: MouseEvent) => any; hoverCallback: (e: MouseEvent) => any | undefined;
tooltipCallback?: (e: MouseEvent) => any; tooltipCallback: (e: MouseEvent) => any | undefined;
leaveCallback?: () => any; leaveCallback: () => any | undefined;
willLinkActivate: (e: MouseEvent) => boolean;
} }
+8 -4
View File
@@ -38,10 +38,10 @@ export class Renderer extends EventEmitter implements IRenderer {
} }
this._renderLayers = [ this._renderLayers = [
new TextRenderLayer(this._terminal.element, 0, this.colorManager.colors, this._terminal.options.allowTransparency), new TextRenderLayer(this._terminal.screenElement, 0, this.colorManager.colors, this._terminal.options.allowTransparency),
new SelectionRenderLayer(this._terminal.element, 1, this.colorManager.colors), new SelectionRenderLayer(this._terminal.screenElement, 1, this.colorManager.colors),
new LinkRenderLayer(this._terminal.element, 2, this.colorManager.colors, this._terminal), new LinkRenderLayer(this._terminal.screenElement, 2, this.colorManager.colors, this._terminal),
new CursorRenderLayer(this._terminal.element, 3, this.colorManager.colors) new CursorRenderLayer(this._terminal.screenElement, 3, this.colorManager.colors)
]; ];
this.dimensions = { this.dimensions = {
scaledCharWidth: null, scaledCharWidth: null,
@@ -120,6 +120,10 @@ export class Renderer extends EventEmitter implements IRenderer {
this._terminal.refresh(0, this._terminal.rows - 1); this._terminal.refresh(0, this._terminal.rows - 1);
} }
// Resize the screen
this._terminal.screenElement.style.width = `${this.dimensions.canvasWidth + this._terminal.viewport.scrollBarWidth}px`;
this._terminal.screenElement.style.height = `${this.dimensions.canvasHeight}px`;
this.emit('resize', { this.emit('resize', {
width: this.dimensions.canvasWidth, width: this.dimensions.canvasWidth,
height: this.dimensions.canvasHeight height: this.dimensions.canvasHeight
+3
View File
@@ -80,6 +80,7 @@ export class MockTerminal implements ITerminal {
isFocused: boolean; isFocused: boolean;
options: ITerminalOptions = {}; options: ITerminalOptions = {};
element: HTMLElement; element: HTMLElement;
screenElement: HTMLElement;
rowContainer: HTMLElement; rowContainer: HTMLElement;
selectionContainer: HTMLElement; selectionContainer: HTMLElement;
selectionManager: ISelectionManager; selectionManager: ISelectionManager;
@@ -96,6 +97,7 @@ export class MockTerminal implements ITerminal {
scrollback: number; scrollback: number;
buffers: IBufferSet; buffers: IBufferSet;
buffer: IBuffer; buffer: IBuffer;
viewport: IViewport;
applicationCursor: boolean; applicationCursor: boolean;
handler(data: string): void { handler(data: string): void {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
@@ -308,6 +310,7 @@ export class MockRenderer implements IRenderer {
} }
export class MockViewport implements IViewport { export class MockViewport implements IViewport {
scrollBarWidth: number = 0;
onThemeChanged(colors: IColorSet): void { onThemeChanged(colors: IColorSet): void {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
+10 -1
View File
@@ -96,9 +96,18 @@
background-color: #000; background-color: #000;
overflow-y: scroll; overflow-y: scroll;
cursor: default; cursor: default;
position: absolute;
right: 0;
left: 0;
top: 0;
bottom: 0;
} }
.xterm canvas { .xterm .xterm-screen {
position: relative;
}
.xterm .xterm-screen canvas {
position: absolute; position: absolute;
left: 0; left: 0;
top: 0; top: 0;
+20 -4
View File
@@ -55,6 +55,8 @@ declare module 'xterm' {
/** /**
* Whether to enable the rendering of bold text. * Whether to enable the rendering of bold text.
*
* @deprecated Use fontWeight and fontWeightBold instead.
*/ */
enableBold?: boolean; enableBold?: boolean;
@@ -93,6 +95,12 @@ declare module 'xterm' {
*/ */
macOptionIsMeta?: boolean; macOptionIsMeta?: boolean;
/**
* Whether to select the word under the cursor on right click, this is
* standard behavior in a lot of macOS applications.
*/
rightClickSelectsWord?: boolean;
/** /**
* The number of rows in the terminal. * The number of rows in the terminal.
*/ */
@@ -174,8 +182,8 @@ declare module 'xterm' {
matchIndex?: number; matchIndex?: number;
/** /**
* A callback that validates an individual link, returning true if valid and * A callback that validates whether to create an individual link, pass
* false if invalid. * whether the link is valid to the callback.
*/ */
validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void; validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void;
@@ -196,6 +204,14 @@ declare module 'xterm' {
* default value is 0. * default value is 0.
*/ */
priority?: number; priority?: number;
/**
* A callback that fires when the mousedown and click events occur that
* determines whether a link will be activated upon click. This enables
* only activating a link when a certain modifier is held down, if not the
* mouse event will continue propagation (eg. double click to select word).
*/
willLinkActivate?: (event: MouseEvent, uri: string) => boolean;
} }
export interface IEventEmitter { export interface IEventEmitter {
@@ -427,7 +443,7 @@ declare module 'xterm' {
* Retrieves an option's value from the terminal. * Retrieves an option's value from the terminal.
* @param key The option key. * @param key The option key.
*/ */
getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'macOptionIsMeta' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell'): boolean; getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell'): boolean;
/** /**
* Retrieves an option's value from the terminal. * Retrieves an option's value from the terminal.
* @param key The option key. * @param key The option key.
@@ -478,7 +494,7 @@ declare module 'xterm' {
* @param key The option key. * @param key The option key.
* @param value The option value. * @param value The option value.
*/ */
setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'macOptionIsMeta' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell', value: boolean): void; setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'macOptionIsMeta' | 'popOnBell' | 'rightClickSelectsWord' | 'screenKeys' | 'useFlowControl' | 'visualBell', value: boolean): void;
/** /**
* Sets an option on the terminal. * Sets an option on the terminal.
* @param key The option key. * @param key The option key.