]> prime8.dev >> repos - ttyd.git/commitdiff
Improve base64 decode and utf8 handling
authorShuanglei Tao <tsl0922@gmail.com>
Fri, 3 Feb 2017 03:23:59 +0000 (11:23 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Fri, 3 Feb 2017 03:23:59 +0000 (11:23 +0800)
html/index.html
html/js/app.js
html/js/overlay.js [moved from html/js/overlay/overlay.js with 95% similarity]
html/js/utf8.js [new file with mode: 0644]
src/index.html
src/utils.c
src/utils.h

index b5ed7560001d1fa6cffb8001b0c817b24b37b4b9..d252eaf23699fcf61d3bfec9c3791184c99dd6dc 100644 (file)
@@ -9,11 +9,12 @@
     <link inline href="css/app.css">
     <script inline src="node_modules/xterm/dist/xterm.js"></script>
     <script inline src="node_modules/xterm/dist/addons/fit/fit.js"></script>
-    <script inline src="js/overlay/overlay.js"></script>
+    <script inline src="js/utf8.js"></script>
+    <script inline src="js/overlay.js"></script>
 </head>
 <body>
        <div id="terminal-container"></div>
        <script src="auth_token.js"></script>
        <script inline src="js/app.js"></script>
 </body>
-</html>
\ No newline at end of file
+</html>
index 3e085ba691c59858fe80c70869fe1d0a7e96bb78..c9127e66b61bf24ccc624eae1065f743d6394d35 100644 (file)
@@ -52,7 +52,7 @@
             var data = event.data.slice(1);
             switch(event.data[0]) {
                 case '0':
-                    term.write(decodeURIComponent(escape(window.atob(data))));
+                    term.writeUTF8(window.atob(data));
                     break;
                 case '1': // pong
                     break;
similarity index 95%
rename from html/js/overlay/overlay.js
rename to html/js/overlay.js
index d212368dab94f827ed9efc4bd742045ca7d0788d..d777276dc1556ce003a4f26dfc82bba29ab515cd 100644 (file)
@@ -1,4 +1,6 @@
 // ported from hterm.Terminal.prototype.showOverlay
+// https://chromium.googlesource.com/apps/libapps/+/master/hterm/js/hterm_terminal.js
+
 Terminal.prototype.showOverlay = function(msg, timeout) {
     if (!this.overlayNode_) {
         if (!this.element)
diff --git a/html/js/utf8.js b/html/js/utf8.js
new file mode 100644 (file)
index 0000000..5a10144
--- /dev/null
@@ -0,0 +1,118 @@
+// ported from hterm.Terminal.IO.prototype.writeUTF8
+// https://chromium.googlesource.com/apps/libapps/+/master/hterm/js/hterm_terminal_io.js
+
+UTF8Decoder = function() {
+    this.bytesLeft = 0;
+    this.codePoint = 0;
+    this.lowerBound = 0;
+};
+
+UTF8Decoder.prototype.decode = function(str) {
+    var ret = '';
+    for (var i = 0; i < str.length; i++) {
+        var c = str.charCodeAt(i);
+        if (this.bytesLeft == 0) {
+            if (c <= 0x7F) {
+                ret += str.charAt(i);
+            } else if (0xC0 <= c && c <= 0xDF) {
+                this.codePoint = c - 0xC0;
+                this.bytesLeft = 1;
+                this.lowerBound = 0x80;
+            } else if (0xE0 <= c && c <= 0xEF) {
+                this.codePoint = c - 0xE0;
+                this.bytesLeft = 2;
+                this.lowerBound = 0x800;
+            } else if (0xF0 <= c && c <= 0xF7) {
+                this.codePoint = c - 0xF0;
+                this.bytesLeft = 3;
+                this.lowerBound = 0x10000;
+            } else if (0xF8 <= c && c <= 0xFB) {
+                this.codePoint = c - 0xF8;
+                this.bytesLeft = 4;
+                this.lowerBound = 0x200000;
+            } else if (0xFC <= c && c <= 0xFD) {
+                this.codePoint = c - 0xFC;
+                this.bytesLeft = 5;
+                this.lowerBound = 0x4000000;
+            } else {
+                ret += '\ufffd';
+            }
+        } else {
+            if (0x80 <= c && c <= 0xBF) {
+                this.bytesLeft--;
+                this.codePoint = (this.codePoint << 6) + (c - 0x80);
+                if (this.bytesLeft == 0) {
+                    var codePoint = this.codePoint;
+                    if (codePoint < this.lowerBound
+                        || (0xD800 <= codePoint && codePoint <= 0xDFFF)
+                        || codePoint > 0x10FFFF) {
+                        ret += '\ufffd';
+                    } else {
+                        if (codePoint < 0x10000) {
+                            ret += String.fromCharCode(codePoint);
+                        } else {
+                            codePoint -= 0x10000;
+                            ret += String.fromCharCode(
+                                0xD800 + ((codePoint >>> 10) & 0x3FF),
+                                0xDC00 + (codePoint & 0x3FF));
+                        }
+                    }
+                }
+            } else {
+                ret += '\ufffd';
+                this.bytesLeft = 0;
+                i--;
+            }
+        }
+    }
+    return ret;
+};
+
+Terminal.prototype.decodeUTF8 = function(str) {
+    return (new UTF8Decoder()).decode(str);
+};
+
+Terminal.prototype.encodeUTF8 = function(str) {
+    var ret = '';
+    for (var i = 0; i < str.length; i++) {
+        var c = str.charCodeAt(i);
+        if (0xDC00 <= c && c <= 0xDFFF) {
+            c = 0xFFFD;
+        } else if (0xD800 <= c && c <= 0xDBFF) {
+            if (i+1 < str.length) {
+                var d = str.charCodeAt(i+1);
+                if (0xDC00 <= d && d <= 0xDFFF) {
+                    c = 0x10000 + ((c & 0x3FF) << 10) + (d & 0x3FF);
+                    i++;
+                } else {
+                    c = 0xFFFD;
+                }
+            } else {
+                c = 0xFFFD;
+            }
+        }
+        var bytesLeft;
+        if (c <= 0x7F) {
+            ret += str.charAt(i);
+            continue;
+        } else if (c <= 0x7FF) {
+            ret += String.fromCharCode(0xC0 | (c >>> 6));
+            bytesLeft = 1;
+        } else if (c <= 0xFFFF) {
+            ret += String.fromCharCode(0xE0 | (c >>> 12));
+            bytesLeft = 2;
+        } else {
+            ret += String.fromCharCode(0xF0 | (c >>> 18));
+            bytesLeft = 3;
+        }
+        while (bytesLeft > 0) {
+            bytesLeft--;
+            ret += String.fromCharCode(0x80 | ((c >>> (6 * bytesLeft)) & 0x3F));
+        }
+    }
+    return ret;
+};
+
+Terminal.prototype.writeUTF8 = function (str) {
+    this.write(this.decodeUTF8(str));
+};
index 7dddfb5e0b941f32c7d5ce82e3ef6fb60b39ab28..fb3ab57b418793436cab1983d5d0bdc2a8216623 100644 (file)
     <script>!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Terminal=t()}}(function(){var t;return function t(e,s,i){function r(a,h){if(!s[a]){if(!e[a]){var n="function"==typeof require&&require;if(!h&&n)return n(a,!0);if(o)return o(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var l=s[a]={exports:{}};e[a][0].call(l.exports,function(t){var s=e[a][1][t];return r(s?s:t)},l,l.exports,t,e,s,i)}return s[a].exports}for(var o="function"==typeof require&&require,a=0;a<i.length;a++)r(i[a]);return r}({1:[function(t,e,s){"use strict";var i=function(){function t(t,e,s){this.textarea=t,this.compositionView=e,this.terminal=s,this.isComposing=!1,this.isSendingComposition=!1,this.compositionPosition={start:null,end:null}}return t.prototype.compositionstart=function(){this.isComposing=!0,this.compositionPosition.start=this.textarea.value.length,this.compositionView.textContent="",this.compositionView.classList.add("active")},t.prototype.compositionupdate=function(t){this.compositionView.textContent=t.data,this.updateCompositionElements();var e=this;setTimeout(function(){e.compositionPosition.end=e.textarea.value.length},0)},t.prototype.compositionend=function(){this.finalizeComposition(!0)},t.prototype.keydown=function(t){if(this.isComposing||this.isSendingComposition){if(229===t.keyCode)return!1;if(16===t.keyCode||17===t.keyCode||18===t.keyCode)return!1;this.finalizeComposition(!1)}return 229!==t.keyCode||(this.handleAnyTextareaChanges(),!1)},t.prototype.finalizeComposition=function(t){if(this.compositionView.classList.remove("active"),this.isComposing=!1,this.clearTextareaPosition(),t){var e={start:this.compositionPosition.start,end:this.compositionPosition.end},s=this;this.isSendingComposition=!0,setTimeout(function(){if(s.isSendingComposition){s.isSendingComposition=!1;var t;t=s.isComposing?s.textarea.value.substring(e.start,e.end):s.textarea.value.substring(e.start),s.terminal.handler(t)}},0)}else{this.isSendingComposition=!1;var i=this.textarea.value.substring(this.compositionPosition.start,this.compositionPosition.end);this.terminal.handler(i)}},t.prototype.handleAnyTextareaChanges=function(){var t=this.textarea.value,e=this;setTimeout(function(){if(!e.isComposing){var s=e.textarea.value,i=s.replace(t,"");i.length>0&&e.terminal.handler(i)}},0)},t.prototype.updateCompositionElements=function(t){if(this.isComposing){var e=this.terminal.element.querySelector(".terminal-cursor");if(e){var s=this.terminal.element.querySelector(".xterm-rows"),i=s.offsetTop+e.offsetTop;this.compositionView.style.left=e.offsetLeft+"px",this.compositionView.style.top=i+"px",this.compositionView.style.height=e.offsetHeight+"px",this.compositionView.style.lineHeight=e.offsetHeight+"px";var r=this.compositionView.getBoundingClientRect();this.textarea.style.left=e.offsetLeft+"px",this.textarea.style.top=i+"px",this.textarea.style.width=r.width+"px",this.textarea.style.height=r.height+"px",this.textarea.style.lineHeight=r.height+"px"}t||setTimeout(this.updateCompositionElements.bind(this,!0),0)}},t.prototype.clearTextareaPosition=function(){this.textarea.style.left="",this.textarea.style.top=""},t}();s.CompositionHelper=i},{}],2:[function(t,e,s){"use strict";function i(){this._events=this._events||{}}s.EventEmitter=i,i.prototype.addListener=function(t,e){this._events[t]=this._events[t]||[],this._events[t].push(e)},i.prototype.on=i.prototype.addListener,i.prototype.removeListener=function(t,e){if(this._events[t])for(var s=this._events[t],i=s.length;i--;)if(s[i]===e||s[i].listener===e)return void s.splice(i,1)},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(t){this._events[t]&&delete this._events[t]},i.prototype.once=function(t,e){function s(){var i=Array.prototype.slice.call(arguments);return this.removeListener(t,s),e.apply(this,i)}return s.listener=e,this.on(t,s)},i.prototype.emit=function(t){if(this._events[t])for(var e=Array.prototype.slice.call(arguments,1),s=this._events[t],i=s.length,r=0;r<i;r++)s[r].apply(this,e)},i.prototype.listeners=function(t){return this._events[t]=this._events[t]||[]}},{}],3:[function(t,e,s){"use strict";var i=function(){function t(t,e,s,i){this.terminal=t,this.viewportElement=e,this.scrollArea=s,this.charMeasureElement=i,this.currentRowHeight=0,this.lastRecordedBufferLength=0,this.lastRecordedViewportHeight=0,this.terminal.on("scroll",this.syncScrollArea.bind(this)),this.terminal.on("resize",this.syncScrollArea.bind(this)),this.viewportElement.addEventListener("scroll",this.onScroll.bind(this)),this.syncScrollArea()}return t.prototype.refresh=function(t){var e=t||this.charMeasureElement.getBoundingClientRect();if(e.height>0){var s=e.height!==this.currentRowHeight;s&&(this.currentRowHeight=e.height,this.viewportElement.style.lineHeight=e.height+"px",this.terminal.rowContainer.style.lineHeight=e.height+"px");var i=this.lastRecordedViewportHeight!==this.terminal.rows;(s||i)&&(this.lastRecordedViewportHeight=this.terminal.rows,this.viewportElement.style.height=e.height*this.terminal.rows+"px"),this.scrollArea.style.height=e.height*this.lastRecordedBufferLength+"px"}},t.prototype.syncScrollArea=function(){if(this.lastRecordedBufferLength!==this.terminal.lines.length)this.lastRecordedBufferLength=this.terminal.lines.length,this.refresh();else if(this.lastRecordedViewportHeight!==this.terminal.rows)this.refresh();else{var t=this.charMeasureElement.getBoundingClientRect();t.height!==this.currentRowHeight&&this.refresh(t)}var e=this.terminal.ydisp*this.currentRowHeight;this.viewportElement.scrollTop!==e&&(this.viewportElement.scrollTop=e)},t.prototype.onScroll=function(t){var e=Math.round(this.viewportElement.scrollTop/this.currentRowHeight),s=e-this.terminal.ydisp;this.terminal.scrollDisp(s,!0)},t.prototype.onWheel=function(t){if(0!==t.deltaY){var e=1;t.deltaMode===WheelEvent.DOM_DELTA_LINE?e=this.currentRowHeight:t.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(e=this.currentRowHeight*this.terminal.rows),this.viewportElement.scrollTop+=t.deltaY*e,t.preventDefault()}},t}();s.Viewport=i},{}],4:[function(t,e,s){"use strict";function i(t){var e=String.fromCharCode(32),s=String.fromCharCode(160),i=new RegExp(s,"g"),r=t.split("\n").map(function(t){var s=t.replace(/\s+$/g,"").replace(i,e);return s}).join("\n");return r}function r(t,e){var s=window.getSelection().toString(),r=i(s);e.browser.isMSIE?window.clipboardData.setData("Text",r):t.clipboardData.setData("text/plain",r),t.preventDefault()}function o(t,e){t.stopPropagation();var s,i=function(s){return e.handler(s),e.textarea.value="",e.cancel(t)};e.browser.isMSIE?window.clipboardData&&(s=window.clipboardData.getData("Text"),i(s)):t.clipboardData&&(s=t.clipboardData.getData("text/plain"),i(s))}function a(t,e){var s=document.getSelection(),r=i(s.toString()),o=!1,a=t.clientX,h=t.clientY;if(s.rangeCount){for(var n=s.getRangeAt(0),c=n.getClientRects(),l=0;l<c.length;l++){var p=c[l];if(o=a>p.left&&a<p.right&&h>p.top&&h<p.bottom)break}!r.match(/^\s$/)&&r.length||(o=!1)}o||(e.textarea.style.position="fixed",e.textarea.style.width="20px",e.textarea.style.height="20px",e.textarea.style.left=a-10+"px",e.textarea.style.top=h-10+"px",e.textarea.style.zIndex="1000",e.textarea.focus(),setTimeout(function(){e.textarea.style.position=null,e.textarea.style.width=null,e.textarea.style.height=null,e.textarea.style.left=null,e.textarea.style.top=null,e.textarea.style.zIndex=null},4))}s.prepareTextForClipboard=i,s.copyHandler=r,s.pasteHandler=o,s.rightClickHandler=a},{}],5:[function(t,e,s){"use strict";var i=t("./Generic.js"),r="undefined"==typeof navigator,o=r?"node":navigator.userAgent,a=r?"node":navigator.platform;s.isFirefox=!!~o.indexOf("Firefox"),s.isMSIE=!!~o.indexOf("MSIE")||!!~o.indexOf("Trident"),s.isMac=i.contains(["Macintosh","MacIntel","MacPPC","Mac68K"],a),s.isIpad="iPad"===a,s.isIphone="iPhone"===a,s.isMSWindows=i.contains(["Windows","Win16","Win32","WinCE"],a)},{"./Generic.js":6}],6:[function(t,e,s){"use strict";s.contains=function(t,e){return t.indexOf(e)>=0}},{}],7:[function(e,s,i){"use strict";function r(t){var e=this;if(!(this instanceof r))return new r(arguments[0],arguments[1],arguments[2]);e.browser=k,e.cancel=r.cancel,y.EventEmitter.call(this),"number"==typeof t&&(t={cols:arguments[0],rows:arguments[1],handler:arguments[2]}),t=t||{},Object.keys(r.defaults).forEach(function(s){null==t[s]&&(t[s]=r.options[s],r[s]!==r.defaults[s]&&(t[s]=r[s])),e[s]=t[s]}),8===t.colors.length?t.colors=t.colors.concat(r._colors.slice(8)):16===t.colors.length?t.colors=t.colors.concat(r._colors.slice(16)):10===t.colors.length?t.colors=t.colors.slice(0,-2).concat(r._colors.slice(8,-2),t.colors.slice(-2)):18===t.colors.length&&(t.colors=t.colors.concat(r._colors.slice(16,-2),t.colors.slice(-2))),this.colors=t.colors,this.options=t,this.parent=t.body||t.parent||(v?v.getElementsByTagName("body")[0]:null),this.cols=t.cols||t.geometry[0],this.rows=t.rows||t.geometry[1],this.geometry=[this.cols,this.rows],t.handler&&this.on("data",t.handler),this.ybase=0,this.ydisp=0,this.x=0,this.y=0,this.isRefreshing=!1,this.cursorState=0,this.cursorHidden=!1,this.convertEol,this.state=0,this.queue="",this.scrollTop=0,this.scrollBottom=this.rows-1,this.customKeydownHandler=null,this.applicationKeypad=!1,this.applicationCursor=!1,this.originMode=!1,this.insertMode=!1,this.wraparoundMode=!0,this.normal=null,this.charset=null,this.gcharset=null,this.glevel=0,this.charsets=[null],this.decLocator,this.x10Mouse,this.vt200Mouse,this.vt300Mouse,this.normalMouse,this.mouseEvents,this.sendFocus,this.utfMouse,this.sgrMouse,this.urxvtMouse,this.element,this.children,this.refreshStart,this.refreshEnd,this.savedX,this.savedY,this.savedCols,this.readable=!0,this.writable=!0,this.defAttr=131840,this.curAttr=this.defAttr,this.params=[],this.currentParam=0,this.prefix="",this.postfix="",this.surrogate_high="",this.lines=[];for(var s=this.rows;s--;)this.lines.push(this.blankLine());this.tabs,this.setupStops(),this.userScrolling=!1}function o(t,e,s,i){Array.isArray(t)||(t=[t]),t.forEach(function(t){t.addEventListener(e,s,i||!1)})}function a(t,e,s,i){t.removeEventListener(e,s,i||!1)}function h(t,e){if(this.cancelEvents||e)return t.preventDefault(),t.stopPropagation(),!1}function n(t,e){function s(){this.constructor=t}s.prototype=e.prototype,t.prototype=new s}function c(t){var e=t.getElementsByTagName("body")[0],s=t.createElement("span");s.innerHTML="hello world",e.appendChild(s);var i=s.scrollWidth;s.style.fontWeight="bold";var r=s.scrollWidth;return e.removeChild(s),i!==r}function l(t,e){var s=t.browser.isMac&&e.altKey&&!e.ctrlKey&&!e.metaKey||t.browser.isMSWindows&&e.altKey&&e.ctrlKey&&!e.metaKey;return"keypress"==e.type?s:s&&(!e.keyCode||e.keyCode>47)}function p(t,e,s){var i=t<<16|e<<8|s;if(null!=p._cache[i])return p._cache[i];for(var o,a,h,n,c,l=1/0,u=-1,f=0;f<r.vcolors.length;f++){if(o=r.vcolors[f],a=o[0],h=o[1],n=o[2],c=p.distance(t,e,s,a,h,n),0===c){u=f;break}c<l&&(l=c,u=f)}return p._cache[i]=u}function u(t,e,s){if(t.forEach)return t.forEach(e,s);for(var i=0;i<t.length;i++)e.call(s,t[i],i,t)}function f(t){if(Object.keys)return Object.keys(t);var e,s=[];for(e in t)Object.prototype.hasOwnProperty.call(t,e)&&s.push(e);return s}var d=e("./CompositionHelper.js"),y=e("./EventEmitter.js"),m=e("./Viewport.js"),b=e("./handlers/Clipboard.js"),k=e("./utils/Browser"),v="undefined"!=typeof window?window.document:null,g=0,w=1,x=2,C=3,S=4,E=5,M=6;n(r,y.EventEmitter),r.prototype.eraseAttr=function(){return this.defAttr&-512|511&this.curAttr},r.tangoColors=["#2e3436","#cc0000","#4e9a06","#c4a000","#3465a4","#75507b","#06989a","#d3d7cf","#555753","#ef2929","#8ae234","#fce94f","#729fcf","#ad7fa8","#34e2e2","#eeeeec"],r.colors=function(){function t(t,s,r){i.push("#"+e(t)+e(s)+e(r))}function e(t){return t=t.toString(16),t.length<2?"0"+t:t}var s,i=r.tangoColors.slice(),o=[0,95,135,175,215,255];for(s=0;s<216;s++)t(o[s/36%6|0],o[s/6%6|0],o[s%6]);for(s=0;s<24;s++)o=8+10*s,t(o,o,o);return i}(),r._colors=r.colors.slice(),r.vcolors=function(){for(var t,e=[],s=r.colors,i=0;i<256;i++)t=parseInt(s[i].substring(1),16),e.push([t>>16&255,t>>8&255,255&t]);return e}(),r.defaults={colors:r.colors,theme:"default",convertEol:!1,termName:"xterm",geometry:[80,24],cursorBlink:!1,visualBell:!1,popOnBell:!1,scrollback:1e3,screenKeys:!1,debug:!1,cancelEvents:!1},r.options={},r.focus=null,u(f(r.defaults),function(t){r[t]=r.defaults[t],r.options[t]=r.defaults[t]}),r.prototype.focus=function(){return this.textarea.focus()},r.prototype.getOption=function(t,e){if(!(t in r.defaults))throw new Error('No option with key "'+t+'"');return"undefined"!=typeof this.options[t]?this.options[t]:this[t]},r.prototype.setOption=function(t,e){if(!(t in r.defaults))throw new Error('No option with key "'+t+'"');this[t]=e,this.options[t]=e},r.bindFocus=function(t){o(t.textarea,"focus",function(e){t.sendFocus&&t.send("\e[I"),t.element.classList.add("focus"),t.showCursor(),r.focus=t,t.emit("focus",{terminal:t})})},r.prototype.blur=function(){return this.textarea.blur()},r.bindBlur=function(t){o(t.textarea,"blur",function(e){t.refresh(t.y,t.y),t.sendFocus&&t.send("\e[O"),t.element.classList.remove("focus"),r.focus=null,t.emit("blur",{terminal:t})})},r.prototype.initGlobal=function(){function t(t){b.rightClickHandler.call(this,t,e)}var e=this;r.bindKeys(this),r.bindFocus(this),r.bindBlur(this),o(this.element,"copy",function(t){b.copyHandler.call(this,t,e)}),o(this.textarea,"paste",function(t){b.pasteHandler.call(this,t,e)}),o(this.element,"paste",function(t){b.pasteHandler.call(this,t,e)}),e.browser.isFirefox?o(this.element,"mousedown",function(e){2==e.button&&t(e)}):o(this.element,"contextmenu",t)},r.bindKeys=function(t){o(t.element,"keydown",function(e){v.activeElement==this&&t.keyDown(e)},!0),o(t.element,"keypress",function(e){v.activeElement==this&&t.keyPress(e)},!0),o(t.element,"keyup",t.focus.bind(t)),o(t.textarea,"keydown",function(e){t.keyDown(e)},!0),o(t.textarea,"keypress",function(e){t.keyPress(e),this.value=""},!0),o(t.textarea,"compositionstart",t.compositionHelper.compositionstart.bind(t.compositionHelper)),o(t.textarea,"compositionupdate",t.compositionHelper.compositionupdate.bind(t.compositionHelper)),o(t.textarea,"compositionend",t.compositionHelper.compositionend.bind(t.compositionHelper)),t.on("refresh",t.compositionHelper.updateCompositionElements.bind(t.compositionHelper))},r.prototype.insertRow=function(t){return"object"!=typeof t&&(t=v.createElement("div")),this.rowContainer.appendChild(t),this.children.push(t),t},r.prototype.open=function(t){var e=this,s=0;if(this.parent=t||this.parent,!this.parent)throw new Error("Terminal requires a parent element.");for(this.context=this.parent.ownerDocument.defaultView,this.document=this.parent.ownerDocument,this.body=this.document.getElementsByTagName("body")[0],this.element=this.document.createElement("div"),this.element.classList.add("terminal"),this.element.classList.add("xterm"),this.element.classList.add("xterm-theme-"+this.theme),this.element.style.height,this.element.setAttribute("tabindex",0),this.viewportElement=v.createElement("div"),this.viewportElement.classList.add("xterm-viewport"),this.element.appendChild(this.viewportElement),this.viewportScrollArea=v.createElement("div"),this.viewportScrollArea.classList.add("xterm-scroll-area"),this.viewportElement.appendChild(this.viewportScrollArea),this.rowContainer=v.createElement("div"),this.rowContainer.classList.add("xterm-rows"),this.element.appendChild(this.rowContainer),this.children=[],this.helperContainer=v.createElement("div"),this.helperContainer.classList.add("xterm-helpers"),this.element.appendChild(this.helperContainer),this.textarea=v.createElement("textarea"),this.textarea.classList.add("xterm-helper-textarea"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.tabIndex=0,this.textarea.addEventListener("focus",function(){e.emit("focus",{terminal:e})}),this.textarea.addEventListener("blur",function(){e.emit("blur",{terminal:e})}),this.helperContainer.appendChild(this.textarea),this.compositionView=v.createElement("div"),this.compositionView.classList.add("composition-view"),this.compositionHelper=new d.CompositionHelper(this.textarea,this.compositionView,this),this.helperContainer.appendChild(this.compositionView),this.charMeasureElement=v.createElement("div"),this.charMeasureElement.classList.add("xterm-char-measure-element"),this.charMeasureElement.innerHTML="W",this.helperContainer.appendChild(this.charMeasureElement);s<this.rows;s++)this.insertRow();this.parent.appendChild(this.element),this.viewport=new m.Viewport(this,this.viewportElement,this.viewportScrollArea,this.charMeasureElement),this.refresh(0,this.rows-1),this.initGlobal(),this.focus(),o(this.element,"click",function(){var t=v.getSelection(),s=t.isCollapsed,i="boolean"==typeof s?!s:"Range"==t.type;i||e.focus()}),this.bindMouse(),null==r.brokenBold&&(r.brokenBold=c(this.document)),this.emit("open")},r.loadAddon=function(r,o){return"object"==typeof i&&"object"==typeof s?e("./addons/"+r+"/"+r):"function"==typeof t?e(["./addons/"+r+"/"+r],o):(console.error("Cannot load a module without a CommonJS or RequireJS environment."),!1)},r.prototype.bindMouse=function(){function t(t){var e,s;if(e=r(t),s=h(t))switch(i(e,s),t.overrideType||t.type){case"mousedown":l=e;break;case"mouseup":l=32;break;case"wheel":}}function e(t){var e,s=l;e=h(t),e&&(s+=32,i(s,e))}function s(t,e){if(c.utfMouse){if(2047===e)return t.push(0);e<127?t.push(e):(e>2047&&(e=2047),t.push(192|e>>6),t.push(128|63&e))}else{if(255===e)return t.push(0);e>127&&(e=127),t.push(e)}}function i(t,e){if(c.vt300Mouse){t&=3,e.x-=32,e.y-=32;var i="\e[24";if(0===t)i+="1";else if(1===t)i+="3";else if(2===t)i+="5";else{if(3===t)return;i+="0"}return i+="~["+e.x+","+e.y+"]\r",void c.send(i)}if(c.decLocator)return t&=3,e.x-=32,e.y-=32,0===t?t=2:1===t?t=4:2===t?t=6:3===t&&(t=3),void c.send("\e["+t+";"+(3===t?4:0)+";"+e.y+";"+e.x+";"+(e.page||0)+"&w");if(c.urxvtMouse)return e.x-=32,e.y-=32,e.x++,e.y++,void c.send("\e["+t+";"+e.x+";"+e.y+"M");if(c.sgrMouse)return e.x-=32,e.y-=32,void c.send("\e[<"+((3===(3&t)?t&-4:t)-32)+";"+e.x+";"+e.y+(3===(3&t)?"m":"M"));var i=[];s(i,t),s(i,e.x),s(i,e.y),c.send("\e[M"+String.fromCharCode.apply(String,i))}function r(t){var e,s,i,r,o;switch(t.overrideType||t.type){case"mousedown":e=null!=t.button?+t.button:null!=t.which?t.which-1:null,c.browser.isMSIE&&(e=1===e?0:4===e?1:e);break;case"mouseup":e=3;break;case"DOMMouseScroll":e=t.detail<0?64:65;break;case"wheel":e=t.wheelDeltaY>0?64:65}return s=t.shiftKey?4:0,i=t.metaKey?8:0,r=t.ctrlKey?16:0,o=s|i|r,c.vt200Mouse?o&=r:c.normalMouse||(o=0),e=32+(o<<2)+e}function h(t){var e,s,i,r,o;if(null!=t.pageX){for(e=t.pageX,s=t.pageY,o=c.element;o&&o!==c.document.documentElement;)e-=o.offsetLeft,s-=o.offsetTop,o="offsetParent"in o?o.offsetParent:o.parentNode;return i=c.element.clientWidth,r=c.element.clientHeight,e=Math.ceil(e/i*c.cols),s=Math.ceil(s/r*c.rows),e<0&&(e=0),e>c.cols&&(e=c.cols),s<0&&(s=0),s>c.rows&&(s=c.rows),e+=32,s+=32,{x:e,y:s,type:"wheel"}}}var n=this.element,c=this,l=32;o(n,"mousedown",function(s){if(c.mouseEvents)return t(s),c.focus(),c.vt200Mouse?(s.overrideType="mouseup",t(s),c.cancel(s)):(c.normalMouse&&o(c.document,"mousemove",e),c.x10Mouse||o(c.document,"mouseup",function s(i){return t(i),c.normalMouse&&a(c.document,"mousemove",e),a(c.document,"mouseup",s),c.cancel(i)}),c.cancel(s))}),o(n,"wheel",function(e){if(c.mouseEvents&&!(c.x10Mouse||c.vt300Mouse||c.decLocator))return t(e),c.cancel(e)}),o(n,"wheel",function(t){if(!c.mouseEvents)return c.viewport.onWheel(t),c.cancel(t)})},r.prototype.destroy=function(){this.readable=!1,this.writable=!1,this._events={},this.handler=function(){},this.write=function(){},this.element.parentNode&&this.element.parentNode.removeChild(this.element)},r.flags={BOLD:1,UNDERLINE:2,BLINK:4,INVERSE:8,INVISIBLE:16},r.prototype.refresh=function(t,e,s){var i=this;if(s="undefined"==typeof s||s)return void(this._refreshIsQueued?this._fullRefreshNext=!0:(setTimeout(function(){i.refresh(t,e,!1)},34),this._refreshIsQueued=!0));this._refreshIsQueued=!1,this._fullRefreshNext&&(t=0,e=this.rows-1,this._fullRefreshNext=!1);var o,a,h,n,c,l,p,u,f,d,y,m,b,k,g;v.activeElement;for(e-t>=this.rows/2&&(g=this.element.parentNode,g&&this.element.removeChild(this.rowContainer)),u=this.cols,a=t,e>=this.rows.length&&(this.log("`end` is too large. Most likely a bad CSR."),e=this.rows.length-1);a<=e;a++){for(k=a+this.ydisp,n=this.lines[k],c="",o=this.y===a-(this.ybase-this.ydisp)&&this.cursorState&&!this.cursorHidden?this.x:-1,d=this.defAttr,h=0;h<u;h++)if(f=n[h][0],l=n[h][1],p=n[h][2]){if(h===o&&(f=-1),f!==d&&(d!==this.defAttr&&(c+="</span>"),f!==this.defAttr))if(f===-1)c+='<span class="reverse-video terminal-cursor',this.cursorBlink&&(c+=" blinking"),c+='">';else{var w=[];y=511&f,m=f>>9&511,b=f>>18,b&r.flags.BOLD&&(r.brokenBold||w.push("xterm-bold"),m<8&&(m+=8)),b&r.flags.UNDERLINE&&w.push("xterm-underline"),b&r.flags.BLINK&&w.push("xterm-blink"),b&r.flags.INVERSE&&(y=[m,m=y][0],1&b&&m<8&&(m+=8)),b&r.flags.INVISIBLE&&w.push("xterm-hidden"),b&r.flags.INVERSE&&(257==y&&(y=15),256==m&&(m=0)),y<256&&w.push("xterm-bg-color-"+y),m<256&&w.push("xterm-color-"+m),c+="<span",w.length&&(c+=' class="'+w.join(" ")+'"'),c+=">"}switch(l){case"&":c+="&amp;";break;case"<":c+="&lt;";break;case">":c+="&gt;";break;default:c+=l<=" "?"&nbsp;":l}d=f}d!==this.defAttr&&(c+="</span>"),this.children[a].innerHTML=c}g&&this.element.appendChild(this.rowContainer),this.emit("refresh",{element:this.element,start:t,end:e})},r.prototype.showCursor=function(){this.cursorState||(this.cursorState=1,this.refresh(this.y,this.y))},r.prototype.scroll=function(){var t;++this.ybase===this.scrollback&&(this.ybase=this.ybase/2|0,this.lines=this.lines.slice(-(this.ybase+this.rows)+1)),this.userScrolling||(this.ydisp=this.ybase),t=this.ybase+this.rows-1,t-=this.rows-1-this.scrollBottom,t===this.lines.length?this.lines.push(this.blankLine()):this.lines.splice(t,0,this.blankLine()),0!==this.scrollTop&&(0!==this.ybase&&(this.ybase--,this.userScrolling||(this.ydisp=this.ybase)),this.lines.splice(this.ybase+this.scrollTop,1)),this.updateRange(this.scrollTop),this.updateRange(this.scrollBottom),this.emit("scroll",this.ydisp)},r.prototype.scrollDisp=function(t,e){t<0?this.userScrolling=!0:t+this.ydisp>=this.ybase&&(this.userScrolling=!1),this.ydisp+=t,this.ydisp>this.ybase?this.ydisp=this.ybase:this.ydisp<0&&(this.ydisp=0),e||this.emit("scroll",this.ydisp),this.refresh(0,this.rows-1)},r.prototype.scrollPages=function(t){this.scrollDisp(t*(this.rows-1))},r.prototype.scrollToTop=function(){this.scrollDisp(-this.ydisp)},r.prototype.scrollToBottom=function(){this.scrollDisp(this.ybase-this.ydisp)},r.prototype.write=function(t){var e,s,i,o,a,h,n=t.length,c=0;for(this.refreshStart=this.y,this.refreshEnd=this.y,this.surrogate_high&&(t=this.surrogate_high+t,this.surrogate_high="");c<n;c++){if(s=t[c],i=t.charCodeAt(c),55296<=i&&i<=56319){if(o=t.charCodeAt(c+1),isNaN(o)){this.surrogate_high=s;continue}i=1024*(i-55296)+(o-56320)+65536,s+=t.charAt(c+1)}if(!(56320<=i&&i<=57343))switch(this.state){case g:switch(s){case"\a":this.bell();break;case"\n":case"\v":case"\f":this.convertEol&&(this.x=0),this.y++,this.y>this.scrollBottom&&(this.y--,this.scroll());break;case"\r":this.x=0;break;case"\b":this.x>0&&this.x--;break;case"\t":this.x=this.nextStop();break;case"\ e":this.setgLevel(1);break;case"\ f":this.setgLevel(0);break;case"\e":this.state=w;break;default:if(a=A(i),s>=" "){if(this.charset&&this.charset[s]&&(s=this.charset[s]),h=this.y+this.ybase,!a&&this.x){this.lines[h][this.x-1]&&(this.lines[h][this.x-1][2]?this.lines[h][this.x-1][1]+=s:this.lines[h][this.x-2]&&(this.lines[h][this.x-2][1]+=s),this.updateRange(this.y));break}if(this.x+a-1>=this.cols)if(this.wraparoundMode)this.x=0,this.y++,this.y>this.scrollBottom&&(this.y--,this.scroll());else if(this.x=this.cols-1,2===a)continue;if(h=this.y+this.ybase,this.insertMode)for(var l=0;l<a;++l){var p=this.lines[this.y+this.ybase].pop();0===p[2]&&this.lines[h][this.cols-2]&&2===this.lines[h][this.cols-2][2]&&(this.lines[h][this.cols-2]=[this.curAttr," ",1]),this.lines[h].splice(this.x,0,[this.curAttr," ",1])}this.lines[h][this.x]=[this.curAttr,s,a],this.x++,this.updateRange(this.y),2===a&&(this.lines[h][this.x]=[this.curAttr,"",0],this.x++)}}break;case w:switch(s){case"[":this.params=[],this.currentParam=0,this.state=x;break;case"]":this.params=[],this.currentParam=0,this.state=C;break;case"P":this.params=[],this.currentParam=0,this.state=E;break;case"_":this.state=M;break;case"^":this.state=M;break;case"c":this.reset();break;case"E":this.x=0;case"D":this.index();break;case"M":this.reverseIndex();break;case"%":this.setgLevel(0),this.setgCharset(0,r.charsets.US),this.state=g,c++;break;case"(":case")":case"*":case"+":case"-":case".":switch(s){case"(":this.gcharset=0;break;case")":this.gcharset=1;break;case"*":this.gcharset=2;break;case"+":this.gcharset=3;break;case"-":this.gcharset=1;break;case".":this.gcharset=2}this.state=S;break;case"/":this.gcharset=3,this.state=S,c--;break;case"N":break;case"O":break;case"n":this.setgLevel(2);break;case"o":this.setgLevel(3);break;case"|":this.setgLevel(3);break;case"}":this.setgLevel(2);break;case"~":this.setgLevel(1);break;case"7":this.saveCursor(),this.state=g;break;case"8":this.restoreCursor(),this.state=g;break;case"#":this.state=g,c++;break;case"H":this.tabSet();break;case"=":this.log("Serial port requested application keypad."),this.applicationKeypad=!0,this.viewport.syncScrollArea(),this.state=g;break;case">":this.log("Switching back to normal keypad."),this.applicationKeypad=!1,this.viewport.syncScrollArea(),this.state=g;break;default:this.state=g,this.error("Unknown ESC control: %s.",s)}break;case S:switch(s){case"0":e=r.charsets.SCLD;break;case"A":e=r.charsets.UK;break;case"B":e=r.charsets.US;break;case"4":e=r.charsets.Dutch;break;case"C":case"5":e=r.charsets.Finnish;break;case"R":e=r.charsets.French;break;case"Q":e=r.charsets.FrenchCanadian;break;case"K":e=r.charsets.German;break;case"Y":e=r.charsets.Italian;break;case"E":case"6":e=r.charsets.NorwegianDanish;break;case"Z":e=r.charsets.Spanish;break;case"H":case"7":e=r.charsets.Swedish;break;case"=":e=r.charsets.Swiss;break;case"/":e=r.charsets.ISOLatin,c++;break;default:e=r.charsets.US}this.setgCharset(this.gcharset,e),this.gcharset=null,this.state=g;break;case C:if("\e"===s||"\a"===s){switch("\e"===s&&c++,this.params.push(this.currentParam),this.params[0]){case 0:case 1:case 2:this.params[1]&&(this.title=this.params[1],this.handleTitle(this.title));break;case 3:break;case 4:case 5:break;case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:case 19:break;case 46:break;case 50:break;case 51:break;case 52:break;case 104:case 105:case 110:case 111:case 112:case 113:case 114:case 115:case 116:case 117:case 118:}this.params=[],this.currentParam=0,this.state=g}else this.params.length?this.currentParam+=s:s>="0"&&s<="9"?this.currentParam=10*this.currentParam+s.charCodeAt(0)-48:";"===s&&(this.params.push(this.currentParam),this.currentParam="");break;case x:if("?"===s||">"===s||"!"===s){this.prefix=s;break}if(s>="0"&&s<="9"){this.currentParam=10*this.currentParam+s.charCodeAt(0)-48;break}if("$"===s||'"'===s||" "===s||"'"===s){this.postfix=s;break}if(this.params.push(this.currentParam),this.currentParam=0,";"===s)break;switch(this.state=g,s){case"A":this.cursorUp(this.params);break;case"B":this.cursorDown(this.params);break;case"C":this.cursorForward(this.params);break;case"D":this.cursorBackward(this.params);break;case"H":this.cursorPos(this.params);break;case"J":this.eraseInDisplay(this.params);break;case"K":this.eraseInLine(this.params);break;case"m":this.prefix||this.charAttributes(this.params);break;case"n":this.prefix||this.deviceStatus(this.params);break;case"@":this.insertChars(this.params);break;case"E":this.cursorNextLine(this.params);break;case"F":this.cursorPrecedingLine(this.params);break;case"G":this.cursorCharAbsolute(this.params);break;case"L":this.insertLines(this.params);break;case"M":this.deleteLines(this.params);break;case"P":this.deleteChars(this.params);break;case"X":this.eraseChars(this.params);break;case"`":this.charPosAbsolute(this.params);break;case"a":this.HPositionRelative(this.params);break;case"c":this.sendDeviceAttributes(this.params);break;case"d":this.linePosAbsolute(this.params);break;case"e":this.VPositionRelative(this.params);break;case"f":this.HVPosition(this.params);break;case"h":this.setMode(this.params);break;case"l":this.resetMode(this.params);break;case"r":this.setScrollRegion(this.params);break;case"s":this.saveCursor(this.params);break;case"u":this.restoreCursor(this.params);break;case"I":this.cursorForwardTab(this.params);break;case"S":this.scrollUp(this.params);break;case"T":this.params.length<2&&!this.prefix&&this.scrollDown(this.params);break;case"Z":this.cursorBackwardTab(this.params);break;case"b":this.repeatPrecedingCharacter(this.params);break;case"g":this.tabClear(this.params);break;case"p":switch(this.prefix){case"!":this.softReset(this.params)}break;default:this.error("Unknown CSI code: %s.",s)}this.prefix="",this.postfix="";break;case E:if("\e"===s||"\a"===s){switch("\e"===s&&c++,this.prefix){case"":break;case"$q":var u=this.currentParam,f=!1;switch(u){case'"q':u='0"q';break;case'"p':u='61"p';break;case"r":u=""+(this.scrollTop+1)+";"+(this.scrollBottom+1)+"r";break;case"m":u="0m";break;default:this.error("Unknown DCS Pt: %s.",u),u=""}this.send("\eP"+ +f+"$r"+u+"\e\\");break;case"+p":break;case"+q":var u=this.currentParam,f=!1;this.send("\eP"+ +f+"+r"+u+"\e\\");break;default:this.error("Unknown DCS prefix: %s.",this.prefix)}this.currentParam=0,this.prefix="",this.state=g}else this.currentParam?this.currentParam+=s:this.prefix||"$"===s||"+"===s?2===this.prefix.length?this.currentParam=s:this.prefix+=s:this.currentParam=s;break;case M:"\e"!==s&&"\a"!==s||("\e"===s&&c++,this.state=g)}}this.updateRange(this.y),this.refresh(this.refreshStart,this.refreshEnd)},r.prototype.writeln=function(t){this.write(t+"\r\n")},r.prototype.attachCustomKeydownHandler=function(t){this.customKeydownHandler=t},r.prototype.keyDown=function(t){if(this.customKeydownHandler&&this.customKeydownHandler(t)===!1)return!1;if(!this.compositionHelper.keydown.bind(this.compositionHelper)(t))return this.ybase!==this.ydisp&&this.scrollToBottom(),!1;var e=this.evaluateKeyEscapeSequence(t);return e.scrollDisp?(this.scrollDisp(e.scrollDisp),this.cancel(t,!0)):!!l(this,t)||(e.cancel&&this.cancel(t,!0),!e.key||(this.emit("keydown",t),this.emit("key",e.key,t),this.showCursor(),this.handler(e.key),this.cancel(t,!0)))},r.prototype.evaluateKeyEscapeSequence=function(t){var e={cancel:!1,key:void 0,scrollDisp:void 0},s=t.shiftKey<<0|t.altKey<<1|t.ctrlKey<<2|t.metaKey<<3;switch(t.keyCode){case 8:if(t.shiftKey){e.key="\b";break}e.key="\7f";break;case 9:if(t.shiftKey){e.key="\e[Z";break}e.key="\t",e.cancel=!0;break;case 13:e.key="\r",e.cancel=!0;break;case 27:e.key="\e",e.cancel=!0;break;case 37:s?(e.key="\e[1;"+(s+1)+"D","\e[1;3D"==e.key&&(e.key="\e[1;5D")):this.applicationCursor?e.key="\eOD":e.key="\e[D";break;case 39:s?(e.key="\e[1;"+(s+1)+"C","\e[1;3C"==e.key&&(e.key="\e[1;5C")):this.applicationCursor?e.key="\eOC":e.key="\e[C";break;case 38:s?(e.key="\e[1;"+(s+1)+"A","\e[1;3A"==e.key&&(e.key="\e[1;5A")):this.applicationCursor?e.key="\eOA":e.key="\e[A";break;case 40:s?(e.key="\e[1;"+(s+1)+"B","\e[1;3B"==e.key&&(e.key="\e[1;5B")):this.applicationCursor?e.key="\eOB":e.key="\e[B";break;case 45:t.shiftKey||t.ctrlKey||(e.key="\e[2~");break;case 46:s?e.key="\e[3;"+(s+1)+"~":e.key="\e[3~";break;case 36:s?e.key="\e[1;"+(s+1)+"H":this.applicationCursor?e.key="\eOH":e.key="\e[H";break;case 35:s?e.key="\e[1;"+(s+1)+"F":this.applicationCursor?e.key="\eOF":e.key="\e[F";
 break;case 33:t.shiftKey?e.scrollDisp=-(this.rows-1):e.key="\e[5~";break;case 34:t.shiftKey?e.scrollDisp=this.rows-1:e.key="\e[6~";break;case 112:s?e.key="\e[1;"+(s+1)+"P":e.key="\eOP";break;case 113:s?e.key="\e[1;"+(s+1)+"Q":e.key="\eOQ";break;case 114:s?e.key="\e[1;"+(s+1)+"R":e.key="\eOR";break;case 115:s?e.key="\e[1;"+(s+1)+"S":e.key="\eOS";break;case 116:s?e.key="\e[15;"+(s+1)+"~":e.key="\e[15~";break;case 117:s?e.key="\e[17;"+(s+1)+"~":e.key="\e[17~";break;case 118:s?e.key="\e[18;"+(s+1)+"~":e.key="\e[18~";break;case 119:s?e.key="\e[19;"+(s+1)+"~":e.key="\e[19~";break;case 120:s?e.key="\e[20;"+(s+1)+"~":e.key="\e[20~";break;case 121:s?e.key="\e[21;"+(s+1)+"~":e.key="\e[21~";break;case 122:s?e.key="\e[23;"+(s+1)+"~":e.key="\e[23~";break;case 123:s?e.key="\e[24;"+(s+1)+"~":e.key="\e[24~";break;default:!t.ctrlKey||t.shiftKey||t.altKey||t.metaKey?this.browser.isMac||!t.altKey||t.ctrlKey||t.metaKey||(t.keyCode>=65&&t.keyCode<=90?e.key="\e"+String.fromCharCode(t.keyCode+32):192===t.keyCode?e.key="\e`":t.keyCode>=48&&t.keyCode<=57&&(e.key="\e"+(t.keyCode-48))):t.keyCode>=65&&t.keyCode<=90?e.key=String.fromCharCode(t.keyCode-64):32===t.keyCode?e.key=String.fromCharCode(0):t.keyCode>=51&&t.keyCode<=55?e.key=String.fromCharCode(t.keyCode-51+27):56===t.keyCode?e.key=String.fromCharCode(127):219===t.keyCode?e.key=String.fromCharCode(27):220===t.keyCode?e.key=String.fromCharCode(28):221===t.keyCode&&(e.key=String.fromCharCode(29))}return e},r.prototype.setgLevel=function(t){this.glevel=t,this.charset=this.charsets[t]},r.prototype.setgCharset=function(t,e){this.charsets[t]=e,this.glevel===t&&(this.charset=e)},r.prototype.keyPress=function(t){var e;if(this.cancel(t),t.charCode)e=t.charCode;else if(null==t.which)e=t.keyCode;else{if(0===t.which||0===t.charCode)return!1;e=t.which}return!(!e||(t.altKey||t.ctrlKey||t.metaKey)&&!l(this,t))&&(e=String.fromCharCode(e),this.emit("keypress",e,t),this.emit("key",e,t),this.showCursor(),this.handler(e),!1)},r.prototype.send=function(t){var e=this;this.queue||setTimeout(function(){e.handler(e.queue),e.queue=""},1),this.queue+=t},r.prototype.bell=function(){if(this.visualBell){var t=this;this.element.style.borderColor="white",setTimeout(function(){t.element.style.borderColor=""},10),this.popOnBell&&this.focus()}},r.prototype.log=function(){if(this.debug&&this.context.console&&this.context.console.log){var t=Array.prototype.slice.call(arguments);this.context.console.log.apply(this.context.console,t)}},r.prototype.error=function(){if(this.debug&&this.context.console&&this.context.console.error){var t=Array.prototype.slice.call(arguments);this.context.console.error.apply(this.context.console,t)}},r.prototype.resize=function(t,e){var s,i,r,o,a;if(t!==this.cols||e!==this.rows){if(t<1&&(t=1),e<1&&(e=1),r=this.cols,r<t)for(o=[this.defAttr," ",1],i=this.lines.length;i--;)for(;this.lines[i].length<t;)this.lines[i].push(o);else for(i=this.lines.length;i--;)for(;this.lines[i].length>t;)this.lines[i].pop();if(this.setupStops(r),this.cols=t,r=this.rows,a=0,r<e)for(s=this.element;r++<e;)this.lines.length<e+this.ybase&&(this.ybase>0&&this.lines.length<=this.ybase+this.y+a+1?(this.ybase--,a++,this.ydisp>0&&this.ydisp--):this.lines.push(this.blankLine())),this.children.length<e&&this.insertRow();else for(;r-- >e;)if(this.lines.length>e+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++)),this.children.length>e){if(s=this.children.shift(),!s)continue;s.parentNode.removeChild(s)}this.rows=e,this.y>=e&&(this.y=e-1),a&&(this.y+=a),this.x>=t&&(this.x=t-1),this.scrollTop=0,this.scrollBottom=e-1,this.refresh(0,this.rows-1),this.normal=null,this.geometry=[this.cols,this.rows],this.emit("resize",{terminal:this,cols:t,rows:e})}},r.prototype.updateRange=function(t){t<this.refreshStart&&(this.refreshStart=t),t>this.refreshEnd&&(this.refreshEnd=t)},r.prototype.maxRange=function(){this.refreshStart=0,this.refreshEnd=this.rows-1},r.prototype.setupStops=function(t){for(null!=t?this.tabs[t]||(t=this.prevStop(t)):(this.tabs={},t=0);t<this.cols;t+=8)this.tabs[t]=!0},r.prototype.prevStop=function(t){for(null==t&&(t=this.x);!this.tabs[--t]&&t>0;);return t>=this.cols?this.cols-1:t<0?0:t},r.prototype.nextStop=function(t){for(null==t&&(t=this.x);!this.tabs[++t]&&t<this.cols;);return t>=this.cols?this.cols-1:t<0?0:t},r.prototype.eraseRight=function(t,e){for(var s=this.lines[this.ybase+e],i=[this.eraseAttr()," ",1];t<this.cols;t++)s[t]=i;this.updateRange(e)},r.prototype.eraseLeft=function(t,e){var s=this.lines[this.ybase+e],i=[this.eraseAttr()," ",1];for(t++;t--;)s[t]=i;this.updateRange(e)},r.prototype.clear=function(){if(0!==this.ybase||0!==this.y){this.lines=[this.lines[this.ybase+this.y]],this.ydisp=0,this.ybase=0,this.y=0;for(var t=1;t<this.rows;t++)this.lines.push(this.blankLine());this.refresh(0,this.rows-1),this.emit("scroll",this.ydisp)}},r.prototype.eraseLine=function(t){this.eraseRight(0,t)},r.prototype.blankLine=function(t){for(var e=t?this.eraseAttr():this.defAttr,s=[e," ",1],i=[],r=0;r<this.cols;r++)i[r]=s;return i},r.prototype.ch=function(t){return t?[this.eraseAttr()," ",1]:[this.defAttr," ",1]},r.prototype.is=function(t){var e=this.termName;return 0===(e+"").indexOf(t)},r.prototype.handler=function(t){this.ybase!==this.ydisp&&this.scrollToBottom(),this.emit("data",t)},r.prototype.handleTitle=function(t){this.emit("title",t)},r.prototype.index=function(){this.y++,this.y>this.scrollBottom&&(this.y--,this.scroll()),this.state=g},r.prototype.reverseIndex=function(){var t;this.y--,this.y<this.scrollTop&&(this.y++,this.lines.splice(this.y+this.ybase,0,this.blankLine(!0)),t=this.rows-1-this.scrollBottom,this.lines.splice(this.rows-1+this.ybase-t+1,1),this.updateRange(this.scrollTop),this.updateRange(this.scrollBottom)),this.state=g},r.prototype.reset=function(){this.options.rows=this.rows,this.options.cols=this.cols;var t=this.customKeydownHandler;r.call(this,this.options),this.customKeydownHandler=t,this.refresh(0,this.rows-1),this.viewport.syncScrollArea()},r.prototype.tabSet=function(){this.tabs[this.x]=!0,this.state=g},r.prototype.cursorUp=function(t){var e=t[0];e<1&&(e=1),this.y-=e,this.y<0&&(this.y=0)},r.prototype.cursorDown=function(t){var e=t[0];e<1&&(e=1),this.y+=e,this.y>=this.rows&&(this.y=this.rows-1)},r.prototype.cursorForward=function(t){var e=t[0];e<1&&(e=1),this.x+=e,this.x>=this.cols&&(this.x=this.cols-1)},r.prototype.cursorBackward=function(t){var e=t[0];e<1&&(e=1),this.x-=e,this.x<0&&(this.x=0)},r.prototype.cursorPos=function(t){var e,s;e=t[0]-1,s=t.length>=2?t[1]-1:0,e<0?e=0:e>=this.rows&&(e=this.rows-1),s<0?s=0:s>=this.cols&&(s=this.cols-1),this.x=s,this.y=e},r.prototype.eraseInDisplay=function(t){var e;switch(t[0]){case 0:for(this.eraseRight(this.x,this.y),e=this.y+1;e<this.rows;e++)this.eraseLine(e);break;case 1:for(this.eraseLeft(this.x,this.y),e=this.y;e--;)this.eraseLine(e);break;case 2:for(e=this.rows;e--;)this.eraseLine(e);break;case 3:}},r.prototype.eraseInLine=function(t){switch(t[0]){case 0:this.eraseRight(this.x,this.y);break;case 1:this.eraseLeft(this.x,this.y);break;case 2:this.eraseLine(this.y)}},r.prototype.charAttributes=function(t){if(1===t.length&&0===t[0])return void(this.curAttr=this.defAttr);for(var e,s=t.length,i=0,r=this.curAttr>>18,o=this.curAttr>>9&511,a=511&this.curAttr;i<s;i++)e=t[i],e>=30&&e<=37?o=e-30:e>=40&&e<=47?a=e-40:e>=90&&e<=97?(e+=8,o=e-90):e>=100&&e<=107?(e+=8,a=e-100):0===e?(r=this.defAttr>>18,o=this.defAttr>>9&511,a=511&this.defAttr):1===e?r|=1:4===e?r|=2:5===e?r|=4:7===e?r|=8:8===e?r|=16:22===e?r&=-2:24===e?r&=-3:25===e?r&=-5:27===e?r&=-9:28===e?r&=-17:39===e?o=this.defAttr>>9&511:49===e?a=511&this.defAttr:38===e?2===t[i+1]?(i+=2,o=p(255&t[i],255&t[i+1],255&t[i+2]),o===-1&&(o=511),i+=2):5===t[i+1]&&(i+=2,e=255&t[i],o=e):48===e?2===t[i+1]?(i+=2,a=p(255&t[i],255&t[i+1],255&t[i+2]),a===-1&&(a=511),i+=2):5===t[i+1]&&(i+=2,e=255&t[i],a=e):100===e?(o=this.defAttr>>9&511,a=511&this.defAttr):this.error("Unknown SGR attribute: %d.",e);this.curAttr=r<<18|o<<9|a},r.prototype.deviceStatus=function(t){if(this.prefix){if("?"===this.prefix)switch(t[0]){case 6:this.send("\e[?"+(this.y+1)+";"+(this.x+1)+"R");break;case 15:break;case 25:break;case 26:break;case 53:}}else switch(t[0]){case 5:this.send("\e[0n");break;case 6:this.send("\e["+(this.y+1)+";"+(this.x+1)+"R")}},r.prototype.insertChars=function(t){var e,s,i,r;for(e=t[0],e<1&&(e=1),s=this.y+this.ybase,i=this.x,r=[this.eraseAttr()," ",1];e--&&i<this.cols;)this.lines[s].splice(i++,0,r),this.lines[s].pop()},r.prototype.cursorNextLine=function(t){var e=t[0];e<1&&(e=1),this.y+=e,this.y>=this.rows&&(this.y=this.rows-1),this.x=0},r.prototype.cursorPrecedingLine=function(t){var e=t[0];e<1&&(e=1),this.y-=e,this.y<0&&(this.y=0),this.x=0},r.prototype.cursorCharAbsolute=function(t){var e=t[0];e<1&&(e=1),this.x=e-1},r.prototype.insertLines=function(t){var e,s,i;for(e=t[0],e<1&&(e=1),s=this.y+this.ybase,i=this.rows-1-this.scrollBottom,i=this.rows-1+this.ybase-i+1;e--;)this.lines.splice(s,0,this.blankLine(!0)),this.lines.splice(i,1);this.updateRange(this.y),this.updateRange(this.scrollBottom)},r.prototype.deleteLines=function(t){var e,s,i;for(e=t[0],e<1&&(e=1),s=this.y+this.ybase,i=this.rows-1-this.scrollBottom,i=this.rows-1+this.ybase-i;e--;)this.lines.splice(i+1,0,this.blankLine(!0)),this.lines.splice(s,1);this.updateRange(this.y),this.updateRange(this.scrollBottom)},r.prototype.deleteChars=function(t){var e,s,i;for(e=t[0],e<1&&(e=1),s=this.y+this.ybase,i=[this.eraseAttr()," ",1];e--;)this.lines[s].splice(this.x,1),this.lines[s].push(i)},r.prototype.eraseChars=function(t){var e,s,i,r;for(e=t[0],e<1&&(e=1),s=this.y+this.ybase,i=this.x,r=[this.eraseAttr()," ",1];e--&&i<this.cols;)this.lines[s][i++]=r},r.prototype.charPosAbsolute=function(t){var e=t[0];e<1&&(e=1),this.x=e-1,this.x>=this.cols&&(this.x=this.cols-1)},r.prototype.HPositionRelative=function(t){var e=t[0];e<1&&(e=1),this.x+=e,this.x>=this.cols&&(this.x=this.cols-1)},r.prototype.sendDeviceAttributes=function(t){t[0]>0||(this.prefix?">"===this.prefix&&(this.is("xterm")?this.send("\e[>0;276;0c"):this.is("rxvt-unicode")?this.send("\e[>85;95;0c"):this.is("linux")?this.send(t[0]+"c"):this.is("screen")&&this.send("\e[>83;40003;0c")):this.is("xterm")||this.is("rxvt-unicode")||this.is("screen")?this.send("\e[?1;2c"):this.is("linux")&&this.send("\e[?6c"))},r.prototype.linePosAbsolute=function(t){var e=t[0];e<1&&(e=1),this.y=e-1,this.y>=this.rows&&(this.y=this.rows-1)},r.prototype.VPositionRelative=function(t){var e=t[0];e<1&&(e=1),this.y+=e,this.y>=this.rows&&(this.y=this.rows-1)},r.prototype.HVPosition=function(t){t[0]<1&&(t[0]=1),t[1]<1&&(t[1]=1),this.y=t[0]-1,this.y>=this.rows&&(this.y=this.rows-1),this.x=t[1]-1,this.x>=this.cols&&(this.x=this.cols-1)},r.prototype.setMode=function(t){if("object"!=typeof t)if(this.prefix){if("?"===this.prefix)switch(t){case 1:this.applicationCursor=!0;break;case 2:this.setgCharset(0,r.charsets.US),this.setgCharset(1,r.charsets.US),this.setgCharset(2,r.charsets.US),this.setgCharset(3,r.charsets.US);break;case 3:this.savedCols=this.cols,this.resize(132,this.rows);break;case 6:this.originMode=!0;break;case 7:this.wraparoundMode=!0;break;case 12:break;case 66:this.log("Serial port requested application keypad."),this.applicationKeypad=!0,this.viewport.syncScrollArea();break;case 9:case 1e3:case 1002:case 1003:this.x10Mouse=9===t,this.vt200Mouse=1e3===t,this.normalMouse=t>1e3,this.mouseEvents=!0,this.element.style.cursor="default",this.log("Binding to mouse events.");break;case 1004:this.sendFocus=!0;break;case 1005:this.utfMouse=!0;break;case 1006:this.sgrMouse=!0;break;case 1015:this.urxvtMouse=!0;break;case 25:this.cursorHidden=!1;break;case 1049:case 47:case 1047:if(!this.normal){var e={lines:this.lines,ybase:this.ybase,ydisp:this.ydisp,x:this.x,y:this.y,scrollTop:this.scrollTop,scrollBottom:this.scrollBottom,tabs:this.tabs};this.reset(),this.normal=e,this.showCursor()}}}else switch(t){case 4:this.insertMode=!0;break;case 20:}else for(var s=t.length,i=0;i<s;i++)this.setMode(t[i])},r.prototype.resetMode=function(t){if("object"!=typeof t)if(this.prefix){if("?"===this.prefix)switch(t){case 1:this.applicationCursor=!1;break;case 3:132===this.cols&&this.savedCols&&this.resize(this.savedCols,this.rows),delete this.savedCols;break;case 6:this.originMode=!1;break;case 7:this.wraparoundMode=!1;break;case 12:break;case 66:this.log("Switching back to normal keypad."),this.applicationKeypad=!1,this.viewport.syncScrollArea();break;case 9:case 1e3:case 1002:case 1003:this.x10Mouse=!1,this.vt200Mouse=!1,this.normalMouse=!1,this.mouseEvents=!1,this.element.style.cursor="";break;case 1004:this.sendFocus=!1;break;case 1005:this.utfMouse=!1;break;case 1006:this.sgrMouse=!1;break;case 1015:this.urxvtMouse=!1;break;case 25:this.cursorHidden=!0;break;case 1049:case 47:case 1047:this.normal&&(this.lines=this.normal.lines,this.ybase=this.normal.ybase,this.ydisp=this.normal.ydisp,this.x=this.normal.x,this.y=this.normal.y,this.scrollTop=this.normal.scrollTop,this.scrollBottom=this.normal.scrollBottom,this.tabs=this.normal.tabs,this.normal=null,this.refresh(0,this.rows-1),this.showCursor())}}else switch(t){case 4:this.insertMode=!1;break;case 20:}else for(var e=t.length,s=0;s<e;s++)this.resetMode(t[s])},r.prototype.setScrollRegion=function(t){this.prefix||(this.scrollTop=(t[0]||1)-1,this.scrollBottom=(t[1]||this.rows)-1,this.x=0,this.y=0)},r.prototype.saveCursor=function(t){this.savedX=this.x,this.savedY=this.y},r.prototype.restoreCursor=function(t){this.x=this.savedX||0,this.y=this.savedY||0},r.prototype.cursorForwardTab=function(t){for(var e=t[0]||1;e--;)this.x=this.nextStop()},r.prototype.scrollUp=function(t){for(var e=t[0]||1;e--;)this.lines.splice(this.ybase+this.scrollTop,1),this.lines.splice(this.ybase+this.scrollBottom,0,this.blankLine());this.updateRange(this.scrollTop),this.updateRange(this.scrollBottom)},r.prototype.scrollDown=function(t){for(var e=t[0]||1;e--;)this.lines.splice(this.ybase+this.scrollBottom,1),this.lines.splice(this.ybase+this.scrollTop,0,this.blankLine());this.updateRange(this.scrollTop),this.updateRange(this.scrollBottom)},r.prototype.initMouseTracking=function(t){},r.prototype.resetTitleModes=function(t){},r.prototype.cursorBackwardTab=function(t){for(var e=t[0]||1;e--;)this.x=this.prevStop()},r.prototype.repeatPrecedingCharacter=function(t){for(var e=t[0]||1,s=this.lines[this.ybase+this.y],i=s[this.x-1]||[this.defAttr," ",1];e--;)s[this.x++]=i},r.prototype.tabClear=function(t){var e=t[0];e<=0?delete this.tabs[this.x]:3===e&&(this.tabs={})},r.prototype.mediaCopy=function(t){},r.prototype.setResources=function(t){},r.prototype.disableModifiers=function(t){},r.prototype.setPointerMode=function(t){},r.prototype.softReset=function(t){this.cursorHidden=!1,this.insertMode=!1,this.originMode=!1,this.wraparoundMode=!1,this.applicationKeypad=!1,this.viewport.syncScrollArea(),this.applicationCursor=!1,this.scrollTop=0,this.scrollBottom=this.rows-1,this.curAttr=this.defAttr,this.x=this.y=0,this.charset=null,this.glevel=0,this.charsets=[null]},r.prototype.requestAnsiMode=function(t){},r.prototype.requestPrivateMode=function(t){},r.prototype.setConformanceLevel=function(t){},r.prototype.loadLEDs=function(t){},r.prototype.setCursorStyle=function(t){},r.prototype.setCharProtectionAttr=function(t){},r.prototype.restorePrivateValues=function(t){},r.prototype.setAttrInRectangle=function(t){for(var e,s,i=t[0],r=t[1],o=t[2],a=t[3],h=t[4];i<o+1;i++)for(e=this.lines[this.ybase+i],s=r;s<a;s++)e[s]=[h,e[s][1]];this.updateRange(t[0]),this.updateRange(t[2])},r.prototype.fillRectangle=function(t){for(var e,s,i=t[0],r=t[1],o=t[2],a=t[3],h=t[4];r<a+1;r++)for(e=this.lines[this.ybase+r],s=o;s<h;s++)e[s]=[e[s][0],String.fromCharCode(i)];this.updateRange(t[1]),this.updateRange(t[3])},r.prototype.enableLocatorReporting=function(t){t[0]>0},r.prototype.eraseRectangle=function(t){var e,s,i,r=t[0],o=t[1],a=t[2],h=t[3];for(i=[this.eraseAttr()," ",1];r<a+1;r++)for(e=this.lines[this.ybase+r],s=o;s<h;s++)e[s]=i;this.updateRange(t[0]),this.updateRange(t[2])},r.prototype.insertColumns=function(){for(var t,e=params[0],s=this.ybase+this.rows,i=[this.eraseAttr()," ",1];e--;)for(t=this.ybase;t<s;t++)this.lines[t].splice(this.x+1,0,i),this.lines[t].pop();this.maxRange()},r.prototype.deleteColumns=function(){for(var t,e=params[0],s=this.ybase+this.rows,i=[this.eraseAttr()," ",1];e--;)for(t=this.ybase;t<s;t++)this.lines[t].splice(this.x,1),this.lines[t].push(i);this.maxRange()},r.charsets={},r.charsets.SCLD={"`":"◆",a:"▒",b:"\t",c:"\f",d:"\r",e:"\n",f:"°",g:"±",h:"␤",i:"\v",j:"┘",k:"┐",l:"┌",m:"└",n:"┼",o:"⎺",p:"⎻",q:"─",r:"⎼",s:"⎽",t:"├",u:"┤",v:"┴",w:"┬",x:"│",y:"≤",z:"≥","{":"π","|":"≠","}":"£","~":"·"},r.charsets.UK=null,r.charsets.US=null,r.charsets.Dutch=null,r.charsets.Finnish=null,r.charsets.French=null,r.charsets.FrenchCanadian=null,r.charsets.German=null,r.charsets.Italian=null,r.charsets.NorwegianDanish=null,r.charsets.Spanish=null,r.charsets.Swedish=null,r.charsets.Swiss=null,r.charsets.ISOLatin=null,p._cache={},p.distance=function(t,e,s,i,r,o){return Math.pow(30*(t-i),2)+Math.pow(59*(e-r),2)+Math.pow(11*(s-o),2)};var A=function(t){function e(t){var e,s=0,r=i.length-1;if(t<i[0][0]||t>i[r][1])return!1;for(;r>=s;)if(e=Math.floor((s+r)/2),t>i[e][1])s=e+1;else{if(!(t<i[e][0]))return!0;r=e-1}return!1}function s(s){return 0===s?t.nul:s<32||s>=127&&s<160?t.control:e(s)?0:1+(s>=4352&&(s<=4447||9001==s||9002==s||s>=11904&&s<=42191&&12351!=s||s>=44032&&s<=55203||s>=63744&&s<=64255||s>=65040&&s<=65049||s>=65072&&s<=65135||s>=65280&&s<=65376||s>=65504&&s<=65510||s>=131072&&s<=196605||s>=196608&&s<=262141))}var i=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531],[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]];return s}({nul:0,control:0});r.EventEmitter=y.EventEmitter,r.inherits=n,r.on=o,r.off=a,r.cancel=h,s.exports=r},{"./CompositionHelper.js":1,"./EventEmitter.js":2,"./Viewport.js":3,"./handlers/Clipboard.js":4,"./utils/Browser":5}]},{},[7])(7)});</script>
     <script>!function(e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("../../xterm")):"function"==typeof define?define(["../../xterm"],e):e(window.Terminal)}(function(e){var t={};return t.proposeGeometry=function(e){var t,r,n,o,i,p=window.getComputedStyle(e.element.parentElement),a=parseInt(p.getPropertyValue("height")),s=Math.max(0,parseInt(p.getPropertyValue("width"))-17),l=window.getComputedStyle(e.element),d=parseInt(l.getPropertyValue("padding-top"))+parseInt(l.getPropertyValue("padding-bottom")),u=parseInt(l.getPropertyValue("padding-right"))+parseInt(l.getPropertyValue("padding-left")),y=a-d,f=s-u,g=(e.rowContainer,e.rowContainer.firstElementChild),m=g.innerHTML;return g.style.display="inline",g.innerHTML="W",n=g.getBoundingClientRect().width,g.style.display="",t=parseInt(g.offsetHeight),g.innerHTML=m,r=parseInt(y/t),o=parseInt(f/n),i={cols:o,rows:r}},t.fit=function(e){var r=t.proposeGeometry(e);e.resize(r.cols,r.rows)},e.prototype.proposeGeometry=function(){return t.proposeGeometry(this)},e.prototype.fit=function(){return t.fit(this)},t});</script>
