mirror of
https://git.proxmox.com/git/mirror_xterm.js
synced 2025-10-04 22:49:47 +00:00
Make src/xterm.js
ES2015 and export EventEmitter into its own file
Fix #158
This commit is contained in:
parent
04a226f813
commit
ed1a31d1cf
@ -21,7 +21,7 @@
|
|||||||
/*
|
/*
|
||||||
* Plain browser environment
|
* Plain browser environment
|
||||||
*/
|
*/
|
||||||
attach(this.Xterm);
|
attach(window.Terminal);
|
||||||
}
|
}
|
||||||
})(function (Xterm) {
|
})(function (Xterm) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
/*
|
/*
|
||||||
* Plain browser environment
|
* Plain browser environment
|
||||||
*/
|
*/
|
||||||
fit(this.Xterm);
|
fit(window.Terminal);
|
||||||
}
|
}
|
||||||
})(function (Xterm) {
|
})(function (Xterm) {
|
||||||
/**
|
/**
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
/*
|
/*
|
||||||
* Plain browser environment
|
* Plain browser environment
|
||||||
*/
|
*/
|
||||||
fullscreen(this.Xterm);
|
fullscreen(window.Terminal);
|
||||||
}
|
}
|
||||||
})(function (Xterm) {
|
})(function (Xterm) {
|
||||||
var exports = {};
|
var exports = {};
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
/*
|
/*
|
||||||
* Plain browser environment
|
* Plain browser environment
|
||||||
*/
|
*/
|
||||||
linkify(this.Xterm);
|
linkify(window.Terminal);
|
||||||
}
|
}
|
||||||
})(function (Xterm) {
|
})(function (Xterm) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
38
bin/build
Executable file
38
bin/build
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#! /usr/bin/env node
|
||||||
|
|
||||||
|
var child_process = require('child_process');
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
var buildDir = process.env.BUILD_DIR || 'build';
|
||||||
|
|
||||||
|
if (!fs.existsSync(buildDir)){
|
||||||
|
fs.mkdirSync(buildDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add `node_modules/.bin` to PATH
|
||||||
|
process.env.PATH = process.cwd() + '/node_modules/.bin:' + process.env.PATH;
|
||||||
|
|
||||||
|
console.log('Building xterm.js into ' + buildDir);
|
||||||
|
|
||||||
|
// Build ES2015 modules into ES5 form, then concatenate them,
|
||||||
|
// then remove unused require calls and save in output file with source map.
|
||||||
|
console.log(' - Building ' + buildDir + '/xterm.js...');
|
||||||
|
|
||||||
|
var jsBuildCmd = 'browserify src/xterm.js -s Terminal -t [ babelify --presets [ es2015 ] ] --debug | ';
|
||||||
|
jsBuildCmd += 'derequire | exorcist ' + buildDir + '/xterm.js.map > ' + buildDir + '/xterm.js';
|
||||||
|
|
||||||
|
var jsBuildProcess = child_process.execSync(jsBuildCmd);
|
||||||
|
|
||||||
|
if (jsBuildProcess.status) {
|
||||||
|
console.log(jsBuildProcess.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(' OK.');
|
||||||
|
|
||||||
|
// Copy CSS into $BUILD_DIR
|
||||||
|
console.log(' - Building ' + buildDir + '/xterm.css...');
|
||||||
|
|
||||||
|
fs.createReadStream('src/xterm.css').pipe(
|
||||||
|
fs.createWriteStream(buildDir + '/xterm.css')
|
||||||
|
);
|
||||||
|
console.log(' OK.');
|
@ -17,12 +17,16 @@ CURRENT_BOWER_JSON_VERSION=$(cat bower.json \
|
|||||||
| sed 's/[",]//g' \
|
| sed 's/[",]//g' \
|
||||||
| tr -d '[[:space:]]')
|
| tr -d '[[:space:]]')
|
||||||
|
|
||||||
# Update version in package.json and bower.json
|
# Build xterm.js into `dist`
|
||||||
sed -i "s/\"version\": \"$CURRENT_PACKAGE_JSON_VERSION\"/\"version\": \"$NEW_VERSION\"/g" package.json
|
export BUILD_DIR=dist
|
||||||
sed -i "s/\"version\": \"$CURRENT_BOWER_JSON_VERSION\"/\"version\": \"$NEW_VERSION\"/g" bower.json
|
sh bin/build
|
||||||
|
|
||||||
# Update AUTHORS file
|
# Update AUTHORS file
|
||||||
sh bin/generate-authors
|
sh bin/generate-authors
|
||||||
|
|
||||||
|
# Update version in package.json and bower.json
|
||||||
|
sed -i "s/\"version\": \"$CURRENT_PACKAGE_JSON_VERSION\"/\"version\": \"$NEW_VERSION\"/g" package.json
|
||||||
|
sed -i "s/\"version\": \"$CURRENT_BOWER_JSON_VERSION\"/\"version\": \"$NEW_VERSION\"/g" bower.json
|
||||||
|
|
||||||
git commit -S -s -a -m "Bump version to $NEW_VERSION"
|
git commit -S -s -a -m "Bump version to $NEW_VERSION"
|
||||||
git tag $NEW_VERSION
|
git tag $NEW_VERSION
|
||||||
|
@ -7,7 +7,7 @@ var pty = require('pty.js');
|
|||||||
var terminals = {},
|
var terminals = {},
|
||||||
logs = {};
|
logs = {};
|
||||||
|
|
||||||
app.use('/src', express.static(__dirname + '/../src'));
|
app.use('/build', express.static(__dirname + '/../build'));
|
||||||
app.use('/addons', express.static(__dirname + '/../addons'));
|
app.use('/addons', express.static(__dirname + '/../addons'));
|
||||||
|
|
||||||
app.get('/', function(req, res){
|
app.get('/', function(req, res){
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>xterm.js demo</title>
|
<title>xterm.js demo</title>
|
||||||
<link rel="stylesheet" href="../src/xterm.css" />
|
<link rel="stylesheet" href="../build/xterm.css" />
|
||||||
<link rel="stylesheet" href="../addons/fullscreen/fullscreen.css" />
|
<link rel="stylesheet" href="../addons/fullscreen/fullscreen.css" />
|
||||||
<link rel="stylesheet" href="style.css" />
|
<link rel="stylesheet" href="style.css" />
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
|
||||||
<script src="../src/xterm.js" ></script>
|
<script src="../build/xterm.js" ></script>
|
||||||
<script src="../addons/attach/attach.js" ></script>
|
<script src="../addons/attach/attach.js" ></script>
|
||||||
<script src="../addons/fit/fit.js" ></script>
|
<script src="../addons/fit/fit.js" ></script>
|
||||||
<script src="../addons/fullscreen/fullscreen.js" ></script>
|
<script src="../addons/fullscreen/fullscreen.js" ></script>
|
||||||
|
14
package.json
14
package.json
@ -10,19 +10,27 @@
|
|||||||
"repository": "https://github.com/sourcelair/xterm.js",
|
"repository": "https://github.com/sourcelair/xterm.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel-core": "6.14.0",
|
||||||
|
"babel-preset-es2015": "6.14.0",
|
||||||
|
"babelify": "^7.3.0",
|
||||||
|
"browserify": "^13.1.0",
|
||||||
"chai": "3.5.0",
|
"chai": "3.5.0",
|
||||||
|
"derequire": "^2.0.3",
|
||||||
"docdash": "0.4.0",
|
"docdash": "0.4.0",
|
||||||
|
"exorcist": "^0.4.0",
|
||||||
"express": "4.13.4",
|
"express": "4.13.4",
|
||||||
"express-ws": "2.0.0-rc.1",
|
"express-ws": "2.0.0-rc.1",
|
||||||
"glob": "^7.0.5",
|
"glob": "^7.0.5",
|
||||||
"jsdoc": "3.4.0",
|
"jsdoc": "3.4.0",
|
||||||
"mocha": "2.5.3",
|
"mocha": "2.5.3",
|
||||||
|
"nodemon": "1.10.2",
|
||||||
"pty.js": "0.3.1",
|
"pty.js": "0.3.1",
|
||||||
"sleep": "^3.0.1"
|
"sleep": "^3.0.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node demo/app",
|
"start": "nodemon --watch src --watch addons --exec bash -c './bin/build && node demo/app'",
|
||||||
"test": "mocha --recursive",
|
"test": "mocha --recursive --compilers js:babel-core/register",
|
||||||
"build:docs": "node_modules/.bin/jsdoc -c jsdoc.json"
|
"build:docs": "jsdoc -c jsdoc.json",
|
||||||
|
"build": "./bin/build"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
64
src/EventEmitter.js
Normal file
64
src/EventEmitter.js
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/**
|
||||||
|
* EventEmitter
|
||||||
|
*/
|
||||||
|
|
||||||
|
function EventEmitter() {
|
||||||
|
this._events = this._events || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
EventEmitter.prototype.addListener = function(type, listener) {
|
||||||
|
this._events[type] = this._events[type] || [];
|
||||||
|
this._events[type].push(listener);
|
||||||
|
};
|
||||||
|
|
||||||
|
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
||||||
|
|
||||||
|
EventEmitter.prototype.removeListener = function(type, listener) {
|
||||||
|
if (!this._events[type]) return;
|
||||||
|
|
||||||
|
var obj = this._events[type]
|
||||||
|
, i = obj.length;
|
||||||
|
|
||||||
|
while (i--) {
|
||||||
|
if (obj[i] === listener || obj[i].listener === listener) {
|
||||||
|
obj.splice(i, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
||||||
|
|
||||||
|
EventEmitter.prototype.removeAllListeners = function(type) {
|
||||||
|
if (this._events[type]) delete this._events[type];
|
||||||
|
};
|
||||||
|
|
||||||
|
EventEmitter.prototype.once = function(type, listener) {
|
||||||
|
var self = this;
|
||||||
|
function on() {
|
||||||
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
this.removeListener(type, on);
|
||||||
|
return listener.apply(this, args);
|
||||||
|
}
|
||||||
|
on.listener = listener;
|
||||||
|
return this.on(type, on);
|
||||||
|
};
|
||||||
|
|
||||||
|
EventEmitter.prototype.emit = function(type) {
|
||||||
|
if (!this._events[type]) return;
|
||||||
|
|
||||||
|
var args = Array.prototype.slice.call(arguments, 1)
|
||||||
|
, obj = this._events[type]
|
||||||
|
, l = obj.length
|
||||||
|
, i = 0;
|
||||||
|
|
||||||
|
for (; i < l; i++) {
|
||||||
|
obj[i].apply(this, args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
EventEmitter.prototype.listeners = function(type) {
|
||||||
|
return this._events[type] = this._events[type] || [];
|
||||||
|
};
|
||||||
|
|
||||||
|
export { EventEmitter };
|
102
src/xterm.js
102
src/xterm.js
@ -31,25 +31,8 @@
|
|||||||
* other features.
|
* other features.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function (xterm) {
|
import { EventEmitter } from './EventEmitter.js';
|
||||||
if (typeof exports === 'object' && typeof module === 'object') {
|
|
||||||
/*
|
|
||||||
* CommonJS environment
|
|
||||||
*/
|
|
||||||
module.exports = xterm.call(this);
|
|
||||||
} else if (typeof define == 'function') {
|
|
||||||
/*
|
|
||||||
* Require.js is available
|
|
||||||
*/
|
|
||||||
define([], xterm.bind(window));
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* Plain browser environment
|
|
||||||
*/
|
|
||||||
this.Xterm = xterm.call(this);
|
|
||||||
this.Terminal = this.Xterm; /* Backwards compatibility with term.js */
|
|
||||||
}
|
|
||||||
})(function() {
|
|
||||||
/**
|
/**
|
||||||
* Terminal Emulation References:
|
* Terminal Emulation References:
|
||||||
* http://vt100.net/
|
* http://vt100.net/
|
||||||
@ -61,77 +44,8 @@
|
|||||||
* http://linux.die.net/man/7/urxvt
|
* http://linux.die.net/man/7/urxvt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
// Let it work inside Node.js for automated testing purposes.
|
||||||
|
var document = (typeof window != 'undefined') ? window.document : null;
|
||||||
/**
|
|
||||||
* Shared
|
|
||||||
*/
|
|
||||||
|
|
||||||
var window = this, document = this.document;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* EventEmitter
|
|
||||||
*/
|
|
||||||
|
|
||||||
function EventEmitter() {
|
|
||||||
this._events = this._events || {};
|
|
||||||
}
|
|
||||||
|
|
||||||
EventEmitter.prototype.addListener = function(type, listener) {
|
|
||||||
this._events[type] = this._events[type] || [];
|
|
||||||
this._events[type].push(listener);
|
|
||||||
};
|
|
||||||
|
|
||||||
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
||||||
|
|
||||||
EventEmitter.prototype.removeListener = function(type, listener) {
|
|
||||||
if (!this._events[type]) return;
|
|
||||||
|
|
||||||
var obj = this._events[type]
|
|
||||||
, i = obj.length;
|
|
||||||
|
|
||||||
while (i--) {
|
|
||||||
if (obj[i] === listener || obj[i].listener === listener) {
|
|
||||||
obj.splice(i, 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
||||||
|
|
||||||
EventEmitter.prototype.removeAllListeners = function(type) {
|
|
||||||
if (this._events[type]) delete this._events[type];
|
|
||||||
};
|
|
||||||
|
|
||||||
EventEmitter.prototype.once = function(type, listener) {
|
|
||||||
var self = this;
|
|
||||||
function on() {
|
|
||||||
var args = Array.prototype.slice.call(arguments);
|
|
||||||
this.removeListener(type, on);
|
|
||||||
return listener.apply(this, args);
|
|
||||||
}
|
|
||||||
on.listener = listener;
|
|
||||||
return this.on(type, on);
|
|
||||||
};
|
|
||||||
|
|
||||||
EventEmitter.prototype.emit = function(type) {
|
|
||||||
if (!this._events[type]) return;
|
|
||||||
|
|
||||||
var args = Array.prototype.slice.call(arguments, 1)
|
|
||||||
, obj = this._events[type]
|
|
||||||
, l = obj.length
|
|
||||||
, i = 0;
|
|
||||||
|
|
||||||
for (; i < l; i++) {
|
|
||||||
obj[i].apply(this, args);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
EventEmitter.prototype.listeners = function(type) {
|
|
||||||
return this._events[type] = this._events[type] || [];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates the logic for handling compositionstart, compositionupdate and compositionend
|
* Encapsulates the logic for handling compositionstart, compositionupdate and compositionend
|
||||||
@ -5232,10 +5146,6 @@
|
|||||||
return w1 !== w2;
|
return w1 !== w2;
|
||||||
}
|
}
|
||||||
|
|
||||||
var String = this.String;
|
|
||||||
var setTimeout = this.setTimeout;
|
|
||||||
var setInterval = this.setInterval;
|
|
||||||
|
|
||||||
function indexOf(obj, el) {
|
function indexOf(obj, el) {
|
||||||
var i = obj.length;
|
var i = obj.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
@ -5444,6 +5354,4 @@
|
|||||||
Terminal.off = off;
|
Terminal.off = off;
|
||||||
Terminal.cancel = cancel;
|
Terminal.cancel = cancel;
|
||||||
|
|
||||||
|
module.exports = Terminal;
|
||||||
return Terminal;
|
|
||||||
});
|
|
||||||
|
@ -15,7 +15,7 @@ describe('CompositionHelper', function () {
|
|||||||
remove: function () {},
|
remove: function () {},
|
||||||
},
|
},
|
||||||
getBoundingClientRect: function () {
|
getBoundingClientRect: function () {
|
||||||
return { width: 0 }
|
return { width: 0 };
|
||||||
},
|
},
|
||||||
style: {
|
style: {
|
||||||
left: 0,
|
left: 0,
|
||||||
|
@ -27,7 +27,7 @@ function pty_write_read(s) {
|
|||||||
return b.toString('utf8', 0, bytes);
|
return b.toString('utf8', 0, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure raw pty is at x=0 and has no pending data
|
// make sure raw pty is at x=0 and has no pending data
|
||||||
function pty_reset() {
|
function pty_reset() {
|
||||||
pty_write_read('\r\n');
|
pty_write_read('\r\n');
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ describe('Viewport', function () {
|
|||||||
var viewportElement;
|
var viewportElement;
|
||||||
var charMeasureElement;
|
var charMeasureElement;
|
||||||
var viewport;
|
var viewport;
|
||||||
|
var scrollAreaElement;
|
||||||
|
|
||||||
var CHARACTER_HEIGHT = 10;
|
var CHARACTER_HEIGHT = 10;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user