Merge branch 'master' of github.com:sourcelair/xterm.js into content-editable
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
web: ./bin/server
|
||||||
+112
-107
@@ -7,123 +7,128 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function (attach) {
|
(function (attach) {
|
||||||
if (typeof define == 'function') {
|
if (typeof exports === 'object' && typeof module === 'object') {
|
||||||
/*
|
/*
|
||||||
* Require.js is available
|
* CommonJS environment
|
||||||
*/
|
*/
|
||||||
define(['../../src/xterm'], attach);
|
module.exports = attach(require('../../src/xterm'));
|
||||||
} else {
|
} else if (typeof define == 'function') {
|
||||||
/*
|
/*
|
||||||
* Plain browser environment
|
* Require.js is available
|
||||||
*/
|
*/
|
||||||
attach(this.Xterm);
|
define(['../../src/xterm'], attach);
|
||||||
}
|
} else {
|
||||||
|
/*
|
||||||
|
* Plain browser environment
|
||||||
|
*/
|
||||||
|
attach(this.Xterm);
|
||||||
|
}
|
||||||
})(function (Xterm) {
|
})(function (Xterm) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This module provides methods for attaching a terminal to a WebSocket
|
* This module provides methods for attaching a terminal to a WebSocket
|
||||||
* stream.
|
* stream.
|
||||||
*
|
*
|
||||||
* @module xterm/addons/attach/attach
|
* @module xterm/addons/attach/attach
|
||||||
*/
|
*/
|
||||||
var exports = {};
|
var exports = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches the given terminal to the given socket.
|
* Attaches the given terminal to the given socket.
|
||||||
*
|
*
|
||||||
* @param {Xterm} term - The terminal to be attached to the given socket.
|
* @param {Xterm} term - The terminal to be attached to the given socket.
|
||||||
* @param {WebSocket} socket - The socket to attach the current terminal.
|
* @param {WebSocket} socket - The socket to attach the current terminal.
|
||||||
* @param {boolean} bidirectional - Whether the terminal should send data
|
* @param {boolean} bidirectional - Whether the terminal should send data
|
||||||
* to the socket as well.
|
* to the socket as well.
|
||||||
* @param {boolean} buffered - Whether the rendering of incoming data
|
* @param {boolean} buffered - Whether the rendering of incoming data
|
||||||
* should happen instantly or at a maximum
|
* should happen instantly or at a maximum
|
||||||
* frequency of 1 rendering per 10ms.
|
* frequency of 1 rendering per 10ms.
|
||||||
*/
|
*/
|
||||||
exports.attach = function (term, socket, bidirectional, buffered) {
|
exports.attach = function (term, socket, bidirectional, buffered) {
|
||||||
bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
|
bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
|
||||||
term.socket = socket;
|
term.socket = socket;
|
||||||
|
|
||||||
term._flushBuffer = function () {
|
term._flushBuffer = function () {
|
||||||
term.write(term._attachSocketBuffer);
|
term.write(term._attachSocketBuffer);
|
||||||
term._attachSocketBuffer = null;
|
term._attachSocketBuffer = null;
|
||||||
clearTimeout(term._attachSocketBufferTimer);
|
clearTimeout(term._attachSocketBufferTimer);
|
||||||
term._attachSocketBufferTimer = null;
|
term._attachSocketBufferTimer = null;
|
||||||
};
|
|
||||||
|
|
||||||
term._pushToBuffer = function (data) {
|
|
||||||
if (term._attachSocketBuffer) {
|
|
||||||
term._attachSocketBuffer += data;
|
|
||||||
} else {
|
|
||||||
term._attachSocketBuffer = data;
|
|
||||||
setTimeout(term._flushBuffer, 10);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
term._getMessage = function (ev) {
|
|
||||||
if (buffered) {
|
|
||||||
term._pushToBuffer(ev.data);
|
|
||||||
} else {
|
|
||||||
term.write(ev.data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
term._sendData = function (data) {
|
|
||||||
socket.send(data);
|
|
||||||
};
|
|
||||||
|
|
||||||
socket.addEventListener('message', term._getMessage);
|
|
||||||
|
|
||||||
if (bidirectional) {
|
|
||||||
term.on('data', term._sendData);
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.addEventListener('close', term.detach.bind(term, socket));
|
|
||||||
socket.addEventListener('error', term.detach.bind(term, socket));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
term._pushToBuffer = function (data) {
|
||||||
* Detaches the given terminal from the given socket
|
if (term._attachSocketBuffer) {
|
||||||
*
|
term._attachSocketBuffer += data;
|
||||||
* @param {Xterm} term - The terminal to be detached from the given socket.
|
} else {
|
||||||
* @param {WebSocket} socket - The socket from which to detach the current
|
term._attachSocketBuffer = data;
|
||||||
* terminal.
|
setTimeout(term._flushBuffer, 10);
|
||||||
*/
|
}
|
||||||
exports.detach = function (term, socket) {
|
|
||||||
term.off('data', term._sendData);
|
|
||||||
|
|
||||||
socket = (typeof socket == 'undefined') ? term.socket : socket;
|
|
||||||
|
|
||||||
if (socket) {
|
|
||||||
socket.removeEventListener('message', term._getMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete term.socket;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
term._getMessage = function (ev) {
|
||||||
* Attaches the current terminal to the given socket
|
if (buffered) {
|
||||||
*
|
term._pushToBuffer(ev.data);
|
||||||
* @param {WebSocket} socket - The socket to attach the current terminal.
|
} else {
|
||||||
* @param {boolean} bidirectional - Whether the terminal should send data
|
term.write(ev.data);
|
||||||
* to the socket as well.
|
}
|
||||||
* @param {boolean} buffered - Whether the rendering of incoming data
|
|
||||||
* should happen instantly or at a maximum
|
|
||||||
* frequency of 1 rendering per 10ms.
|
|
||||||
*/
|
|
||||||
Xterm.prototype.attach = function (socket, bidirectional, buffered) {
|
|
||||||
return exports.attach(this, socket, bidirectional, buffered);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
term._sendData = function (data) {
|
||||||
* Detaches the current terminal from the given socket.
|
socket.send(data);
|
||||||
*
|
|
||||||
* @param {WebSocket} socket - The socket from which to detach the current
|
|
||||||
* terminal.
|
|
||||||
*/
|
|
||||||
Xterm.prototype.detach = function (socket) {
|
|
||||||
return exports.detach(this, socket);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return exports;
|
socket.addEventListener('message', term._getMessage);
|
||||||
|
|
||||||
|
if (bidirectional) {
|
||||||
|
term.on('data', term._sendData);
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.addEventListener('close', term.detach.bind(term, socket));
|
||||||
|
socket.addEventListener('error', term.detach.bind(term, socket));
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detaches the given terminal from the given socket
|
||||||
|
*
|
||||||
|
* @param {Xterm} term - The terminal to be detached from the given socket.
|
||||||
|
* @param {WebSocket} socket - The socket from which to detach the current
|
||||||
|
* terminal.
|
||||||
|
*/
|
||||||
|
exports.detach = function (term, socket) {
|
||||||
|
term.off('data', term._sendData);
|
||||||
|
|
||||||
|
socket = (typeof socket == 'undefined') ? term.socket : socket;
|
||||||
|
|
||||||
|
if (socket) {
|
||||||
|
socket.removeEventListener('message', term._getMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete term.socket;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attaches the current terminal to the given socket
|
||||||
|
*
|
||||||
|
* @param {WebSocket} socket - The socket to attach the current terminal.
|
||||||
|
* @param {boolean} bidirectional - Whether the terminal should send data
|
||||||
|
* to the socket as well.
|
||||||
|
* @param {boolean} buffered - Whether the rendering of incoming data
|
||||||
|
* should happen instantly or at a maximum
|
||||||
|
* frequency of 1 rendering per 10ms.
|
||||||
|
*/
|
||||||
|
Xterm.prototype.attach = function (socket, bidirectional, buffered) {
|
||||||
|
return exports.attach(this, socket, bidirectional, buffered);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detaches the current terminal from the given socket.
|
||||||
|
*
|
||||||
|
* @param {WebSocket} socket - The socket from which to detach the current
|
||||||
|
* terminal.
|
||||||
|
*/
|
||||||
|
Xterm.prototype.detach = function (socket) {
|
||||||
|
return exports.detach(this, socket);
|
||||||
|
};
|
||||||
|
|
||||||
|
return exports;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "xterm.attach",
|
||||||
|
"main": "attach.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
+65
-43
@@ -12,53 +12,75 @@
|
|||||||
* of columns)
|
* of columns)
|
||||||
*/
|
*/
|
||||||
(function (fit) {
|
(function (fit) {
|
||||||
if (typeof define == 'function') {
|
if (typeof exports === 'object' && typeof module === 'object') {
|
||||||
/*
|
/*
|
||||||
* Require.js is available
|
* CommonJS environment
|
||||||
*/
|
*/
|
||||||
define(['../../src/xterm'], fit);
|
module.exports = fit(require('../../src/xterm'));
|
||||||
} else {
|
} else if (typeof define == 'function') {
|
||||||
/*
|
/*
|
||||||
* Plain browser environment
|
* Require.js is available
|
||||||
*/
|
*/
|
||||||
fit(this.Xterm);
|
define(['../../src/xterm'], fit);
|
||||||
}
|
} else {
|
||||||
|
/*
|
||||||
|
* Plain browser environment
|
||||||
|
*/
|
||||||
|
fit(this.Xterm);
|
||||||
|
}
|
||||||
})(function (Xterm) {
|
})(function (Xterm) {
|
||||||
Xterm.prototype.proposeGeometry = function () {
|
/**
|
||||||
var parentElementStyle = window.getComputedStyle(this.element.parentElement),
|
* This module provides methods for fitting a terminal's size to a parent container.
|
||||||
parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')),
|
*
|
||||||
parentElementWidth = parseInt(parentElementStyle.getPropertyValue('width')),
|
* @module xterm/addons/fit/fit
|
||||||
elementStyle = window.getComputedStyle(this.element),
|
*/
|
||||||
elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')),
|
var exports = {};
|
||||||
elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left')),
|
|
||||||
availableHeight = parentElementHeight - elementPaddingVer,
|
|
||||||
availableWidth = parentElementWidth - elementPaddingHor,
|
|
||||||
container = this.rowContainer,
|
|
||||||
subjectRow = this.rowContainer.firstElementChild,
|
|
||||||
contentBuffer = subjectRow.innerHTML,
|
|
||||||
characterHeight,
|
|
||||||
rows,
|
|
||||||
characterWidth,
|
|
||||||
cols,
|
|
||||||
geometry;
|
|
||||||
|
|
||||||
subjectRow.style.display = 'inline';
|
exports.proposeGeometry = function (term) {
|
||||||
subjectRow.innerHTML = 'W'; // Common character for measuring width, although on monospace
|
var parentElementStyle = window.getComputedStyle(term.element.parentElement),
|
||||||
characterWidth = subjectRow.getBoundingClientRect().width;
|
parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')),
|
||||||
subjectRow.style.display = ''; // Revert style before calculating height, since they differ.
|
parentElementWidth = parseInt(parentElementStyle.getPropertyValue('width')),
|
||||||
characterHeight = parseInt(subjectRow.offsetHeight);
|
elementStyle = window.getComputedStyle(term.element),
|
||||||
subjectRow.innerHTML = contentBuffer;
|
elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')),
|
||||||
|
elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left')),
|
||||||
|
availableHeight = parentElementHeight - elementPaddingVer,
|
||||||
|
availableWidth = parentElementWidth - elementPaddingHor,
|
||||||
|
container = term.rowContainer,
|
||||||
|
subjectRow = term.rowContainer.firstElementChild,
|
||||||
|
contentBuffer = subjectRow.innerHTML,
|
||||||
|
characterHeight,
|
||||||
|
rows,
|
||||||
|
characterWidth,
|
||||||
|
cols,
|
||||||
|
geometry;
|
||||||
|
|
||||||
rows = parseInt(availableHeight / characterHeight);
|
subjectRow.style.display = 'inline';
|
||||||
cols = parseInt(availableWidth / characterWidth) - 1;
|
subjectRow.innerHTML = 'W'; // Common character for measuring width, although on monospace
|
||||||
|
characterWidth = subjectRow.getBoundingClientRect().width;
|
||||||
|
subjectRow.style.display = ''; // Revert style before calculating height, since they differ.
|
||||||
|
characterHeight = parseInt(subjectRow.offsetHeight);
|
||||||
|
subjectRow.innerHTML = contentBuffer;
|
||||||
|
|
||||||
geometry = {cols: cols, rows: rows};
|
rows = parseInt(availableHeight / characterHeight);
|
||||||
return geometry;
|
cols = parseInt(availableWidth / characterWidth) - 1;
|
||||||
};
|
|
||||||
|
|
||||||
Xterm.prototype.fit = function () {
|
geometry = {cols: cols, rows: rows};
|
||||||
var geometry = this.proposeGeometry();
|
return geometry;
|
||||||
|
};
|
||||||
|
|
||||||
this.resize(geometry.cols, geometry.rows);
|
exports.fit = function (term) {
|
||||||
};
|
var geometry = exports.proposeGeometry(term);
|
||||||
|
|
||||||
|
term.resize(geometry.cols, geometry.rows);
|
||||||
|
};
|
||||||
|
|
||||||
|
Xterm.prototype.proposeGeometry = function () {
|
||||||
|
return exports.proposeGeometry(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
Xterm.prototype.fit = function () {
|
||||||
|
return exports.fit(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
return exports;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "xterm.fit",
|
||||||
|
"main": "fit.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -11,29 +11,42 @@
|
|||||||
* fullscreen mode is being toggled.
|
* fullscreen mode is being toggled.
|
||||||
*/
|
*/
|
||||||
(function (fullscreen) {
|
(function (fullscreen) {
|
||||||
if (typeof define == 'function') {
|
if (typeof exports === 'object' && typeof module === 'object') {
|
||||||
/*
|
/*
|
||||||
* Require.js is available
|
* CommonJS environment
|
||||||
*/
|
*/
|
||||||
define(['../../src/xterm'], fullscreen);
|
module.exports = fullscreen(require('../../src/xterm'));
|
||||||
} else {
|
} else if (typeof define == 'function') {
|
||||||
/*
|
/*
|
||||||
* Plain browser environment
|
* Require.js is available
|
||||||
*/
|
*/
|
||||||
fullscreen(this.Xterm);
|
define(['../../src/xterm'], fullscreen);
|
||||||
}
|
} else {
|
||||||
|
/*
|
||||||
|
* Plain browser environment
|
||||||
|
*/
|
||||||
|
fullscreen(this.Xterm);
|
||||||
|
}
|
||||||
})(function (Xterm) {
|
})(function (Xterm) {
|
||||||
Xterm.prototype.toggleFullscreen = function (fullscreen) {
|
var exports = {};
|
||||||
var fn;
|
|
||||||
|
|
||||||
if (typeof fullscreen == 'undefined') {
|
exports.toggleFullScreen = function (term, fullscreen) {
|
||||||
fn = (this.element.classList.contains('fullscreen')) ? 'remove' : 'add';
|
var fn;
|
||||||
} else if (!fullscreen) {
|
|
||||||
fn = 'remove';
|
|
||||||
} else {
|
|
||||||
fn = 'add';
|
|
||||||
}
|
|
||||||
|
|
||||||
this.element.classList[fn]('fullscreen');
|
if (typeof fullscreen == 'undefined') {
|
||||||
};
|
fn = (term.element.classList.contains('fullscreen')) ? 'remove' : 'add';
|
||||||
});
|
} else if (!fullscreen) {
|
||||||
|
fn = 'remove';
|
||||||
|
} else {
|
||||||
|
fn = 'add';
|
||||||
|
}
|
||||||
|
|
||||||
|
term.element.classList[fn]('fullscreen');
|
||||||
|
};
|
||||||
|
|
||||||
|
Xterm.prototype.toggleFullscreen = function (fullscreen) {
|
||||||
|
exports.toggleFullScreen(this, fullscreen);
|
||||||
|
};
|
||||||
|
|
||||||
|
return exports;
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "xterm.fullscreen",
|
||||||
|
"main": "fullscreen.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
+176
-171
@@ -1,182 +1,187 @@
|
|||||||
(function (linkify) {
|
(function (linkify) {
|
||||||
if (typeof define == 'function') {
|
if (typeof exports === 'object' && typeof module === 'object') {
|
||||||
/*
|
|
||||||
* Require.js is available
|
|
||||||
*/
|
|
||||||
define(['../../src/xterm'], linkify);
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* Plain browser environment
|
|
||||||
*/
|
|
||||||
linkify(this.Xterm);
|
|
||||||
}
|
|
||||||
})(function (Xterm) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This module provides methods for convertings valid URL substrings
|
|
||||||
* into HTML anchor elements (links), inside a terminal view.
|
|
||||||
*
|
|
||||||
* @module xterm/addons/linkify/linkify
|
|
||||||
*/
|
|
||||||
var exports = {},
|
|
||||||
protocolClause = '(https?:\\/\\/)',
|
|
||||||
domainCharacterSet = '[\\da-z\\.-]+',
|
|
||||||
negatedDomainCharacterSet = '[^\\da-z\\.-]+',
|
|
||||||
domainBodyClause = '(' + domainCharacterSet + ')',
|
|
||||||
tldClause = '([a-z\\.]{2,6})',
|
|
||||||
hostClause = domainBodyClause + '\\.' + tldClause,
|
|
||||||
pathClause = '([\\/\\w\\.-]*)*\\/?',
|
|
||||||
negatedPathCharacterSet = '[^\\/\\w\\.-]+',
|
|
||||||
bodyClause = hostClause + pathClause,
|
|
||||||
start = '(?:^|' + negatedDomainCharacterSet + ')(',
|
|
||||||
end = ')($|' + negatedPathCharacterSet + ')',
|
|
||||||
lenientUrlClause = start + protocolClause + '?' + bodyClause + end,
|
|
||||||
strictUrlClause = start + protocolClause + bodyClause + end,
|
|
||||||
lenientUrlRegex = new RegExp(lenientUrlClause),
|
|
||||||
strictUrlRegex = new RegExp(strictUrlClause);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts all valid URLs found in the given terminal line into
|
|
||||||
* hyperlinks. The terminal line can be either the HTML element itself
|
|
||||||
* or the index of the termina line in the children of the terminal
|
|
||||||
* rows container.
|
|
||||||
*
|
|
||||||
* @param {Xterm} terminal - The terminal that owns the given line.
|
|
||||||
* @param {number|HTMLDivElement} line - The terminal line that should get
|
|
||||||
* "linkified".
|
|
||||||
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
|
||||||
* false, the regex requires a protocol clause. Defaults to true.
|
|
||||||
* @emits linkify
|
|
||||||
* @emits linkify:line
|
|
||||||
*/
|
|
||||||
exports.linkifyTerminalLine = function (terminal, line, lenient) {
|
|
||||||
if (typeof line == 'number') {
|
|
||||||
line = terminal.rowContainer.children[line];
|
|
||||||
} else if (! (line instanceof HTMLDivElement)) {
|
|
||||||
var message = 'The "line" argument should be either a number';
|
|
||||||
message += ' or an HTMLDivElement';
|
|
||||||
|
|
||||||
throw new TypeError(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
var buffer = document.createElement('span'),
|
|
||||||
nodes = line.childNodes;
|
|
||||||
|
|
||||||
for (var j=0; j<nodes.length; j++) {
|
|
||||||
var node = nodes[j],
|
|
||||||
match;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Since we cannot access the TextNode's HTML representation
|
|
||||||
* from the instance itself, we assign its data as textContent
|
|
||||||
* to a dummy buffer span, in order to retrieve the TextNode's
|
|
||||||
* HTML representation from the buffer's innerHTML.
|
|
||||||
*/
|
|
||||||
buffer.textContent = node.data;
|
|
||||||
|
|
||||||
var nodeHTML = buffer.innerHTML;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Apply function only on TextNodes
|
|
||||||
*/
|
|
||||||
if (node.nodeType != node.TEXT_NODE) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (lenient) {
|
|
||||||
match = node.data.match(lenientUrlRegex);
|
|
||||||
} else {
|
|
||||||
match = node.data.match(strictUrlRegex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If no URL was found in the current text, return.
|
|
||||||
*/
|
|
||||||
if (!match) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var url = match[1],
|
|
||||||
startsWithProtocol = new RegExp('^' + protocolClause),
|
|
||||||
urlHasProtocol = url.match(startsWithProtocol),
|
|
||||||
href = (urlHasProtocol) ? url : 'http://' + url,
|
|
||||||
link = '<a href="' + href + '" >' + url + '</a>',
|
|
||||||
newHTML = nodeHTML.replace(url, link);
|
|
||||||
|
|
||||||
line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event gets emitted when conversion of all URL susbtrings
|
|
||||||
* to HTML anchor elements (links) has finished, for a specific
|
|
||||||
* line of the current Xterm instance.
|
|
||||||
*
|
|
||||||
* @event linkify:line
|
|
||||||
*/
|
|
||||||
terminal.emit('linkify:line', line);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts all valid URLs found in the terminal view into hyperlinks.
|
|
||||||
*
|
|
||||||
* @param {Xterm} terminal - The terminal that should get "linkified".
|
|
||||||
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
|
||||||
* false, the regex requires a protocol clause. Defaults to true.
|
|
||||||
* @emits linkify
|
|
||||||
* @emits linkify:line
|
|
||||||
*/
|
|
||||||
exports.linkify = function (terminal, lenient) {
|
|
||||||
var rows = terminal.rowContainer.children;
|
|
||||||
|
|
||||||
lenient = (typeof lenient == "boolean") ? lenient : true;
|
|
||||||
for (var i=0; i<rows.length; i++) {
|
|
||||||
var line = rows[i];
|
|
||||||
|
|
||||||
exports.linkifyTerminalLine(terminal, line, lenient);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event gets emitted when conversion of all URL substrings to
|
|
||||||
* HTML anchor elements (links) has finished for the current Xterm
|
|
||||||
* instance's view.
|
|
||||||
*
|
|
||||||
* @event linkify
|
|
||||||
*/
|
|
||||||
terminal.emit('linkify');
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Extend Xterm prototype.
|
* CommonJS environment
|
||||||
*/
|
*/
|
||||||
|
module.exports = linkify(require('../../src/xterm'));
|
||||||
|
} else if (typeof define == 'function') {
|
||||||
|
/*
|
||||||
|
* Require.js is available
|
||||||
|
*/
|
||||||
|
define(['../../src/xterm'], linkify);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Plain browser environment
|
||||||
|
*/
|
||||||
|
linkify(this.Xterm);
|
||||||
|
}
|
||||||
|
})(function (Xterm) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts all valid URLs found in the current terminal linte into
|
* This module provides methods for convertings valid URL substrings
|
||||||
* hyperlinks.
|
* into HTML anchor elements (links), inside a terminal view.
|
||||||
|
*
|
||||||
|
* @module xterm/addons/linkify/linkify
|
||||||
|
*/
|
||||||
|
var exports = {},
|
||||||
|
protocolClause = '(https?:\\/\\/)',
|
||||||
|
domainCharacterSet = '[\\da-z\\.-]+',
|
||||||
|
negatedDomainCharacterSet = '[^\\da-z\\.-]+',
|
||||||
|
domainBodyClause = '(' + domainCharacterSet + ')',
|
||||||
|
tldClause = '([a-z\\.]{2,6})',
|
||||||
|
hostClause = domainBodyClause + '\\.' + tldClause,
|
||||||
|
pathClause = '([\\/\\w\\.-]*)*\\/?',
|
||||||
|
negatedPathCharacterSet = '[^\\/\\w\\.-]+',
|
||||||
|
bodyClause = hostClause + pathClause,
|
||||||
|
start = '(?:^|' + negatedDomainCharacterSet + ')(',
|
||||||
|
end = ')($|' + negatedPathCharacterSet + ')',
|
||||||
|
lenientUrlClause = start + protocolClause + '?' + bodyClause + end,
|
||||||
|
strictUrlClause = start + protocolClause + bodyClause + end,
|
||||||
|
lenientUrlRegex = new RegExp(lenientUrlClause),
|
||||||
|
strictUrlRegex = new RegExp(strictUrlClause);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts all valid URLs found in the given terminal line into
|
||||||
|
* hyperlinks. The terminal line can be either the HTML element itself
|
||||||
|
* or the index of the termina line in the children of the terminal
|
||||||
|
* rows container.
|
||||||
|
*
|
||||||
|
* @param {Xterm} terminal - The terminal that owns the given line.
|
||||||
|
* @param {number|HTMLDivElement} line - The terminal line that should get
|
||||||
|
* "linkified".
|
||||||
|
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
||||||
|
* false, the regex requires a protocol clause. Defaults to true.
|
||||||
|
* @emits linkify
|
||||||
|
* @emits linkify:line
|
||||||
|
*/
|
||||||
|
exports.linkifyTerminalLine = function (terminal, line, lenient) {
|
||||||
|
if (typeof line == 'number') {
|
||||||
|
line = terminal.rowContainer.children[line];
|
||||||
|
} else if (! (line instanceof HTMLDivElement)) {
|
||||||
|
var message = 'The "line" argument should be either a number';
|
||||||
|
message += ' or an HTMLDivElement';
|
||||||
|
|
||||||
|
throw new TypeError(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
var buffer = document.createElement('span'),
|
||||||
|
nodes = line.childNodes;
|
||||||
|
|
||||||
|
for (var j=0; j<nodes.length; j++) {
|
||||||
|
var node = nodes[j],
|
||||||
|
match;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since we cannot access the TextNode's HTML representation
|
||||||
|
* from the instance itself, we assign its data as textContent
|
||||||
|
* to a dummy buffer span, in order to retrieve the TextNode's
|
||||||
|
* HTML representation from the buffer's innerHTML.
|
||||||
|
*/
|
||||||
|
buffer.textContent = node.data;
|
||||||
|
|
||||||
|
var nodeHTML = buffer.innerHTML;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply function only on TextNodes
|
||||||
|
*/
|
||||||
|
if (node.nodeType != node.TEXT_NODE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (lenient) {
|
||||||
|
match = node.data.match(lenientUrlRegex);
|
||||||
|
} else {
|
||||||
|
match = node.data.match(strictUrlRegex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If no URL was found in the current text, return.
|
||||||
|
*/
|
||||||
|
if (!match) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var url = match[1],
|
||||||
|
startsWithProtocol = new RegExp('^' + protocolClause),
|
||||||
|
urlHasProtocol = url.match(startsWithProtocol),
|
||||||
|
href = (urlHasProtocol) ? url : 'http://' + url,
|
||||||
|
link = '<a href="' + href + '" >' + url + '</a>',
|
||||||
|
newHTML = nodeHTML.replace(url, link);
|
||||||
|
|
||||||
|
line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event gets emitted when conversion of all URL susbtrings
|
||||||
|
* to HTML anchor elements (links) has finished, for a specific
|
||||||
|
* line of the current Xterm instance.
|
||||||
*
|
*
|
||||||
* @memberof Xterm
|
* @event linkify:line
|
||||||
* @param {number|HTMLDivElement} line - The terminal line that should get
|
|
||||||
* "linkified".
|
|
||||||
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
|
||||||
* false, the regex requires a protocol clause. Defaults to true.
|
|
||||||
*/
|
*/
|
||||||
Xterm.prototype.linkifyTerminalLine = function (line, lenient) {
|
terminal.emit('linkify:line', line);
|
||||||
return exports.linkifyTerminalLine(this, line, lenient);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts all valid URLs found in the current terminal into hyperlinks.
|
/**
|
||||||
|
* Converts all valid URLs found in the terminal view into hyperlinks.
|
||||||
|
*
|
||||||
|
* @param {Xterm} terminal - The terminal that should get "linkified".
|
||||||
|
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
||||||
|
* false, the regex requires a protocol clause. Defaults to true.
|
||||||
|
* @emits linkify
|
||||||
|
* @emits linkify:line
|
||||||
|
*/
|
||||||
|
exports.linkify = function (terminal, lenient) {
|
||||||
|
var rows = terminal.rowContainer.children;
|
||||||
|
|
||||||
|
lenient = (typeof lenient == "boolean") ? lenient : true;
|
||||||
|
for (var i=0; i<rows.length; i++) {
|
||||||
|
var line = rows[i];
|
||||||
|
|
||||||
|
exports.linkifyTerminalLine(terminal, line, lenient);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event gets emitted when conversion of all URL substrings to
|
||||||
|
* HTML anchor elements (links) has finished for the current Xterm
|
||||||
|
* instance's view.
|
||||||
*
|
*
|
||||||
* @memberof Xterm
|
* @event linkify
|
||||||
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
|
||||||
* false, the regex requires a protocol clause. Defaults to true.
|
|
||||||
*/
|
*/
|
||||||
Xterm.prototype.linkify = function (lenient) {
|
terminal.emit('linkify');
|
||||||
return exports.linkify(this, lenient);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
return exports;
|
/**
|
||||||
|
* Extend Xterm prototype.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts all valid URLs found in the current terminal linte into
|
||||||
|
* hyperlinks.
|
||||||
|
*
|
||||||
|
* @memberof Xterm
|
||||||
|
* @param {number|HTMLDivElement} line - The terminal line that should get
|
||||||
|
* "linkified".
|
||||||
|
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
||||||
|
* false, the regex requires a protocol clause. Defaults to true.
|
||||||
|
*/
|
||||||
|
Xterm.prototype.linkifyTerminalLine = function (line, lenient) {
|
||||||
|
return exports.linkifyTerminalLine(this, line, lenient);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts all valid URLs found in the current terminal into hyperlinks.
|
||||||
|
*
|
||||||
|
* @memberof Xterm
|
||||||
|
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
||||||
|
* false, the regex requires a protocol clause. Defaults to true.
|
||||||
|
*/
|
||||||
|
Xterm.prototype.linkify = function (lenient) {
|
||||||
|
return exports.linkify(this, lenient);
|
||||||
|
};
|
||||||
|
|
||||||
|
return exports;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "xterm.linkify",
|
||||||
|
"main": "linkify.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
Executable
+4
@@ -0,0 +1,4 @@
|
|||||||
|
#! /usr/bin/env sh
|
||||||
|
|
||||||
|
# Development server for xterm.js
|
||||||
|
browser-sync start --server --port 8000 --files="**" --no-ui --index index.html --directory
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "xterm.js",
|
"name": "xterm.js",
|
||||||
"version": "0.32",
|
"version": "0.33",
|
||||||
"ignore": ["demo", "test", ".gitignore"]
|
"ignore": ["demo", "test", ".gitignore"]
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xterm",
|
"name": "xterm",
|
||||||
"version": "0.32.0",
|
"version": "0.33.0",
|
||||||
"ignore": ["demo", "test", ".gitignore"],
|
"ignore": ["demo", "test", ".gitignore"],
|
||||||
"main": "src/xterm.js",
|
"main": "src/xterm.js",
|
||||||
"repository": "https://github.com/sourcelair/xterm.js",
|
"repository": "https://github.com/sourcelair/xterm.js",
|
||||||
|
|||||||
@@ -2134,3 +2134,19 @@
|
|||||||
.terminal .xterm-bg-color-255 {
|
.terminal .xterm-bg-color-255 {
|
||||||
background-color: #eeeeee;
|
background-color: #eeeeee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All terminal rows should have explicitly declared height,
|
||||||
|
* in order to allow child elements to adjust.
|
||||||
|
*/
|
||||||
|
.terminal .xterm-rows > div {
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All styled spans inside terminal lines should be inline-blocks,
|
||||||
|
* in orde to achieve better height adjustment.
|
||||||
|
*/
|
||||||
|
.terminal .xterm-rows span {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|||||||
+53
-21
@@ -32,7 +32,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function (xterm) {
|
(function (xterm) {
|
||||||
if (typeof define == 'function') {
|
if (typeof exports === 'object' && typeof module === 'object') {
|
||||||
|
/*
|
||||||
|
* CommonJS environment
|
||||||
|
*/
|
||||||
|
module.exports = xterm.call(this);
|
||||||
|
} else if (typeof define == 'function') {
|
||||||
/*
|
/*
|
||||||
* Require.js is available
|
* Require.js is available
|
||||||
*/
|
*/
|
||||||
@@ -375,6 +380,8 @@
|
|||||||
|
|
||||||
Terminal.options = {};
|
Terminal.options = {};
|
||||||
|
|
||||||
|
Terminal.focus = null;
|
||||||
|
|
||||||
each(keys(Terminal.defaults), function(key) {
|
each(keys(Terminal.defaults), function(key) {
|
||||||
Terminal[key] = Terminal.defaults[key];
|
Terminal[key] = Terminal.defaults[key];
|
||||||
Terminal.options[key] = Terminal.defaults[key];
|
Terminal.options[key] = Terminal.defaults[key];
|
||||||
@@ -394,7 +401,6 @@
|
|||||||
|
|
||||||
this.showCursor();
|
this.showCursor();
|
||||||
this.element.focus();
|
this.element.focus();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Terminal.prototype.blur = function() {
|
Terminal.prototype.blur = function() {
|
||||||
@@ -409,6 +415,7 @@
|
|||||||
if (this.sendFocus) {
|
if (this.sendFocus) {
|
||||||
this.send('\x1b[O');
|
this.send('\x1b[O');
|
||||||
}
|
}
|
||||||
|
Terminal.focus = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -950,6 +957,17 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flags used to render terminal text properly
|
||||||
|
*/
|
||||||
|
Terminal.flags = {
|
||||||
|
BOLD: 0b00001,
|
||||||
|
UNDERLINE: 0b00010,
|
||||||
|
BLINK: 0b00100,
|
||||||
|
INVERSE: 0b01000,
|
||||||
|
INVISIBLE: 0b10000
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Rendering Engine
|
* Rendering Engine
|
||||||
*
|
*
|
||||||
@@ -1017,8 +1035,7 @@
|
|||||||
fg = (data >> 9) & 0x1ff;
|
fg = (data >> 9) & 0x1ff;
|
||||||
flags = data >> 18;
|
flags = data >> 18;
|
||||||
|
|
||||||
// bold
|
if (flags & Terminal.flags.BOLD) {
|
||||||
if (flags & 1) {
|
|
||||||
if (!Terminal.brokenBold) {
|
if (!Terminal.brokenBold) {
|
||||||
out += ' xterm-bold ';
|
out += ' xterm-bold ';
|
||||||
}
|
}
|
||||||
@@ -1026,35 +1043,50 @@
|
|||||||
if (fg < 8) fg += 8;
|
if (fg < 8) fg += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
// underline
|
if (flags & Terminal.flags.UNDERLINE) {
|
||||||
if (flags & 2) {
|
|
||||||
out += ' xterm-underline ';
|
out += ' xterm-underline ';
|
||||||
}
|
}
|
||||||
|
|
||||||
// blink
|
if (flags & Terminal.flags.BLINK) {
|
||||||
if (flags & 4) {
|
|
||||||
out += ' xterm-blink ';
|
out += ' xterm-blink ';
|
||||||
}
|
}
|
||||||
|
|
||||||
// inverse
|
/**
|
||||||
if (flags & 8) {
|
* If inverse flag is on, then swap the foreground and background variables.
|
||||||
bg = (data >> 9) & 0x1ff;
|
*/
|
||||||
fg = data & 0x1ff;
|
if (flags & Terminal.flags.INVERSE) {
|
||||||
// Should inverse just be before the
|
/* One-line variable swap in JavaScript: http://stackoverflow.com/a/16201730 */
|
||||||
// above boldColors effect instead?
|
bg = [fg, fg = bg][0];
|
||||||
if ((flags & 1) && fg < 8) fg += 8;
|
// Should inverse just be before the
|
||||||
|
// above boldColors effect instead?
|
||||||
|
if ((flags & 1) && fg < 8) fg += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
// invisible
|
if (flags & Terminal.flags.INVISIBLE) {
|
||||||
if (flags & 16) {
|
|
||||||
out += ' xterm-hidden ';
|
out += ' xterm-hidden ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bg !== 256) {
|
/**
|
||||||
|
* Weird situation: Invert flag used black foreground and white background results
|
||||||
|
* in invalid background color, positioned at the 256 index of the 256 terminal
|
||||||
|
* color map. Pin the colors manually in such a case.
|
||||||
|
*
|
||||||
|
* Source: https://github.com/sourcelair/xterm.js/issues/57
|
||||||
|
*/
|
||||||
|
if (flags & Terminal.flags.INVERSE) {
|
||||||
|
if (bg == 257) {
|
||||||
|
bg = 15;
|
||||||
|
}
|
||||||
|
if (fg == 256) {
|
||||||
|
fg = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bg < 256) {
|
||||||
out += ' xterm-bg-color-' + bg + ' ';
|
out += ' xterm-bg-color-' + bg + ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fg !== 257) {
|
if (fg < 256) {
|
||||||
out += ' xterm-color-' + fg + ' ';
|
out += ' xterm-color-' + fg + ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2505,10 +2537,10 @@
|
|||||||
} else if (j > y) {
|
} else if (j > y) {
|
||||||
while (j-- > y) {
|
while (j-- > y) {
|
||||||
if (this.lines.length > y + this.ybase) {
|
if (this.lines.length > y + this.ybase) {
|
||||||
this.lines.pop();
|
this.lines.shift();
|
||||||
}
|
}
|
||||||
if (this.children.length > y) {
|
if (this.children.length > y) {
|
||||||
el = this.children.pop();
|
el = this.children.shift();
|
||||||
if (!el) continue;
|
if (!el) continue;
|
||||||
el.parentNode.removeChild(el);
|
el.parentNode.removeChild(el);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user