+    <script>UTF8Decoder=function(){this.bytesLeft=0,this.codePoint=0,this.lowerBound=0},UTF8Decoder.prototype.decode=function(t){for(var e="",o=0;o<t.length;o++){var i=t.charCodeAt(o);if(0==this.bytesLeft)i<=127?e+=t.charAt(o):192<=i&&i<=223?(this.codePoint=i-192,this.bytesLeft=1,this.lowerBound=128):224<=i&&i<=239?(this.codePoint=i-224,this.bytesLeft=2,this.lowerBound=2048):240<=i&&i<=247?(this.codePoint=i-240,this.bytesLeft=3,this.lowerBound=65536):248<=i&&i<=251?(this.codePoint=i-248,this.bytesLeft=4,this.lowerBound=2097152):252<=i&&i<=253?(this.codePoint=i-252,this.bytesLeft=5,this.lowerBound=67108864):e+="�";else if(128<=i&&i<=191){if(this.bytesLeft--,this.codePoint=(this.codePoint<<6)+(i-128),0==this.bytesLeft){var r=this.codePoint;r<this.lowerBound||55296<=r&&r<=57343||r>1114111?e+="�":r<65536?e+=String.fromCharCode(r):(r-=65536,e+=String.fromCharCode(55296+(r>>>10&1023),56320+(1023&r)))}}else e+="�",this.bytesLeft=0,o--}return e},Terminal.prototype.decodeUTF8=function(t){return(new UTF8Decoder).decode(t)},Terminal.prototype.encodeUTF8=function(t){for(var e="",o=0;o<t.length;o++){var i=t.charCodeAt(o);if(56320<=i&&i<=57343)i=65533;else if(55296<=i&&i<=56319)if(o+1<t.length){var r=t.charCodeAt(o+1);56320<=r&&r<=57343?(i=65536+((1023&i)<<10)+(1023&r),o++):i=65533}else i=65533;var n;if(i<=127)e+=t.charAt(o);else for(i<=2047?(e+=String.fromCharCode(192|i>>>6),n=1):i<=65535?(e+=String.fromCharCode(224|i>>>12),n=2):(e+=String.fromCharCode(240|i>>>18),n=3);n>0;)n--,e+=String.fromCharCode(128|i>>>6*n&63)}return e},Terminal.prototype.writeUTF8=function(t){this.write(this.decodeUTF8(t))};</script>
     <script>Terminal.prototype.showOverlay=function(e,t){if(!this.overlayNode_){if(!this.element)return;this.overlayNode_=document.createElement("div"),this.overlayNode_.style.cssText="border-radius: 15px;font-size: xx-large;opacity: 0.75;padding: 0.2em 0.5em 0.2em 0.5em;position: absolute;-webkit-user-select: none;-webkit-transition: opacity 180ms ease-in;-moz-user-select: none;-moz-transition: opacity 180ms ease-in;",this.overlayNode_.addEventListener("mousedown",function(e){e.preventDefault(),e.stopPropagation()},!0)}this.overlayNode_.style.color="#101010",this.overlayNode_.style.backgroundColor="#f0f0f0",this.overlayNode_.textContent=e,this.overlayNode_.style.opacity="0.75",this.overlayNode_.parentNode||this.element.appendChild(this.overlayNode_);var o=this.element.getBoundingClientRect(),i=this.overlayNode_.getBoundingClientRect();this.overlayNode_.style.top=(o.height-i.height)/2+"px",this.overlayNode_.style.left=(o.width-i.width)/2+"px";var l=this;this.overlayTimeout_&&clearTimeout(this.overlayTimeout_),null!==t&&(this.overlayTimeout_=setTimeout(function(){l.overlayNode_.style.opacity="0",l.overlayTimeout_=setTimeout(function(){l.overlayNode_.parentNode&&l.overlayNode_.parentNode.removeChild(l.overlayNode_),l.overlayTimeout_=null,l.overlayNode_.style.opacity="0.75"},200)},t||1500))};</script>
 </head>
 <body>
        <div id="terminal-container"></div>
        <script src="auth_token.js"></script>
