]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Merge pull request #129 from sourcelair/docs
authorParis Kasidiaris <pariskasidiaris@gmail.com>
Tue, 14 Jun 2016 07:56:08 +0000 (10:56 +0300)
committerGitHub <noreply@github.com>
Tue, 14 Jun 2016 07:56:08 +0000 (10:56 +0300)
Improve docs building script and template

src/xterm.js
test/addons/test.js [new file with mode: 0644]
test/test.js

index 3d29a66f9c9b200a3e78ddba253d8f42b4b1c8f8..5d4d34ac27f7bf972eda017623726126835ea249 100644 (file)
        */
       this.y = 0;
 
+      /**
+       * Used to debounce the refresh function
+       */
+      this.isRefreshing = false;
+
+      /**
+       * Whether there is a full terminal refresh queued
+       */
+      this.queuedRefresh = false;
+
       this.cursorState = 0;
       this.cursorHidden = false;
       this.convertEol;
 
       this.tabs;
       this.setupStops();
+      this.debounceRefresh();
     }
 
     inherits(Terminal, EventEmitter);
       return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff);
     };
 
+    /**
+     * Allow refresh to execute only approximately 30 times a second. For commands that pass a
+     * significant amount of output to the write function, this prevents the terminal from maxing
+     * out the CPU and making the UI unresponsive. While commands can still run beyond what they do
+     * on the terminal, it is far better with a debounce in place as every single terminal
+     * manipulation does not need to be constructed in the DOM.
+     *
+     * A side-effect of this is that it makes ^C to interrupt a process seem more responsive.
+     */
+    Terminal.prototype.debounceRefresh = function () {
+      var self = this;
+      window.setInterval(function () {
+        self.isRefreshing = false;
+        if (self.queuedRefresh) {
+          // Do a full refresh in case multiple refreshes were requested.
+          self.refresh(0, self.rows - 1);
+        }
+      }, 34);
+    };
+
     /**
      * Colors
      */
       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
     Terminal.prototype.refresh = function(start, end) {
       var x, y, i, line, out, ch, width, data, attr, bg, fg, flags, row, parent, focused = document.activeElement;
 
+      if (this.isRefreshing) {
+        this.queuedRefresh = true;
+        return;
+      }
+      this.isRefreshing = true;
+
       if (end - start >= this.rows / 2) {
         parent = this.element.parentNode;
         if (parent) parent.removeChild(this.element);
diff --git a/test/addons/test.js b/test/addons/test.js
new file mode 100644 (file)
index 0000000..ba689e6
--- /dev/null
@@ -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');
+  });
+});
index 6f7a07914d8bc6b85899cdbf2cfc496ac48d8d95..fcfd8832408a11da5abb73e6233ef1a2cd18609a 100644 (file)
@@ -79,7 +79,7 @@ describe('xterm.js', function() {
       xterm.handler = function() {};
       xterm.showCursor = function() {};
       xterm.clearSelection = function() {};
-    })
+    });
 
     describe('On Mac OS', function() {
       beforeEach(function() {