From 57300f51598305a436b53368f67bc20d8517bc87 Mon Sep 17 00:00:00 2001 From: Paris Date: Mon, 13 Jun 2016 19:07:29 +0300 Subject: [PATCH 1/2] Implement addon loader (CommonJS + RequireJS) Closes #96 --- src/xterm.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/xterm.js b/src/xterm.js index 3d29a66f..5c20dccf 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -759,6 +759,26 @@ this.emit('open'); }; + + /** + * Attempts to load an add-on using CommonJS or RequireJS (whichever is available). + * @param {string} addon The name of the addon to load + * @static + */ + Terminal.loadAddon = function(addon, callback) { + if (typeof exports === 'object' && typeof module === 'object') { + // CommonJS + return require(__dirname + '/../addons/' + addon); + } else if (typeof define == 'function') { + // RequireJS + return require(['../addons/' + addon + '/' + addon], callback); + } else { + console.error('Cannot load a module without a CommonJS or RequireJS environment.'); + return false; + } + }; + + // XTerm mouse events // http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking // To better understand these From 00f380a75c6ee4d379a39a9bddd082e801ee4da1 Mon Sep 17 00:00:00 2001 From: Paris Date: Tue, 14 Jun 2016 00:05:47 +0300 Subject: [PATCH 2/2] Implement test --- test/addons/test.js | 10 ++++++++++ test/test.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/addons/test.js diff --git a/test/addons/test.js b/test/addons/test.js new file mode 100644 index 00000000..ba689e6e --- /dev/null +++ b/test/addons/test.js @@ -0,0 +1,10 @@ +var assert = require('chai').assert; +var Terminal = require('../../src/xterm'); + +describe('xterm.js addons', function() { + it('should load addons with Terminal.loadAddon', function () { + Terminal.loadAddon('attach'); + // Test that function was loaded successfully + assert.equal(typeof Terminal.prototype.attach, 'function'); + }); +}); diff --git a/test/test.js b/test/test.js index 6f7a0791..fcfd8832 100644 --- a/test/test.js +++ b/test/test.js @@ -79,7 +79,7 @@ describe('xterm.js', function() { xterm.handler = function() {}; xterm.showCursor = function() {}; xterm.clearSelection = function() {}; - }) + }); describe('On Mac OS', function() { beforeEach(function() {