-       <script>!function(){var e,n,o,t=document.getElementById("terminal-container"),s="https:"==window.location.protocol,a=(s?"wss://":"ws://")+window.location.host+window.location.pathname+"ws",i=["tty"],c=-1,r=function(){var s=new WebSocket(a,i);s.onopen=function(a){for(o=!1,"undefined"!=typeof tty_auth_token&&s.send(JSON.stringify({AuthToken:tty_auth_token})),n=setInterval(l,3e4,s),"undefined"!=typeof e&&e.destroy(),e=new Terminal,e.on("resize",function(n){s.readyState===WebSocket.OPEN&&s.send("2"+JSON.stringify({columns:n.cols,rows:n.rows})),setTimeout(function(){e.showOverlay(n.cols+"x"+n.rows)},500)}),e.on("data",function(e){s.readyState===WebSocket.OPEN&&s.send("0"+e)}),window.onresize=function(n){e.fit()};t.firstChild;)t.removeChild(t.firstChild);e.open(t),e.fit(),e.focus()},s.onmessage=function(n){var o=n.data.slice(1);switch(n.data[0]){case"0":e.write(decodeURIComponent(escape(window.atob(o))));break;case"1":break;case"2":document.title=o;break;case"3":var t=JSON.parse(o);Object.keys(t).forEach(function(n){console.log("Setting "+n+": "+t[n]),e.setOption(n,t[n])});break;case"4":c=JSON.parse(o),console.log("Enabling reconnect: "+c+" seconds")}},s.onclose=function(t){e&&(e.off("data"),e.off("resize"),o||e.showOverlay("Connection Closed",null)),clearInterval(n),c>0&&setTimeout(r,1e3*c)},s.onerror=function(n){o=!0,e.showOverlay("Websocket handshake failed",null)}},l=function(e){e.send("1")};r()}();</script>
+       <script>!function(){var e,n,o,t=document.getElementById("terminal-container"),s="https:"==window.location.protocol,a=(s?"wss://":"ws://")+window.location.host+window.location.pathname+"ws",i=["tty"],c=-1,r=function(){var s=new WebSocket(a,i);s.onopen=function(a){for(o=!1,"undefined"!=typeof tty_auth_token&&s.send(JSON.stringify({AuthToken:tty_auth_token})),n=setInterval(l,3e4,s),"undefined"!=typeof e&&e.destroy(),e=new Terminal,e.on("resize",function(n){s.readyState===WebSocket.OPEN&&s.send("2"+JSON.stringify({columns:n.cols,rows:n.rows})),setTimeout(function(){e.showOverlay(n.cols+"x"+n.rows)},500)}),e.on("data",function(e){s.readyState===WebSocket.OPEN&&s.send("0"+e)}),window.onresize=function(n){e.fit()};t.firstChild;)t.removeChild(t.firstChild);e.open(t),e.fit(),e.focus()},s.onmessage=function(n){var o=n.data.slice(1);switch(n.data[0]){case"0":e.writeUTF8(window.atob(o));break;case"1":break;case"2":document.title=o;break;case"3":var t=JSON.parse(o);Object.keys(t).forEach(function(n){console.log("Setting "+n+": "+t[n]),e.setOption(n,t[n])});break;case"4":c=JSON.parse(o),console.log("Enabling reconnect: "+c+" seconds")}},s.onclose=function(t){e&&(e.off("data"),e.off("resize"),o||e.showOverlay("Connection Closed",null)),clearInterval(n),c>0&&setTimeout(r,1e3*c)},s.onerror=function(n){o=!0,e.showOverlay("Websocket handshake failed",null)}},l=function(e){e.send("1")};r()}();</script>
 </body>
-</html>
\ No newline at end of file
+</html>
index be5cd163249cec64f1f1724a5bf0f230395a6d55..180d4958f9993b884ad5684b85ad948144c26bf5 100644 (file)
@@ -37,7 +37,7 @@ uppercase(char *str) {
 }
 
 bool
-endswith(const char * str, const char * suffix) {
+endswith(const char *str, const char *suffix) {
     size_t str_len = strlen(str);
     size_t suffix_len = strlen(suffix);
     return str_len > suffix_len && !strcmp(str + (str_len - suffix_len), suffix);
index 92b639afb126aa3adca5076c8be89be604cc3d8d..ba7525218374ad6d531ef76f526ef026c2071ef4 100644 (file)
@@ -15,7 +15,7 @@ uppercase(char *str);
 
 // Check whether str ends with suffix
 bool
-endswith(const char * str, const char * suffix);
+endswith(const char *str, const char *suffix);
 
 // Get human readable signal string
 int