diff --git a/butterfly/static/ext.js b/butterfly/static/ext.js index dce7fe7..2581470 100644 --- a/butterfly/static/ext.js +++ b/butterfly/static/ext.js @@ -164,30 +164,22 @@ } }); - Terminal.on('change', function(lines) { - var j, len1, line, results; - results = []; - for (j = 0, len1 = lines.length; j < len1; j++) { - line = lines[j]; - if (indexOf.call(line.classList, 'extended') >= 0) { - results.push(line.addEventListener('click', (function(line) { - return function() { - var after, before; - if (indexOf.call(line.classList, 'expanded') >= 0) { - return line.classList.remove('expanded'); - } else { - before = line.getBoundingClientRect().height; - line.classList.add('expanded'); - after = line.getBoundingClientRect().height; - return document.body.scrollTop += after - before; - } - }; - })(line))); - } else { - results.push(void 0); - } + Terminal.on('change', function(line) { + if (indexOf.call(line.classList, 'extended') >= 0) { + return line.addEventListener('click', (function(line) { + return function() { + var after, before; + if (indexOf.call(line.classList, 'expanded') >= 0) { + return line.classList.remove('expanded'); + } else { + before = line.getBoundingClientRect().height; + line.classList.add('expanded'); + after = line.getBoundingClientRect().height; + return document.body.scrollTop += after - before; + } + }; + })(line)); } - return results; }); walk = function(node, callback) { @@ -210,25 +202,19 @@ return text.replace(urlPattern, '$&').replace(pseudoUrlPattern, '$1$2').replace(emailAddressPattern, '$&'); }; - Terminal.on('change', function(lines) { - var j, len1, line, results; - results = []; - for (j = 0, len1 = lines.length; j < len1; j++) { - line = lines[j]; - results.push(walk(line, function() { - var linkified, newNode; - if (this.nodeType === 3) { - linkified = linkify(this.nodeValue); - if (linkified !== this.nodeValue) { - newNode = document.createElement('span'); - newNode.innerHTML = linkified; - this.parentElement.replaceChild(newNode, this); - return true; - } + Terminal.on('change', function(line) { + return walk(line, function() { + var linkified, newNode; + if (this.nodeType === 3) { + linkified = linkify(this.nodeValue); + if (linkified !== this.nodeValue) { + newNode = document.createElement('span'); + newNode.innerHTML = linkified; + this.parentElement.replaceChild(newNode, this); + return true; } - })); - } - return results; + } + }); }); document.addEventListener('keydown', function(e) { diff --git a/butterfly/static/ext.min.js b/butterfly/static/ext.min.js index 2139d64..c717acc 100644 --- a/butterfly/static/ext.min.js +++ b/butterfly/static/ext.min.js @@ -1,4 +1,4 @@ -/*! butterfly 2016-10-11 */ +/*! butterfly 2016-10-12 */ (function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};g=function(a){var b,c,d,e;if(a.indexOf("")<0)return a;for(c=-1,d="",e="normal";c=0&&c++,e="normal";break;case"csi":if("?>!$\" '".indexOf(b)>=0)break;if(b>="0"&&"9">=b)break;if(";"===b)break;e="normal";break;case"osc":""!==b&&""!==b||(""===b&&c++,e="normal")}return d},p=function(a,b){var c;return c=function(d){var e,f,h;return e=g(d.data.slice(1)),null===b||b.test(e)?(butterfly.body.classList.remove("alarm"),f="Butterfly ["+butterfly.title+"]",a?(h=new Notification(f,{body:e,icon:"/static/images/favicon.png"}),h.onclick=function(){return window.focus(),h.close()}):alert(f+"\n"+e),butterfly.ws.shell.removeEventListener("message",c)):void 0},butterfly.ws.shell.addEventListener("message",c),butterfly.body.classList.add("alarm")},f=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},document.addEventListener("keydown",function(a){var b;if(!a.altKey||65!==a.keyCode)return!0;if(b=null,a.shiftKey){if(b=prompt("Ring alarm when encountering the following text: (can be a regexp)"),!b)return;b=new RegExp(b)}return Notification&&"default"===Notification.permission?Notification.requestPermission(function(){return p("granted"===Notification.permission,b)}):p("granted"===Notification.permission,b),f(a)}),addEventListener("copy",h=function(a){var b,c,d,e,f,g,h;for(butterfly.bell("copied"),a.clipboardData.clearData(),h=getSelection().toString().replace(/\u00A0/g," ").replace(/\u2007/g," "),b="",g=h.split("\n"),d=0,e=g.length;e>d;d++)f=g[d],"⏎"===f.slice(-1)?(c="",f=f.slice(0,-1)):c="\n",b+=f.replace(/\s*$/,"")+c;return a.clipboardData.setData("text/plain",b.slice(0,-1)),a.preventDefault()}),addEventListener("paste",function(a){var b,c,d;return butterfly.bell("pasted"),b=a.clipboardData.getData("text/plain"),b=b.replace(/\r\n/g,"\n").replace(/\n/g,"\r"),d=1024,c=function(){return butterfly.send(b.substring(0,d)),b=b.substring(d),b.length?setTimeout(c,25):void 0},c(),a.preventDefault()}),addEventListener("beforeunload",function(a){return butterfly.body.classList.contains("dead")||location.href.indexOf("session")>-1?void 0:a.returnValue="This terminal is active and not in session. Are you sure you want to kill it?"}),Terminal.on("change",function(a){var b,c,d,e;for(e=[],b=0,c=a.length;c>b;b++)d=a[b],s.call(d.classList,"extended")>=0?e.push(d.addEventListener("click",function(a){return function(){var b,c;return s.call(a.classList,"expanded")>=0?a.classList.remove("expanded"):(c=a.getBoundingClientRect().height,a.classList.add("expanded"),b=a.getBoundingClientRect().height,document.body.scrollTop+=b-c)}}(d))):e.push(void 0);return e}),r=function(a,b){var c,d,e,f,g;for(f=a.childNodes,g=[],d=0,e=f.length;e>d;d++)c=f[d],b.call(c),g.push(r(c,b));return g},k=function(a){var b,c,d;return d=/\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim,c=/(^|[^\/])(www\.[\S]+(\b|$))/gim,b=/[\w.]+@[a-zA-Z_-]+?(?:\.[a-zA-Z]{2,6})+/gim,a.replace(d,'$&').replace(c,'$1$2').replace(b,'$&')},Terminal.on("change",function(a){var b,c,d,e;for(e=[],b=0,c=a.length;c>b;b++)d=a[b],e.push(r(d,function(){var a,b;return 3===this.nodeType&&(a=k(this.nodeValue),a!==this.nodeValue)?(b=document.createElement("span"),b.innerHTML=a,this.parentElement.replaceChild(b,this),!0):void 0}));return e}),document.addEventListener("keydown",function(a){return a.altKey&&79===a.keyCode?(open(location.href),f(a)):!0}),a=function(){function a(){this.el=document.getElementById("popup"),this.bound_click_maybe_close=this.click_maybe_close.bind(this),this.bound_key_maybe_close=this.key_maybe_close.bind(this)}return a.prototype.open=function(a){return this.el.innerHTML=a,this.el.classList.remove("hidden"),"undefined"!=typeof InstallTrigger&&(document.body.contentEditable="false"),addEventListener("click",this.bound_click_maybe_close),addEventListener("keydown",this.bound_key_maybe_close)},a.prototype.close=function(){return removeEventListener("click",this.bound_click_maybe_close),removeEventListener("keydown",this.bound_key_maybe_close),"undefined"!=typeof InstallTrigger&&(document.body.contentEditable="true"),this.el.classList.add("hidden"),this.el.innerHTML=""},a.prototype.click_maybe_close=function(a){var b;for(b=a.target;b.parentElement;){if(Array.prototype.slice.call(this.el.children).indexOf(b)>-1)return!0;b=b.parentElement}return this.close(),f(a)},a.prototype.key_maybe_close=function(a){return 27!==a.keyCode?!0:(this.close(),f(a))},a}(),m=new a,o=null,f=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},n=function(a){var b;for(b=a.previousSibling,b||(b=a.parentNode.previousSibling),b||(b=a.parentNode.parentNode.previousSibling);b.lastChild;)b=b.lastChild;return b},l=function(a){var b;for(b=a.nextSibling,b||(b=a.parentNode.nextSibling),b||(b=a.parentNode.parentNode.nextSibling);null!=b?b.firstChild:void 0;)b=b.firstChild;return b},b=function(){function a(){butterfly.body.classList.add("selection"),this.selection=getSelection()}return a.prototype.reset=function(){var a,b,c;for(this.selection=getSelection(),a=document.createRange(),a.setStart(this.selection.anchorNode,this.selection.anchorOffset),a.setEnd(this.selection.focusNode,this.selection.focusOffset),this.start={node:this.selection.anchorNode,offset:this.selection.anchorOffset},this.end={node:this.selection.focusNode,offset:this.selection.focusOffset},a.collapsed&&(b=[this.end,this.start],this.start=b[0],this.end=b[1]),this.startLine=this.start.node;!this.startLine.classList||s.call(this.startLine.classList,"line")<0;)this.startLine=this.startLine.parentNode;for(this.endLine=this.end.node,c=[];!this.endLine.classList||s.call(this.endLine.classList,"line")<0;)c.push(this.endLine=this.endLine.parentNode);return c},a.prototype.clear=function(){return this.selection.removeAllRanges()},a.prototype.destroy=function(){return butterfly.body.classList.remove("selection"),this.clear()},a.prototype.text=function(){return this.selection.toString().replace(/\u00A0/g," ").replace(/\u2007/g," ")},a.prototype.up=function(){return this.go(-1)},a.prototype.down=function(){return this.go(1)},a.prototype.go=function(a){var b;if(b=butterfly.children.indexOf(this.startLine)+a,b>=0&&b=0&&b0;)if(f[--d].match(b))return{node:e,offset:d+1};e=n(e),f=null!=e?e.textContent:void 0,d=f.length}else for(;e;){for(;d=0)return!0;if(a.shiftKey&&13===a.keyCode&&!o&&!getSelection().isCollapsed)return butterfly.send(getSelection().toString()),getSelection().removeAllRanges(),f(a);if(o){if(o.reset(),!a.ctrlKey&&a.shiftKey&&37<=(d=a.keyCode)&&40>=d)return!0;if(a.shiftKey&&a.ctrlKey)38===a.keyCode?o.up():40===a.keyCode&&o.down();else if(39===a.keyCode)o.shrinkLeft();else if(38===a.keyCode)o.expandLeft();else if(37===a.keyCode)o.shrinkRight();else{if(40!==a.keyCode)return f(a);o.expandRight()}return null!=o&&o.apply(),f(a)}return!o&&a.ctrlKey&&a.shiftKey&&38===a.keyCode?(o=new b,o.selectLine(butterfly.y-1),o.apply(),f(a)):!0}),document.addEventListener("keyup",function(a){var b,c;if(b=a.keyCode,s.call([16,17,18,19],b)>=0)return!0;if(o){if(13===a.keyCode)return butterfly.send(o.text()),o.destroy(),o=null,f(a);if(c=a.keyCode,s.call([37,38,39,40],c)<0)return o.destroy(),o=null,!0}return!0}),document.addEventListener("dblclick",function(a){var b,c,d,e,f;if(!(a.ctrlKey||a.altkey||(f=getSelection(),f.isCollapsed||f.toString().match(/\s/)))){for(e=document.createRange(),e.setStart(f.anchorNode,f.anchorOffset),e.setEnd(f.focusNode,f.focusOffset),e.collapsed&&(f.removeAllRanges(),d=document.createRange(),d.setStart(f.focusNode,f.focusOffset),d.setEnd(f.anchorNode,f.anchorOffset),f.addRange(d));!f.toString().match(/\s/)&&f.toString();)f.modify("extend","forward","character");for(f.modify("extend","backward","character"),b=f.anchorNode,c=f.anchorOffset,f.collapseToEnd(),f.extend(b,c);!f.toString().match(/\s/)&&f.toString();)f.modify("extend","backward","character");return f.modify("extend","forward","character")}}),document.addEventListener("keydown",function(a){var b;return a.altKey&&69===a.keyCode?(b=new XMLHttpRequest,b.addEventListener("load",function(){var a,b,c,d,e,f;if(e=JSON.parse(this.responseText),c="
",c+="

Session list

",0===e.sessions.length)c+="No current session for user "+e.user;else{for(c+="
    ",d=e.sessions,a=0,b=d.length;b>a;a++)f=d[a],c+='
  • '+f+"
  • ";c+="
"}return c+="
",m.open(c)}),b.open("GET","/sessions/list.json"),b.send(),f(a)):!0}),c=function(a){var b;return document.getElementById("style").setAttribute("href",a),b=document.createElement("img"),b.onerror=function(){return setTimeout(function(){return"undefined"!=typeof butterfly&&null!==butterfly?butterfly.resize():void 0},250)},b.src=a},d="undefined"!=typeof localStorage&&null!==localStorage?localStorage.getItem("theme"):void 0,d&&c(d),this.set_theme=function(a){return d=a,"undefined"!=typeof localStorage&&null!==localStorage&&localStorage.setItem("theme",a),a?c(a):void 0},document.addEventListener("keydown",function(a){var b,e;return a.altKey&&83===a.keyCode?a.shiftKey?(e=document.getElementById("style").getAttribute("href"),e=e.split("?")[0],c(e+"?"+(new Date).getTime()),f(a)):(b=new XMLHttpRequest,b.addEventListener("load",function(){var a,b,c,e,f,g,h,i,j,k,l,n;if(i=JSON.parse(this.responseText),a=i.builtin_themes,l=i.themes,b='
\n

Pick a theme:

\n \n \n
",m.open(b),k=document.getElementById("theme_list"),k.addEventListener("change",function(){return set_theme(k.value)})}),b.open("GET","/themes/list.json"),b.send(),f(a)):!0}),/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)&&(i=!1,e=!1,j=!0,q=document.createElement("input"),q.type="password",q.style.position="fixed",q.style.top=0,q.style.left=0,q.style.border="none",q.style.outline="none",q.style.opacity=0,q.value="0",document.body.appendChild(q),q.addEventListener("blur",function(){return setTimeout(function(a){return function(){return a.focus()}}(this),10)}),addEventListener("click",function(){return q.focus()}),addEventListener("touchstart",function(a){return 2===a.touches.length?i=!0:3===a.touches.length?(i=!1,e=!0):4===a.touches.length?(i=!0,e=!0):void 0}),q.addEventListener("keydown",function(a){return butterfly.keyDown(a),!0}),q.addEventListener("input",function(a){var b;return b=this.value.length,0===b?(a.keyCode=8,butterfly.keyDown(a),this.value="0",!0):(a.keyCode=this.value.charAt(1).charCodeAt(0),!i&&!e||j?(butterfly.keyPress(a),j=!1,this.value="0",!0):(a.keyCode=this.value.charAt(1).charCodeAt(0),a.ctrlKey=i,a.altKey=e,a.keyCode>=97&&a.keyCode<=122&&(a.keyCode-=32),butterfly.keyDown(a),this.value="0",i=e=!1,!0))}))}).call(this); //# sourceMappingURL=ext.min.js.map \ No newline at end of file diff --git a/butterfly/static/main.js b/butterfly/static/main.js index 2e655c8..641cd47 100644 --- a/butterfly/static/main.js +++ b/butterfly/static/main.js @@ -1,6 +1,5 @@ (function() { var $, State, Terminal, cancel, cols, openTs, quit, rows, s, uuid, ws, - slice = [].slice, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; cols = rows = null; @@ -192,7 +191,7 @@ this.rows = Math.floor(window.innerHeight / this.charSize.height); px = window.innerHeight % this.charSize.height; this.body.style['padding-bottom'] = px + "px"; - this.scrollback = 1000000; + this.scrollback = 10000; this.buffSize = 100000; this.visualBell = 100; this.convertEol = false; @@ -226,11 +225,18 @@ }; })(this)); this.emit('load'); + this.active = null; + Terminal.on('change', (function(_this) { + return function(line) { + if (line.classList.contains('active')) { + return _this.active = line; + } + }; + })(this)); } - Terminal.prototype.emit = function() { - var args, fun, hook, k, len, ref, results; - hook = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : []; + Terminal.prototype.emit = function(hook, obj) { + var fun, k, len, ref, results; if (Terminal.hooks[hook] == null) { Terminal.hooks[hook] = []; } @@ -238,7 +244,11 @@ results = []; for (k = 0, len = ref.length; k < len; k++) { fun = ref[k]; - results.push(fun.apply(this, args)); + results.push(setTimeout((function(f) { + return function() { + return f.call(this, obj); + }; + })(fun), 10)); } return results; }; @@ -543,144 +553,162 @@ })(this)); }; - Terminal.prototype.refresh = function(force) { - var active, attr, ch, classes, cls, cursor, data, fg, group, i, j, k, len, len1, len2, len3, len4, line, lines, m, modified, n, newOut, o, out, q, ref, ref1, ref2, ref3, ref4, ref5, skipnext, styles, u, x; - if (force == null) { - force = false; + Terminal.prototype._putChar = function(data, attr, i, x) { + var ch, classes, fg, out, skipnext, styles; + out = ''; + ch = data.ch; + if (!this.equalAttr(data, attr)) { + if (!this.equalAttr(attr, this.defAttr)) { + out += ""; + } + if (!this.equalAttr(data, this.defAttr)) { + classes = []; + styles = []; + out += ""; } - ref1 = this.body.querySelectorAll(".line.active"); - for (m = 0, len1 = ref1.length; m < len1; m++) { - active = ref1[m]; - active.classList.remove('active'); + if (ch.length > 1) { + out += ch; + } else { + switch (ch) { + case "&": + out += "&"; + break; + case "<": + out += "<"; + break; + case ">": + out += ">"; + break; + default: + if (ch === " ") { + out += '\u2007'; + } else if (ch <= " ") { + out += " "; + } else if (!this.forceWidth || ch <= "~") { + out += ch; + } else if (("\uff00" < ch && ch < "\uffef")) { + skipnext = true; + out += "" + ch + ""; + } else { + out += "" + ch + ""; + } + } } - newOut = ''; - modified = []; - ref2 = this.screen; - for (j = n = 0, len2 = ref2.length; n < len2; j = ++n) { - line = ref2[j]; + if (i === x) { + out += ""; + } + return out; + }; + + Terminal.prototype._putLine = function(x, j, outs, line) { + var cls; + this.screen[j].dirty = false; + if (this.children[j]) { + this.children[j].innerHTML = outs.join(''); + this.emit('change', this.children[j]); + if (x !== null) { + this.children[j].classList.add('active'); + } + if (line.extra) { + this.children[j].classList.add('extended'); + } + return null; + } else { + cls = ['line']; + if (x !== null) { + cls.push('active'); + } + if (line.extra) { + cls.push('extended'); + } + return "
" + (outs.join('')) + "
"; + } + }; + + Terminal.prototype._replotScreen = function(force) { + var attr, data, group, groups, i, j, k, len, line, m, out, outs, ref, ref1, skipnext, x; + groups = []; + ref = this.screen; + for (j = k = 0, len = ref.length; k < len; j = ++k) { + line = ref[j]; if (!(line.dirty || force)) { continue; } - out = ""; + x = null; if (j === this.y + this.shift && !this.cursorHidden) { x = this.x; - } else { - x = -Infinity; } attr = this.cloneAttr(this.defAttr); skipnext = false; - for (i = o = 0, ref3 = this.cols - 1; 0 <= ref3 ? o <= ref3 : o >= ref3; i = 0 <= ref3 ? ++o : --o) { + outs = []; + for (i = m = 0, ref1 = this.cols - 1; 0 <= ref1 ? m <= ref1 : m >= ref1; i = 0 <= ref1 ? ++m : --m) { data = line.chars[i]; if (data.html) { - out += data.html; + outs.push(data.html); break; } if (skipnext) { skipnext = false; continue; } - ch = data.ch; - if (!this.equalAttr(data, attr)) { - if (!this.equalAttr(attr, this.defAttr)) { - out += ""; - } - if (!this.equalAttr(data, this.defAttr)) { - classes = []; - styles = []; - out += ""; - } - if (ch.length > 1) { - out += ch; - } else { - switch (ch) { - case "&": - out += "&"; - break; - case "<": - out += "<"; - break; - case ">": - out += ">"; - break; - default: - if (ch === " ") { - out += '\u2007'; - } else if (ch <= " ") { - out += " "; - } else if (!this.forceWidth || ch <= "~") { - out += ch; - } else if (("\uff00" < ch && ch < "\uffef")) { - skipnext = true; - out += "" + ch + ""; - } else { - out += "" + ch + ""; - } - } - } - if (i === x) { - out += ""; - } + outs.push(this._putChar(data, attr, i, x)); attr = data; } + out = ''; if (!this.equalAttr(attr, this.defAttr)) { out += ""; } @@ -690,53 +718,59 @@ if (line.extra) { out += '' + line.extra + ''; } - if (this.children[j]) { - this.children[j].innerHTML = out; - modified.push(this.children[j]); - if (x !== -Infinity) { - this.children[j].classList.add('active'); - } - if (line.extra) { - this.children[j].classList.add('extended'); - } - } else { - cls = ['line']; - if (x !== -Infinity) { - cls.push('active'); - } - if (line.extra) { - cls.push('extended'); - } - newOut += "
" + out + "
"; + outs.push(out); + group = this._putLine(x, j, outs, line); + if (group) { + groups.push(group); } - this.screen[j].dirty = false; } - if (newOut !== '') { - group = this.document.createElement('div'); - group.className = 'group'; - group.innerHTML = newOut; - modified.push(group); - this.body.appendChild(group); - this.screen = this.screen.slice(-this.rows); - this.shift = 0; - lines = document.querySelectorAll('.line'); - if (lines.length > this.scrollback) { - ref4 = Array.prototype.slice.call(lines, 0, lines.length - this.scrollback); - for (q = 0, len3 = ref4.length; q < len3; q++) { - line = ref4[q]; - line.remove(); - } - ref5 = document.querySelectorAll('.group:empty'); - for (u = 0, len4 = ref5.length; u < len4; u++) { - group = ref5[u]; - group.remove(); - } - lines = document.querySelectorAll('.line'); + if (groups.length) { + return this._putGroup(groups); + } + }; + + Terminal.prototype._putGroup = function(groups) { + var group, i, k, len, m, node, nodes, ref; + group = this.document.createElement('div'); + group.className = 'group'; + group.innerHTML = groups.join(''); + if (true || groups.length > 1) { + nodes = group.childNodes; + node = group; + } else { + nodes = [group.firstChild]; + node = group.firstChild; + } + this.body.appendChild(node); + for (k = 0, len = nodes.length; k < len; k++) { + node = nodes[k]; + if (this.children.length >= this.rows) { + this.children.pop(); } - this.children = Array.prototype.slice.call(lines, -this.rows); + this.emit('change', node); + this.children.push(node); } - this.nativeScrollTo(); - return this.emit('change', modified); + this.screen = this.screen.slice(-this.rows); + this.shift = 0; + if (this.body.childElementCount > this.scrollback) { + this.body.style.display = 'none'; + for (i = m = 0, ref = this.body.childElementCount - this.scrollback; 0 <= ref ? m <= ref : m >= ref; i = 0 <= ref ? ++m : --m) { + this.body.firstChild.remove(); + } + return this.body.style.display = 'block'; + } + }; + + Terminal.prototype.refresh = function(force) { + var ref; + if (force == null) { + force = false; + } + if ((ref = this.active) != null) { + ref.classList.remove('active'); + } + this._replotScreen(force); + return this.nativeScrollTo(); }; Terminal.prototype._cursorBlink = function() { @@ -1747,6 +1781,7 @@ j = oldRows; if (j < this.rows) { el = this.body; + this.body.style.display = 'none'; while (j++ < this.rows) { if (this.screen.length < this.rows) { this.screen.push(this.blankLine()); @@ -1757,6 +1792,7 @@ el.appendChild(line); this.children.push(line); } + this.body.style.display = 'block'; } } else if (j > this.rows) { while (j-- > this.rows) { diff --git a/butterfly/static/main.min.js b/butterfly/static/main.min.js index 775867a..8e531ea 100644 --- a/butterfly/static/main.min.js +++ b/butterfly/static/main.min.js @@ -1,5 +1,5 @@ -/*! butterfly 2016-10-11 */ +/*! butterfly 2016-10-12 */ -(function(){var a,b,c,d,e,f,g,h,i,j,k,l=[].slice,m=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};e=h=null,g=!1,f=(new Date).getTime(),k={shell:null,ctl:null},a=document.querySelectorAll.bind(document),j=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b,c;return b=16*Math.random()|0,c="x"===a?b:3&b|8,c.toString(16)})},document.addEventListener("DOMContentLoaded",function(){var a,b,d,e,h,i,l,m,n,o,p,q,r;return o=null,r="https:"===location.protocol?"wss://":"ws://",n=document.body.getAttribute("data-root-path"),n.length&&(n="/"+n),r+=document.location.host+n,l=location.pathname,l.indexOf("/session")<0&&(l+="session/"+j()),l+=location.search,k.shell=new WebSocket(r+"/ws"+l),k.ctl=new WebSocket(r+"/ctl"+l),i=function(){return console.log("WebSocket open",arguments),o?(o.body.classList.remove("stopped"),o.out=k.shell.send.bind(k.shell),void o.out("\n")):(k.shell.readyState===WebSocket.OPEN&&k.ctl.readyState===WebSocket.OPEN&&(o=new c(document.body,k.shell.send.bind(k.shell),k.ctl.send.bind(k.ctl)),o.ws=k,window.butterfly=o,k.ctl.send(JSON.stringify({cmd:"open"})),k.ctl.send(JSON.stringify({cmd:"size",cols:o.cols,rows:o.rows})),f=(new Date).getTime()),console.log("WebSocket open end",arguments))},d=function(){return console.error("WebSocket error",arguments)},a=function(){return console.log("WebSocket closed",arguments),g?void 0:(g=!0,o.write("Closed"),o.skipNextKey=!0,o.body.classList.add("dead"),(new Date).getTime()-f>6e4?window.open("","_self").close():void 0)},m=function(){return setTimeout(function(){return g?void 0:(k.shell=new WebSocket(r+"/ws"+l),h())},100)},p=function(a){return o?o.write(a):void 0},q=function(a){return setTimeout(p,1,a.data)},b=function(a){var b;return b=JSON.parse(a.data),"size"===b.cmd?o.resize(b.cols,b.rows,!0):void 0},h=function(){return k.shell.addEventListener("open",i),k.shell.addEventListener("message",q),k.shell.addEventListener("error",d),k.shell.addEventListener("close",m)},e=function(){return k.ctl.addEventListener("open",i),k.ctl.addEventListener("message",b),k.ctl.addEventListener("error",d),k.ctl.addEventListener("close",a)},h(),e(),addEventListener("beforeunload",function(){return g?void 0:"This will exit the terminal session"})}),d=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},i=0,b={normal:i++,escaped:i++,csi:i++,osc:i++,charset:i++,dcs:i++,ignore:i++},c=function(){function a(a,b,c){var d,e;this.parent=a,this.out=b,this.ctl=null!=c?c:function(){},this.document=this.parent.ownerDocument,this.html=this.document.getElementsByTagName("html")[0],this.body=this.document.getElementsByTagName("body")[0],this.forceWidth="yes"===this.body.getAttribute("data-force-unicode-width"),this.body.className="terminal focus",this.body.style.outline="none",this.body.setAttribute("tabindex",0),this.body.setAttribute("spellcheck","false"),d=this.document.createElement("div"),d.className="line",this.body.appendChild(d),this.children=[d],this.computeCharSize(),this.cols=Math.floor(this.body.clientWidth/this.charSize.width),this.rows=Math.floor(window.innerHeight/this.charSize.height),e=window.innerHeight%this.charSize.height,this.body.style["padding-bottom"]=e+"px",this.scrollback=1e6,this.buffSize=1e5,this.visualBell=100,this.convertEol=!1,this.termName="xterm",this.cursorBlink=!0,this.cursorState=0,this.resetVars(),this.focus(),this.startBlink(),addEventListener("keydown",this.keyDown.bind(this)),addEventListener("keypress",this.keyPress.bind(this)),addEventListener("focus",this.focus.bind(this)),addEventListener("blur",this.blur.bind(this)),addEventListener("resize",function(a){return function(){return a.resize()}}(this)),this.body.addEventListener("load",function(a){return function(){return a.nativeScrollTo()}}(this),!0),"undefined"!=typeof InstallTrigger&&(this.body.contentEditable="true"),this.initmouse(),addEventListener("load",function(a){return function(){return a.resize()}}(this)),this.emit("load")}return a.hooks={},a.on=function(b,c){return null==a.hooks[b]&&(a.hooks[b]=[]),a.hooks[b].push(c)},a.off=function(b,c){return null==a.hooks[b]&&(a.hooks[b]=[]),a.hooks[b].pop(c)},a.prototype.emit=function(){var b,c,d,e,f,g,h;for(d=arguments[0],b=2<=arguments.length?l.call(arguments,1):[],null==a.hooks[d]&&(a.hooks[d]=[]),g=a.hooks[d],h=[],e=0,f=g.length;f>e;e++)c=g[e],h.push(c.apply(this,b));return h},a.prototype.cloneAttr=function(a,b){return null==b&&(b=null),{bg:a.bg,fg:a.fg,ch:null!==b?b:a.ch,bold:a.bold,underline:a.underline,blink:a.blink,inverse:a.inverse,invisible:a.invisible,italic:a.italic,faint:a.faint,crossed:a.crossed}},a.prototype.equalAttr=function(a,b){return a.bg===b.bg&&a.fg===b.fg&&a.bold===b.bold&&a.underline===b.underline&&a.blink===b.blink&&a.inverse===b.inverse&&a.invisible===b.invisible&&a.italic===b.italic&&a.faint===b.faint&&a.crossed===b.crossed},a.prototype.putChar=function(a){return this.insertMode?(this.screen[this.y+this.shift].chars.splice(this.x,0,this.cloneAttr(this.curAttr,a)),this.screen[this.y+this.shift].chars.pop()):this.screen[this.y+this.shift].chars[this.x]=this.cloneAttr(this.curAttr,a),this.screen[this.y+this.shift].dirty=!0},a.prototype.resetVars=function(){var a;for(this.x=0,this.y=0,this.cursorHidden=!1,this.state=b.normal,this.queue="",this.scrollTop=0,this.scrollBottom=this.rows-1,this.scrollLock=!1,this.applicationKeypad=!1,this.applicationCursor=!1,this.originMode=!1,this.autowrap=!0,this.horizontalWrap=!1,this.normal=null,this.charset=null,this.gcharset=null,this.glevel=0,this.charsets=[null],this.defAttr={bg:256,fg:257,ch:" ",bold:!1,underline:!1,blink:0,inverse:!1,invisible:!1,italic:!1,faint:!1,crossed:!1},this.curAttr=this.cloneAttr(this.defAttr),this.params=[],this.currentParam=0,this.prefix="",this.screen=[],a=this.rows,this.shift=0;a--;)this.screen.push(this.blankLine(!1,!1));return this.setupStops(),this.skipNextKey=null},a.prototype.computeCharSize=function(){var a;return a=document.createElement("span"),a.textContent="0123456789",this.children[0].appendChild(a),this.charSize={width:a.getBoundingClientRect().width/10,height:this.children[0].getBoundingClientRect().height},this.children[0].removeChild(a)},a.prototype.eraseAttr=function(){var a;return a=this.cloneAttr(this.defAttr),a.bg=this.curAttr.bg,a},a.prototype.focus=function(){var a;return a=this.scrollLock,this.scrollLock=!0,this.sendFocus&&this.send(""),this.showCursor(),this.body.classList.add("focus"),this.body.classList.remove("blur"),this.resize(),this.scrollLock=a},a.prototype.blur=function(){var a;return a=this.scrollLock,this.scrollLock=!0,this.cursorState=1,this.screen[this.y+this.shift].dirty=!0,this.refresh(),this.sendFocus&&this.send(""),this.body.classList.add("blur"),this.body.classList.remove("focus"),this.scrollLock=a},a.prototype.initmouse=function(){var a,b,c,e,f,g,h;return e=32,f=function(a){var d,f;return d=b(a),(f=c(a))?(g(d,f,a.type),e=d):void 0},h=function(a){var b,d;return b=e,(d=c(a))?(b+=32,g(b,d,a.type)):void 0},a=function(a){return function(b,c){return a.utfMouse?2047===c?b.push(0):127>c?b.push(c):(c>2047&&(c=2047),b.push(192|c>>6),b.push(128|63&c)):255===c?b.push(0):(c>127&&(c=127),b.push(c))}}(this),g=function(b){return function(c,d,e){var f;return b.urxvtMouse?(d.x-=32,d.y-=32,d.x++,d.y++,void b.send("["+c+";"+d.x+";"+d.y+"M")):b.sgrMouse?(d.x-=32,d.y-=32,c-=32,void b.send("[<"+c+";"+d.x+";"+d.y+("mouseup"===e?"m":"M"))):(f=[],a(f,c),a(f,d.x),a(f,d.y),b.send(""+String.fromCharCode.apply(String,f)))}}(this),b=function(a){return function(b){var c,d,e,f,g;switch(b.type){case"mousedown":c=null!=b.button?+b.button:null!=b.which?b.which-1:null;break;case"mouseup":c=3;break;case"wheel":c=b.deltaY<0?64:65}return g=b.shiftKey?4:0,e=b.metaKey?8:0,d=b.ctrlKey?16:0,f=g|e|d,a.vt200Mouse?f&=d:a.normalMouse||(f=0),32+(f<<2)+c}}(this),c=function(a){return function(b){var c,d,e,f;return e=b.pageX,f=b.pageY-window.scrollY,d=a.body.clientWidth,c=window.innerHeight,e=Math.ceil(e/d*a.cols),f=Math.ceil(f/c*a.rows),0>e&&(e=0),e>a.cols&&(e=a.cols),0>f&&(f=0),f>a.rows&&(f=a.rows),e+=32,f+=32,{x:e,y:f,type:b.type}}}(this),addEventListener("contextmenu",function(a){return function(b){return a.mouseEvents?d(b):void 0}}(this)),addEventListener("mousedown",function(a){return function(b){var c,e;if(a.mouseEvents)return f(b),c=h.bind(a),addEventListener("mousemove",c),a.x10Mouse||addEventListener("mouseup",e=function(a){return f(a),removeEventListener("mousemove",c),removeEventListener("mouseup",e),d(a)}),d(b)}}(this)),addEventListener("wheel",function(a){return function(b){if(a.mouseEvents){if(a.x10Mouse)return;return f(b),d(b)}}}(this))},a.prototype.refresh=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K;for(null==a&&(a=!1),B=this.body.querySelectorAll(".cursor"),m=0,n=B.length;n>m;m++)g=B[m],g.parentNode.replaceChild(this.document.createTextNode(g.textContent),g);for(C=this.body.querySelectorAll(".line.active"),u=0,o=C.length;o>u;u++)b=C[u],b.classList.remove("active");for(x="",v=[],D=this.screen,l=w=0,p=D.length;p>w;l=++w)if(s=D[l],s.dirty||a){for(z="",K=l!==this.y+this.shift||this.cursorHidden?-(1/0):this.x,c=this.cloneAttr(this.defAttr),H=!1,k=y=0,E=this.cols-1;E>=0?E>=y:y>=E;k=E>=0?++y:--y){if(h=s.chars[k],h.html){z+=h.html;break}if(H)H=!1;else{if(d=h.ch,this.equalAttr(h,c)||(this.equalAttr(c,this.defAttr)||(z+=""),this.equalAttr(h,this.defAttr)||(e=[],I=[],z+="i&&(i+=8),e.push("fg-color-"+i)),"string"==typeof h.fg&&I.push("color: "+h.fg),"number"==typeof h.bg&&e.push("bg-color-"+h.bg),"string"==typeof h.bg&&I.push("background-color: "+h.bg),z+='class="',z+=e.join(" "),z+='"',I.length&&(z+=' style="'+I.join("; ")+'"'),z+=">")),k===K&&(z+=''),d.length>1)z+=d;else switch(d){case"&":z+="&";break;case"<":z+="<";break;case">":z+=">";break;default:" "===d?z+='':" ">=d?z+=" ":!this.forceWidth||"~">=d?z+=d:d>"＀"&&"￯">d?(H=!0,z+=''+d+""):z+=''+d+""}k===K&&(z+=""),c=h}}this.equalAttr(c,this.defAttr)||(z+=""),s.wrap&&(z+="⏎"),s.extra&&(z+=''+s.extra+""),this.children[l]?(this.children[l].innerHTML=z,v.push(this.children[l]),K!==-(1/0)&&this.children[l].classList.add("active"),s.extra&&this.children[l].classList.add("extended")):(f=["line"],K!==-(1/0)&&f.push("active"),s.extra&&f.push("extended"),x+='
'+z+"
"),this.screen[l].dirty=!1}if(""!==x){if(j=this.document.createElement("div"),j.className="group",j.innerHTML=x,v.push(j),this.body.appendChild(j),this.screen=this.screen.slice(-this.rows),this.shift=0,t=document.querySelectorAll(".line"),t.length>this.scrollback){for(F=Array.prototype.slice.call(t,0,t.length-this.scrollback),A=0,q=F.length;q>A;A++)s=F[A],s.remove();for(G=document.querySelectorAll(".group:empty"),J=0,r=G.length;r>J;J++)j=G[J],j.remove();t=document.querySelectorAll(".line")}this.children=Array.prototype.slice.call(t,-this.rows)}return this.nativeScrollTo(),this.emit("change",v)},a.prototype._cursorBlink=function(){var a;return this.cursorState^=1,(a=this.body.querySelector(".cursor"))?a.classList.contains("reverse-video")?a.classList.remove("reverse-video"):a.classList.add("reverse-video"):void 0},a.prototype.showCursor=function(){return this.cursorState?void 0:(this.cursorState=1,this.screen[this.y+this.shift].dirty=!0,this.refresh())},a.prototype.startBlink=function(){return this.cursorBlink?(this._blinker=function(a){return function(){return a._cursorBlink()}}(this),this.t_blink=setInterval(this._blinker,500)):void 0},a.prototype.refreshBlink=function(){return this.cursorBlink?(clearInterval(this.t_blink),this.t_blink=setInterval(this._blinker,500)):void 0},a.prototype.scroll=function(){var a,b,c,d,e;if(this.normal||0!==this.scrollTop||this.scrollBottom!==this.rows-1){for(this.screen.splice(this.shift+this.scrollBottom+1,0,this.blankLine()),this.screen.splice(this.shift+this.scrollTop,1),e=[],a=b=c=this.scrollTop,d=this.scrollBottom;d>=c?d>=b:b>=d;a=d>=c?++b:--b)e.push(this.screen[a+this.shift].dirty=!0);return e}return this.screen.push(this.blankLine()),this.shift++},a.prototype.unscroll=function(){var a,b,c,d,e;for(this.screen.splice(this.shift+this.scrollTop,0,this.blankLine(!0)),this.screen.splice(this.shift+this.scrollBottom+1,1),e=[],a=b=c=this.scrollTop,d=this.scrollBottom;d>=c?d>=b:b>=d;a=d>=c?++b:--b)e.push(this.screen[a+this.shift].dirty=!0);return e},a.prototype.nativeScrollTo=function(a){return null==a&&(a=2e9),this.scrollLock?void 0:window.scrollTo(0,a)},a.prototype.scrollDisplay=function(a){return this.nativeScrollTo(window.scrollY+a*this.charSize.height)},a.prototype.nextLine=function(){return this.y++,this.y>this.scrollBottom?(this.y--,this.scroll()):void 0},a.prototype.prevLine=function(){return this.y--,this.yj;){switch(g=c.charAt(j),this.state){case b.normal:switch(g){case"":this.bell();break;case"\n":case"\x0B":case"\f":this.horizontalWrap?this.screen[this.y+this.shift].extra+=g:(this.screen[this.y+this.shift].dirty=!0,this.nextLine());break;case"\r":this.horizontalWrap||(this.x=0);break;case"\b":this.x>=this.cols&&this.x--,this.x>0&&this.x--;break;case" ":this.x=this.nextStop();break;case"":this.setgLevel(1);break;case"":this.setgLevel(0);break;case"":this.state=b.escaped;break;default:if(g>="̀"&&"ͯ">=g||g>="᪰"&&"᫿">=g||g>="᷀"&&"᷿">=g||g>="⃐"&&"⃿">=g||g>="︠"&&"︯">=g){if(z=this.x,A=this.y+this.shift,this.x>0)z-=1;else{if(!(this.y>0))break;A-=1,z=this.cols-1}this.screen[A].chars[z].ch+=g;break}if(g>=" "&&((null!=(s=this.charset)?s[g]:void 0)&&(g=this.charset[g]),this.x>=this.cols&&(this.horizontalWrap?this.screen[this.y+this.shift].extra+=g:(this.autowrap&&(this.screen[this.y+this.shift].wrap=!0,this.nextLine()),this.x=0)),this.putChar(g),this.x++,this.forceWidth&&g>"＀"&&"￯">g)){if(this.cols<2||this.x>=this.cols){this.putChar(" ");break}this.putChar(" "),this.x++}}break;case b.escaped:switch(g){case"[":this.params=[],this.currentParam=0,this.state=b.csi;break;case"]":this.params=[],this.currentParam=0,this.state=b.osc;break;case"P":this.params=[],this.currentParam=0,this.state=b.dcs;break;case"_":this.state=b.ignore;break;case"^":this.state=b.ignore;break;case"c":this.clearScrollback(),this.reset();break;case"E":this.x=0,this.index();break;case"D":this.index();break;case"M":this.reverseIndex();break;case"%":this.setgLevel(0),this.setgCharset(0,a.prototype.charsets.US),this.state=b.normal,j++;break;case"(":case")":case"*":case"+":case"-":case".":switch(g){case"(":this.gcharset=0;break;case")":case"-":this.gcharset=1;break;case"*":case".":this.gcharset=2;break;case"+":this.gcharset=3}this.state=b.charset;break;case"/":this.gcharset=3,this.state=b.charset,j--;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=b.normal;break;case"8":this.restoreCursor(),this.state=b.normal;break;case"#":switch(this.state=b.normal,j++,q=c.charAt(j)){case"3":break;case"4":break;case"5":break;case"6":break;case"8":for(t=this.screen,k=0,m=t.length;m>k;k++)for(n=t[k],n.dirty=!0,f=o=0,u=n.chars.length;u>=0?u>=o:o>=u;f=u>=0?++o:--o)n.chars[f]=this.cloneAttr(this.curAttr,"E");this.x=this.y=0}break;case"H":this.tabSet();break;case"=":this.applicationKeypad=!0,this.state=b.normal;break;case">":this.applicationKeypad=!1,this.state=b.normal;break;default:this.state=b.normal,console.log("Unknown ESC control:",g)}break;case b.charset:switch(g){case"0":i=a.prototype.charsets.SCLD;break;case"A":i=a.prototype.charsets.UK;break;case"B":i=a.prototype.charsets.US;break;case"4":i=a.prototype.charsets.Dutch;break;case"C":case"5":i=a.prototype.charsets.Finnish;break;case"R":i=a.prototype.charsets.French;break;case"Q":i=a.prototype.charsets.FrenchCanadian;break;case"K":i=a.prototype.charsets.German;break;case"Y":i=a.prototype.charsets.Italian;break;case"E":case"6":i=a.prototype.charsets.NorwegianDanish;break;case"Z":i=a.prototype.charsets.Spanish;break;case"H":case"7":i=a.prototype.charsets.Swedish;break;case"=":i=a.prototype.charsets.Swiss;break;case"/":i=a.prototype.charsets.ISOLatin,j++;break;default:i=a.prototype.charsets.US}this.setgCharset(this.gcharset,i),this.gcharset=null,this.state=b.normal;break;case b.osc:if(""===g||""===g){switch(""===g&&j++,this.params.push(this.currentParam),this.params[0]){case 0:case 1:case 2:this.params[1]&&(this.title=this.params[1]+" - ƸӜƷ butterfly",this.handleTitle(this.title))}this.params=[],this.currentParam=0,this.state=b.normal}else this.params.length?this.currentParam+=g:g>="0"&&"9">=g?this.currentParam=10*this.currentParam+g.charCodeAt(0)-48:";"===g&&(this.params.push(this.currentParam),this.currentParam="");break;case b.csi:if("?"===g||">"===g||"!"===g){this.prefix=g;break}if(g>="0"&&"9">=g){this.currentParam=10*this.currentParam+g.charCodeAt(0)-48;break}if("$"===g||'"'===g||" "===g||"'"===g)break;if(" ">=g||g>="~"){"\b"===g&&(this.currentParam=this.currentParam/10&1),"\r"===g&&(this.x=0),["\n","\x0B","\f"].indexOf(g)>=0&&(this.screen[this.y+this.shift].dirty=!0,this.nextLine());break}if(this.params.push(this.currentParam),this.currentParam=0,";"===g)break;switch(this.state=b.normal,g){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.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":"!"===this.prefix&&this.softReset(this.params);break;default:console.error("Unknown CSI code: %s (%d).",g,g.charCodeAt(0))}this.prefix="";break;case b.dcs:if(""===g||""===g){switch(""===g&&j++,this.prefix){case"":if(r=this.currentParam,";"!==r[0]){console.error("Unknown DECUDK: "+r);break}if(r=r.slice(1),v=r.split("|",2),x=v[0],h=v[1],!h){console.error("No type for inline DECUDK: "+r);break}switch(x){case"HTML":w=html_sanitize(h,function(a){return a}),d=this.cloneAttr(this.curAttr),d.html='
'+w+"
",this.screen[this.y+this.shift].chars[this.x]=d,this.resetLine(this.screen[this.y+this.shift]),this.nextLine();break;case"IMAGE":h=encodeURI(h),h.indexOf(";")?(p=h.slice(0,h.indexOf(";")),e=h.slice(h.indexOf(";")+1)):(p="image",e=h),d=this.cloneAttr(this.curAttr),d.html='',this.screen[this.y+this.shift].chars[this.x]=d,this.resetLine(this.screen[this.y+this.shift]);break;case"PROMPT":this.send(h);break;case"TEXT":l+=h.length,c=c.slice(0,j+1)+h+c.slice(j+1);break;default:console.error("Unknown type "+x+" for DECUDK")}break;case"$q":switch(r=this.currentParam,y=!1,r){case'"q':r='0"q';break;case'"p':r='61"p';break;case"r":r=""+(this.scrollTop+1)+";"+(this.scrollBottom+1)+"r";break;case"m":r="0m";break;default:console.error("Unknown DCS Pt: %s.",r),r=""}this.send("P"+ +y+"$r"+r+"\\");break;case"+q":r=this.currentParam,y=!1,this.send("P"+ +y+"+r"+r+"\\");break;default:console.error("Unknown DCS prefix: %s.",this.prefix)}this.currentParam=0,this.prefix="",this.state=b.normal}else this.currentParam?this.currentParam+=g:this.prefix||"$"===g||"+"===g?2===this.prefix.length?this.currentParam=g:this.prefix+=g:this.currentParam=g;break;case b.ignore:""!==g&&""!==g||(""===g&&j++,this.state=b.normal)}j++}return this.screen[this.y+this.shift].dirty=!0,this.refresh()},a.prototype.writeln=function(a){return this.write(a+"\r\n")},a.prototype.keyDown=function(a){var b,c;if(a.keyCode>15&&a.keyCode<19)return!0;if(19===a.keyCode)return this.body.classList.add("stopped"),this.out(""),this.ws.shell.close(),!1;if((a.shiftKey||a.ctrlKey)&&45===a.keyCode)return!0;if(a.shiftKey&&a.ctrlKey&&(67===(c=a.keyCode)||86===c))return!0;if(a.altKey&&90===a.keyCode&&!this.skipNextKey)return this.skipNextKey=!0,this.body.classList.add("skip"),d(a);if(this.skipNextKey)return this.skipNextKey=!1,this.body.classList.remove("skip"),!0;switch(a.keyCode){case 8:if(b=a.altKey?"":"",a.shiftKey){b+="\b";break}b+="";break;case 9:if(a.shiftKey){b="";break}b=" ";break;case 13:b="\r";break;case 27:b="";break;case 37:if(this.applicationCursor){b="OD";break}b="";break;case 39:if(this.applicationCursor){b="OC";break}b="";break;case 38:if(this.applicationCursor){b="OA";break}if(a.ctrlKey)return this.scrollDisplay(-1),d(a);b="";break;case 40:if(this.applicationCursor){b="OB";break}if(a.ctrlKey)return this.scrollDisplay(1),d(a);b="";break;case 46:b="[3~";break;case 45:b="[2~";break;case 36:if(this.applicationKeypad){b="OH";break}b="";break;case 35:if(this.applicationKeypad){b="OF";break}b="";break;case 33:if(a.shiftKey){if(a.ctrlKey)break;return this.scrollDisplay(-(this.rows-1)),d(a)}b="[5~";break;case 34:if(a.shiftKey){if(a.ctrlKey)break;return this.scrollDisplay(this.rows-1),d(a)}b="[6~";break;case 112:b="OP";break;case 113:b="OQ";break;case 114:b="OR";break;case 115:b="OS";break;case 116:b="[15~";break;case 117:b="[17~";break;case 118:b="[18~";break;case 119:b="[19~";break;case 120:b="[20~";break;case 121:b="[21~";break;case 122:b="[23~";break;case 123:b="[24~";break;case 145:return this.scrollLock=!this.scrollLock,this.scrollLock?this.body.classList.add("locked"):this.body.classList.remove("locked"),d(a);default:a.ctrlKey?a.keyCode>=65&&a.keyCode<=90?b=String.fromCharCode(a.keyCode-64):32===a.keyCode?b=String.fromCharCode(0):a.keyCode>=51&&a.keyCode<=55?b=String.fromCharCode(a.keyCode-51+27):56===a.keyCode?b=String.fromCharCode(127):219===a.keyCode?b=String.fromCharCode(27):221===a.keyCode&&(b=String.fromCharCode(29)):(a.altKey&&m.call(navigator.platform,"Mac")<0||a.metaKey&&m.call(navigator.platform,"Mac")>=0)&&(a.keyCode>=65&&a.keyCode<=90?b=""+String.fromCharCode(a.keyCode+32):192===a.keyCode?b="`":a.keyCode>=48&&a.keyCode<=57&&(b=""+(a.keyCode-48)))}return a.keyCode>=37&&a.keyCode<=40&&(a.ctrlKey?b=b.slice(0,-1)+"1;5"+b.slice(-1):a.altKey?b=b.slice(0,-1)+"1;3"+b.slice(-1):a.shiftKey&&(b=b.slice(0,-1)+"1;4"+b.slice(-1))),b?(this.showCursor(),this.send(b),d(a)):!0},a.prototype.setgLevel=function(a){return this.glevel=a,this.charset=this.charsets[a]},a.prototype.setgCharset=function(a,b){return this.charsets[a]=b,this.glevel===a?this.charset=b:void 0},a.prototype.keyPress=function(a){var b,c;if(this.skipNextKey===!1)return this.skipNextKey=null,!0;if(a.keyCode>15&&a.keyCode<19)return!0;if((a.shiftKey||a.ctrlKey)&&45===a.keyCode)return!0;if(a.shiftKey&&a.ctrlKey&&(67===(c=a.keyCode)||86===c))return!0;if(d(a),a.charCode)b=a.charCode;else if(null==a.which)b=a.keyCode;else{if(0===a.which||0===a.charCode)return!1;b=a.which}return!b||a.ctrlKey||a.altKey||a.metaKey?!1:(b=String.fromCharCode(b),this.showCursor(),this.send(b),!1)},a.prototype.bell=function(a){return null==a&&(a="bell"),this.visualBell?(this.body.classList.add(a),this.t_bell=setTimeout(function(b){return function(){return b.body.classList.remove(a)}}(this),this.visualBell)):void 0},a.prototype.resize=function(a,b,c){var d,e,f,g,h,i,j,k,l;if(null==a&&(a=null),null==b&&(b=null),null==c&&(c=!1),i=this.cols,j=this.rows,this.computeCharSize(),l=this.body.clientWidth,e=this.html.clientHeight-(this.html.offsetHeight-this.html.scrollHeight),this.cols=a||Math.floor(l/this.charSize.width),this.rows=b||Math.floor(e/this.charSize.height),k=e%this.charSize.height,this.body.style["padding-bottom"]=k+"px",this.cols=Math.max(1,this.cols),this.rows=Math.max(1,this.rows),this.nativeScrollTo(),a||b||i!==this.cols||j!==this.rows){if(c||this.ctl(JSON.stringify({cmd:"size",cols:this.cols,rows:this.rows})),ithis.cols)for(f=this.screen.length;f--;)for(;this.screen[f].chars.length>this.cols;)this.screen[f].chars.pop();if(this.setupStops(i),g=j,gthis.rows)for(;g-- >this.rows;)this.screen.length>this.rows&&this.screen.pop(),this.children.length>this.rows&&(d=this.children.pop(),null!=d&&d.parentNode.removeChild(d));if(this.normal){if(ithis.cols)for(f=this.normal.screen.length;f--;)for(;this.normal.screen[f].chars.length>this.cols;)this.normal.screen[f].chars.pop();if(g=j,gthis.rows)for(;g-- >this.rows;)this.normal.screen.length>this.rows&&this.normal.screen.pop()}return this.y>=this.rows&&(this.y=this.rows-1),this.x>=this.cols&&(this.x=this.cols-1),this.scrollTop=0,this.scrollBottom=this.rows-1,this.refresh(!0),c||!a&&!b?void 0:this.reset()}},a.prototype.resizeWindowPlease=function(a){var b,c;return b=window.innerWidth-this.body.clientWidth,c=a*this.charSize.width+b,resizeTo(c,window.innerHeight)},a.prototype.setupStops=function(a){var b;for(null!=a?this.tabs[a]||(a=this.prevStop(a)):(this.tabs={},a=0),b=[];a0;);return a>=this.cols?this.cols-1:0>a?0:a},a.prototype.nextStop=function(a){for(null==a&&(a=this.x);!this.tabs[++a]&&a=this.cols?this.cols-1:0>a?0:a},a.prototype.eraseRight=function(a,b){var c;for(c=this.screen[b+this.shift].chars;athis.rows){for(h=Array.prototype.slice.call(f,0,f.length-this.rows),b=0,c=h.length;c>b;b++)e=h[b],e.remove();for(i=document.querySelectorAll(".group:empty"),g=0,d=i.length;d>g;g++)a=i[g],a.remove();f=document.querySelectorAll(".line")}return this.children=Array.prototype.slice.call(f,-this.rows)},a.prototype.tabSet=function(){return this.tabs[this.x]=!0,this.state=b.normal},a.prototype.cursorUp=function(a){var b;return b=a[0],1>b&&(b=1),this.y-=b,this.y<0?this.y=0:void 0},a.prototype.cursorDown=function(a){var b;return b=a[0],1>b&&(b=1),this.y+=b,this.y>=this.rows?this.y=this.rows-1:void 0},a.prototype.cursorForward=function(a){var b;return b=a[0],1>b&&(b=1),this.x+=b,this.x>=this.cols?this.x=this.cols-1:void 0},a.prototype.cursorBackward=function(a){var b;return b=a[0],1>b&&(b=1),this.x-=b,this.x<0?this.x=0:void 0},a.prototype.cursorPos=function(a){var b,c;return c=a[0]-1,b=a.length>=2?a[1]-1:0,0>c?c=0:c>=this.rows&&(c=this.rows-1),0>b?b=0:b>=this.cols&&(b=this.cols-1),this.x=b,this.y=c+(this.originMode?this.scrollTop:0)},a.prototype.eraseInDisplay=function(a){var b,c,d,e;switch(a[0]){case 0:for(this.eraseRight(this.x,this.y),b=this.y+1,c=[];bb;)d=a[b],d>=30&&37>=d?this.curAttr.fg=d-30:d>=40&&47>=d?this.curAttr.bg=d-40:d>=90&&97>=d?(d+=8,this.curAttr.fg=d-90):d>=100&&107>=d?(d+=8,this.curAttr.bg=d-100):0===d?this.curAttr=this.cloneAttr(this.defAttr):1===d?this.curAttr.bold=!0:2===d?this.curAttr.faint=!0:3===d?this.curAttr.italic=!0:4===d?this.curAttr.underline=!0:5===d?this.curAttr.blink=1:6===d?this.curAttr.blink=2:7===d?this.curAttr.inverse=!0:8===d?this.curAttr.invisible=!0:9===d?this.curAttr.crossed=!0:10===d||(21===d?this.curAttr.bold=!1:22===d?(this.curAttr.bold=!1,this.curAttr.faint=!1):23===d?this.curAttr.italic=!1:24===d?this.curAttr.underline=!1:25===d?this.curAttr.blink=!1:27===d?this.curAttr.inverse=!1:28===d?this.curAttr.invisible=!1:29===d?this.curAttr.crossed=!1:39===d?this.curAttr.fg=257:49===d?this.curAttr.bg=256:38===d?2===a[b+1]?(b+=2,this.curAttr.fg="rgb("+a[b]+", "+a[b+1]+", "+a[b+2]+")",b+=2):5===a[b+1]&&(b+=2,this.curAttr.fg=255&a[b]):48===d?2===a[b+1]?(b+=2,this.curAttr.bg="rgb("+a[b]+", "+a[b+1]+", "+a[b+2]+")",b+=2):5===a[b+1]&&(b+=2,this.curAttr.bg=255&a[b]):100===d?(this.curAttr.fg=257,this.curAttr.bg=256):console.error("Unknown SGR attribute: %d.",d)),e.push(b++);return e},a.prototype.deviceStatus=function(a){var b,c;if(this.prefix){if("?"===this.prefix&&(6===a[0]&&this.send("[?"+(this.y+1)+";"+(this.x+1)+"R"),99===a[0]))return null==(null!=(b=navigator.geolocation)?b.getCurrentPosition:void 0)?void this.send("[?R"):null!=(c=navigator.geolocation)?c.getCurrentPosition(function(a){ -return function(b){return a.send("[?"+b.coords.latitude+";"+b.coords.longitude+"R")}}(this),function(a){return function(b){return a.send("[?R")}}(this)):void 0}else switch(a[0]){case 5:return this.send("");case 6:return this.send("["+(this.y+1)+";"+(this.x+1)+"R")}},a.prototype.insertChars=function(a){var b,c,d;for(c=a[0],1>c&&(c=1),d=this.y,b=this.x;c--&&bb&&(b=1),this.y+=b,this.y>=this.rows&&(this.y=this.rows-1),this.x=0},a.prototype.cursorPrecedingLine=function(a){var b;return b=a[0],1>b&&(b=1),this.y-=b,this.y<0&&(this.y=0),this.x=0},a.prototype.cursorCharAbsolute=function(a){var b;return b=a[0],1>b&&(b=1),this.x=b-1},a.prototype.insertLines=function(a){var b,c,d,e,f,g;for(d=a[0],1>d&&(d=1);d--;)this.screen.splice(this.y+this.shift,0,this.blankLine(!0)),this.screen.splice(this.scrollBottom+1+this.shift,1);for(g=[],b=c=e=this.y+this.shift,f=this.screen.length-1;f>=e?f>=c:c>=f;b=f>=e?++c:--c)g.push(this.screen[b].dirty=!0);return g},a.prototype.deleteLines=function(a){var b,c,d,e,f,g;for(d=a[0],1>d&&(d=1);d--;)this.screen.splice(this.scrollBottom+this.shift,0,this.blankLine(!0)),this.screen.splice(this.y+this.shift,1),this.normal||0!==this.scrollTop||this.scrollBottom!==this.rows-1||(this.children[this.y+this.shift].remove(),this.children.splice(this.y+this.shift,1));if(this.normal||0!==this.scrollTop||this.scrollBottom!==this.rows-1){for(g=[],b=c=e=this.y+this.shift,f=this.screen.length-1;f>=e?f>=c:c>=f;b=f>=e?++c:--c)g.push(this.screen[b].dirty=!0);return g}},a.prototype.deleteChars=function(a){var b;for(b=a[0],1>b&&(b=1);b--;)this.screen[this.y+this.shift].chars.splice(this.x,1),this.screen[this.y+this.shift].chars.push(this.eraseAttr());return this.resetLine(this.screen[this.y+this.shift])},a.prototype.eraseChars=function(a){var b,c;for(c=a[0],1>c&&(c=1),b=this.x;c--&&bb&&(b=1),this.x=b-1,this.x>=this.cols?this.x=this.cols-1:void 0},a.prototype.HPositionRelative=function(a){var b;return b=a[0],1>b&&(b=1),this.x+=b,this.x>=this.cols?this.x=this.cols-1:void 0},a.prototype.sendDeviceAttributes=function(a){if(!(a[0]>0))if(this.prefix){if(">"===this.prefix){if(this.isterm("xterm"))return this.send("[>0;276;0c");if(this.isterm("rxvt-unicode"))return this.send("[>85;95;0c");if(this.isterm("linux"))return this.send(a[0]+"c");if(this.isterm("screen"))return this.send("[>83;40003;0c")}}else{if(this.isterm("xterm")||this.isterm("rxvt-unicode")||this.isterm("screen"))return this.send("[?1;2c");if(this.isterm("linux"))return this.send("[?6c")}},a.prototype.linePosAbsolute=function(a){var b;return b=a[0],1>b&&(b=1),this.y=b-1,this.y>=this.rows?this.y=this.rows-1:void 0},a.prototype.VPositionRelative=function(a){var b;return b=a[0],1>b&&(b=1),this.y+=b,this.y>=this.rows?this.y=this.rows-1:void 0},a.prototype.HVPosition=function(a){return a[0]<1&&(a[0]=1),a[1]<1&&(a[1]=1),this.y=a[0]-1,this.y>=this.rows&&(this.y=this.rows-1),this.x=a[1]-1,this.x>=this.cols?this.x=this.cols-1:void 0},a.prototype.setMode=function(b){var c,d,e;if("object"!=typeof b)if(this.prefix){if("?"===this.prefix)switch(b){case 1:return this.applicationCursor=!0;case 2:return this.setgCharset(0,a.prototype.charsets.US),this.setgCharset(1,a.prototype.charsets.US),this.setgCharset(2,a.prototype.charsets.US),this.setgCharset(3,a.prototype.charsets.US);case 3:return this.savedCols=this.cols,this.resize(132,this.rows),this.resizeWindowPlease(132),this.reset();case 6:return this.originMode=!0;case 7:return this.autowrap=!0;case 66:return this.applicationKeypad=!0;case 77:return this.horizontalWrap=!0;case 9:case 1e3:case 1002:case 1003:return this.x10Mouse=9===b,this.vt200Mouse=1e3===b,this.normalMouse=b>1e3,this.mouseEvents=!0,this.body.style.cursor="pointer";case 1004:return this.sendFocus=!0;case 1005:return this.utfMouse=!0;case 1006:return this.sgrMouse=!0;case 1015:return this.urxvtMouse=!0;case 25:return this.cursorHidden=!1;case 1049:case 47:case 1047:if(!this.normal)return e={screen:this.screen,x:this.x,y:this.y,shift:this.shift,scrollTop:this.scrollTop,scrollBottom:this.scrollBottom,tabs:this.tabs,curAttr:this.curAttr},this.reset(),this.normal=e,this.showCursor()}}else switch(b){case 4:this.insertMode=!0;break;case 20:this.convertEol=!0}else for(d=b.length,c=0;d>c;)this.setMode(b[c]),c++},a.prototype.resetMode=function(a){var b,c;if("object"!=typeof a)if(this.prefix){if("?"===this.prefix)switch(a){case 1:return this.applicationCursor=!1;case 3:return 132===this.cols&&this.savedCols&&this.resize(this.savedCols,this.rows),this.resizeWindowPlease(80),this.reset(),delete this.savedCols;case 6:return this.originMode=!1;case 7:return this.autowrap=!1;case 66:return this.applicationKeypad=!1;case 77:return this.horizontalWrap=!1;case 9:case 1e3:case 1002:case 1003:return this.x10Mouse=!1,this.vt200Mouse=!1,this.normalMouse=!1,this.mouseEvents=!1,this.body.style.cursor="";case 1004:return this.sendFocus=!1;case 1005:return this.utfMouse=!1;case 1006:return this.sgrMouse=!1;case 1015:return this.urxvtMouse=!1;case 25:return this.cursorHidden=!0;case 1049:case 47:case 1047:if(this.normal)return this.screen=this.normal.screen,this.x=this.normal.x,this.y=this.normal.y,this.shift=this.normal.shift,this.scrollTop=this.normal.scrollTop,this.scrollBottom=this.normal.scrollBottom,this.tabs=this.normal.tabs,this.curAttr=this.normal.curAttr,this.normal=null,this.refresh(!0),this.showCursor()}}else switch(a){case 4:this.insertMode=!1;break;case 20:this.convertEol=!1}else for(c=a.length,b=0;c>b;)this.resetMode(a[b]),b++},a.prototype.setScrollRegion=function(a){return this.prefix?void 0:(this.scrollTop=(a[0]||1)-1,this.scrollBottom=(a[1]||this.rows)-1,this.x=0,this.y=0)},a.prototype.saveCursor=function(a){return this.savedX=this.x,this.savedY=this.y},a.prototype.restoreCursor=function(a){return this.x=this.savedX||0,this.y=this.savedY||0},a.prototype.cursorForwardTab=function(a){var b,c;for(b=a[0]||1,c=[];b--;)c.push(this.x=this.nextStop());return c},a.prototype.scrollUp=function(a){var b,c,d,e,f,g;for(d=a[0]||1;d--;)this.screen.splice(this.scrollTop,1),this.screen.splice(this.scrollBottom,0,this.blankLine());for(g=[],b=c=e=this.scrollTop,f=this.scrollBottom;f>=e?f>=c:c>=f;b=f>=e?++c:--c)g.push(this.screen[b+this.shift].dirty=!0);return g},a.prototype.scrollDown=function(a){var b,c,d,e,f,g;for(d=a[0]||1;d--;)this.screen.splice(this.scrollBottom,1),this.screen.splice(this.scrollTop,0,this.blankLine());for(g=[],b=c=e=this.scrollTop,f=this.scrollBottom;f>=e?f>=c:c>=f;b=f>=e?++c:--c)g.push(this.screen[b+this.shift].dirty=!0);return g},a.prototype.initMouseTracking=function(a){},a.prototype.resetTitleModes=function(a){},a.prototype.cursorBackwardTab=function(a){var b,c;for(b=a[0]||1,c=[];b--;)c.push(this.x=this.prevStop());return c},a.prototype.repeatPrecedingCharacter=function(a){var b,c,d;for(d=a[0]||1,c=this.screen[this.y+this.shift].chars,b=c[this.x-1]||this.defAttr;d--;)c[this.x++]=b;return this.screen[this.y+this.shift].dirty=!0},a.prototype.tabClear=function(a){var b;return b=a[0],0>=b?delete this.tabs[this.x]:3===b?this.tabs={}:void 0},a.prototype.mediaCopy=function(a){},a.prototype.setResources=function(a){},a.prototype.disableModifiers=function(a){},a.prototype.setPointerMode=function(a){},a.prototype.softReset=function(a){return this.cursorHidden=!1,this.insertMode=!1,this.originMode=!1,this.autowrap=!0,this.applicationKeypad=!1,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]},a.prototype.requestAnsiMode=function(a){},a.prototype.requestPrivateMode=function(a){},a.prototype.setConformanceLevel=function(a){},a.prototype.loadLEDs=function(a){},a.prototype.setCursorStyle=function(a){},a.prototype.setCharProtectionAttr=function(a){},a.prototype.restorePrivateValues=function(a){},a.prototype.setAttrInRectangle=function(a){var b,c,d,e,f,g,h,i;for(i=a[0],e=a[1],c=a[2],g=a[3],b=a[4],h=[];c+1>i;){for(f=this.screen[i+this.shift].chars,this.screen[i+this.shift].dirty=!0,d=e;g>d;)f[d]=this.cloneAttr(b,f[d].ch),d++;h.push(i++)}return h},a.prototype.savePrivateValues=function(a){},a.prototype.manipulateWindow=function(a){},a.prototype.reverseAttrInRectangle=function(a){},a.prototype.setTitleModeFeature=function(a){},a.prototype.setWarningBellVolume=function(a){},a.prototype.setMarginBellVolume=function(a){},a.prototype.copyRectangle=function(a){},a.prototype.enableFilterRectangle=function(a){},a.prototype.requestParameters=function(a){},a.prototype.selectChangeExtent=function(a){},a.prototype.fillRectangle=function(a){var b,c,d,e,f,g,h,i;for(c=a[0],i=a[1],e=a[2],b=a[3],g=a[4],h=[];b+1>i;){for(f=this.screen[i+this.shift].chars,this.screen[i+this.shift].dirty=!0,d=e;g>d;)f[d]=this.cloneAttr(f[d][0],String.fromCharCode(c)),d++;h.push(i++)}return h},a.prototype.enableLocatorReporting=function(a){var b;return b=a[0]>0},a.prototype.eraseRectangle=function(a){var b,c,d,e,f,g,h;for(h=a[0],d=a[1],b=a[2],f=a[3],g=[];b+1>h;){for(e=this.screen[h+this.shift].chars,this.screen[h+this.shift].dirty=!0,c=d;f>c;)e[c]=this.eraseAttr(),c++;g.push(h++)}return g},a.prototype.setLocatorEvents=function(a){},a.prototype.selectiveEraseRectangle=function(a){},a.prototype.requestLocatorPosition=function(a){},a.prototype.insertColumns=function(){var a,b,c,d;for(c=params[0],b=this.rows+this.shift,d=[];c--;)a=this.shift,d.push(function(){var c;for(c=[];b>a;)this.screen[a].chars.splice(this.x+1,0,this.eraseAttr()),this.screen[a].chars.pop(),this.screen[a].dirty=!0,c.push(a++);return c}.call(this));return d},a.prototype.deleteColumns=function(){var a,b,c,d;for(c=params[0],b=this.rows+this.shift,d=[];c--;)a=this.shift,d.push(function(){var c;for(c=[];b>a;)this.screen[a].chars.splice(this.x,1),this.screen[a].chars.push(this.eraseAttr()),this.resetLine(this.screen[a].dirty),c.push(a++);return c}.call(this));return d},a.prototype.charsets={SCLD:{"`":"◆",a:"▒",b:" ",c:"\f",d:"\r",e:"\n",f:"°",g:"±",h:"␤",i:"\x0B",j:"┘",k:"┐",l:"┌",m:"└",n:"┼",o:"⎺",p:"⎻",q:"─",r:"⎼",s:"⎽",t:"├",u:"┤",v:"┴",w:"┬",x:"│",y:"≤",z:"≥","{":"π","|":"≠","}":"£","~":"·"},UK:null,US:null,Dutch:null,Finnish:null,French:null,FrenchCanadian:null,German:null,Italian:null,NorwegianDanish:null,Spanish:null,Swedish:null,Swiss:null,ISOLatin:null},a}(),window.Terminal=c}).call(this); +(function(){var a,b,c,d,e,f,g,h,i,j,k,l=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};e=h=null,g=!1,f=(new Date).getTime(),k={shell:null,ctl:null},a=document.querySelectorAll.bind(document),j=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b,c;return b=16*Math.random()|0,c="x"===a?b:3&b|8,c.toString(16)})},document.addEventListener("DOMContentLoaded",function(){var a,b,d,e,h,i,l,m,n,o,p,q,r;return o=null,r="https:"===location.protocol?"wss://":"ws://",n=document.body.getAttribute("data-root-path"),n.length&&(n="/"+n),r+=document.location.host+n,l=location.pathname,l.indexOf("/session")<0&&(l+="session/"+j()),l+=location.search,k.shell=new WebSocket(r+"/ws"+l),k.ctl=new WebSocket(r+"/ctl"+l),i=function(){return console.log("WebSocket open",arguments),o?(o.body.classList.remove("stopped"),o.out=k.shell.send.bind(k.shell),void o.out("\n")):(k.shell.readyState===WebSocket.OPEN&&k.ctl.readyState===WebSocket.OPEN&&(o=new c(document.body,k.shell.send.bind(k.shell),k.ctl.send.bind(k.ctl)),o.ws=k,window.butterfly=o,k.ctl.send(JSON.stringify({cmd:"open"})),k.ctl.send(JSON.stringify({cmd:"size",cols:o.cols,rows:o.rows})),f=(new Date).getTime()),console.log("WebSocket open end",arguments))},d=function(){return console.error("WebSocket error",arguments)},a=function(){return console.log("WebSocket closed",arguments),g?void 0:(g=!0,o.write("Closed"),o.skipNextKey=!0,o.body.classList.add("dead"),(new Date).getTime()-f>6e4?window.open("","_self").close():void 0)},m=function(){return setTimeout(function(){return g?void 0:(k.shell=new WebSocket(r+"/ws"+l),h())},100)},p=function(a){return o?o.write(a):void 0},q=function(a){return setTimeout(p,1,a.data)},b=function(a){var b;return b=JSON.parse(a.data),"size"===b.cmd?o.resize(b.cols,b.rows,!0):void 0},h=function(){return k.shell.addEventListener("open",i),k.shell.addEventListener("message",q),k.shell.addEventListener("error",d),k.shell.addEventListener("close",m)},e=function(){return k.ctl.addEventListener("open",i),k.ctl.addEventListener("message",b),k.ctl.addEventListener("error",d),k.ctl.addEventListener("close",a)},h(),e(),addEventListener("beforeunload",function(){return g?void 0:"This will exit the terminal session"})}),d=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},i=0,b={normal:i++,escaped:i++,csi:i++,osc:i++,charset:i++,dcs:i++,ignore:i++},c=function(){function a(a,b,c){var d,e;this.parent=a,this.out=b,this.ctl=null!=c?c:function(){},this.document=this.parent.ownerDocument,this.html=this.document.getElementsByTagName("html")[0],this.body=this.document.getElementsByTagName("body")[0],this.forceWidth="yes"===this.body.getAttribute("data-force-unicode-width"),this.body.className="terminal focus",this.body.style.outline="none",this.body.setAttribute("tabindex",0),this.body.setAttribute("spellcheck","false"),d=this.document.createElement("div"),d.className="line",this.body.appendChild(d),this.children=[d],this.computeCharSize(),this.cols=Math.floor(this.body.clientWidth/this.charSize.width),this.rows=Math.floor(window.innerHeight/this.charSize.height),e=window.innerHeight%this.charSize.height,this.body.style["padding-bottom"]=e+"px",this.scrollback=1e6,this.buffSize=1e5,this.visualBell=100,this.convertEol=!1,this.termName="xterm",this.cursorBlink=!0,this.cursorState=0,this.resetVars(),this.focus(),this.startBlink(),addEventListener("keydown",this.keyDown.bind(this)),addEventListener("keypress",this.keyPress.bind(this)),addEventListener("focus",this.focus.bind(this)),addEventListener("blur",this.blur.bind(this)),addEventListener("resize",function(a){return function(){return a.resize()}}(this)),this.body.addEventListener("load",function(a){return function(){return a.nativeScrollTo()}}(this),!0),"undefined"!=typeof InstallTrigger&&(this.body.contentEditable="true"),this.initmouse(),addEventListener("load",function(a){return function(){return a.resize()}}(this)),this.emit("load")}return a.hooks={},a.on=function(b,c){return null==a.hooks[b]&&(a.hooks[b]=[]),a.hooks[b].push(c)},a.off=function(b,c){return null==a.hooks[b]&&(a.hooks[b]=[]),a.hooks[b].pop(c)},a.prototype.emit=function(b,c){var d,e,f,g,h;for(null==a.hooks[b]&&(a.hooks[b]=[]),g=a.hooks[b],h=[],e=0,f=g.length;f>e;e++)d=g[e],h.push(d.call(this,c));return h},a.prototype.cloneAttr=function(a,b){return null==b&&(b=null),{bg:a.bg,fg:a.fg,ch:null!==b?b:a.ch,bold:a.bold,underline:a.underline,blink:a.blink,inverse:a.inverse,invisible:a.invisible,italic:a.italic,faint:a.faint,crossed:a.crossed}},a.prototype.equalAttr=function(a,b){return a.bg===b.bg&&a.fg===b.fg&&a.bold===b.bold&&a.underline===b.underline&&a.blink===b.blink&&a.inverse===b.inverse&&a.invisible===b.invisible&&a.italic===b.italic&&a.faint===b.faint&&a.crossed===b.crossed},a.prototype.putChar=function(a){return this.insertMode?(this.screen[this.y+this.shift].chars.splice(this.x,0,this.cloneAttr(this.curAttr,a)),this.screen[this.y+this.shift].chars.pop()):this.screen[this.y+this.shift].chars[this.x]=this.cloneAttr(this.curAttr,a),this.screen[this.y+this.shift].dirty=!0},a.prototype.resetVars=function(){var a;for(this.x=0,this.y=0,this.cursorHidden=!1,this.state=b.normal,this.queue="",this.scrollTop=0,this.scrollBottom=this.rows-1,this.scrollLock=!1,this.applicationKeypad=!1,this.applicationCursor=!1,this.originMode=!1,this.autowrap=!0,this.horizontalWrap=!1,this.normal=null,this.charset=null,this.gcharset=null,this.glevel=0,this.charsets=[null],this.defAttr={bg:256,fg:257,ch:" ",bold:!1,underline:!1,blink:0,inverse:!1,invisible:!1,italic:!1,faint:!1,crossed:!1},this.curAttr=this.cloneAttr(this.defAttr),this.params=[],this.currentParam=0,this.prefix="",this.screen=[],a=this.rows,this.shift=0;a--;)this.screen.push(this.blankLine(!1,!1));return this.setupStops(),this.skipNextKey=null},a.prototype.computeCharSize=function(){var a;return a=document.createElement("span"),a.textContent="0123456789",this.children[0].appendChild(a),this.charSize={width:a.getBoundingClientRect().width/10,height:this.children[0].getBoundingClientRect().height},this.children[0].removeChild(a)},a.prototype.eraseAttr=function(){var a;return a=this.cloneAttr(this.defAttr),a.bg=this.curAttr.bg,a},a.prototype.focus=function(){var a;return a=this.scrollLock,this.scrollLock=!0,this.sendFocus&&this.send(""),this.showCursor(),this.body.classList.add("focus"),this.body.classList.remove("blur"),this.resize(),this.scrollLock=a},a.prototype.blur=function(){var a;return a=this.scrollLock,this.scrollLock=!0,this.cursorState=1,this.screen[this.y+this.shift].dirty=!0,this.refresh(),this.sendFocus&&this.send(""),this.body.classList.add("blur"),this.body.classList.remove("focus"),this.scrollLock=a},a.prototype.initmouse=function(){var a,b,c,e,f,g,h;return e=32,f=function(a){var d,f;return d=b(a),(f=c(a))?(g(d,f,a.type),e=d):void 0},h=function(a){var b,d;return b=e,(d=c(a))?(b+=32,g(b,d,a.type)):void 0},a=function(a){return function(b,c){return a.utfMouse?2047===c?b.push(0):127>c?b.push(c):(c>2047&&(c=2047),b.push(192|c>>6),b.push(128|63&c)):255===c?b.push(0):(c>127&&(c=127),b.push(c))}}(this),g=function(b){return function(c,d,e){var f;return b.urxvtMouse?(d.x-=32,d.y-=32,d.x++,d.y++,void b.send("["+c+";"+d.x+";"+d.y+"M")):b.sgrMouse?(d.x-=32,d.y-=32,c-=32,void b.send("[<"+c+";"+d.x+";"+d.y+("mouseup"===e?"m":"M"))):(f=[],a(f,c),a(f,d.x),a(f,d.y),b.send(""+String.fromCharCode.apply(String,f)))}}(this),b=function(a){return function(b){var c,d,e,f,g;switch(b.type){case"mousedown":c=null!=b.button?+b.button:null!=b.which?b.which-1:null;break;case"mouseup":c=3;break;case"wheel":c=b.deltaY<0?64:65}return g=b.shiftKey?4:0,e=b.metaKey?8:0,d=b.ctrlKey?16:0,f=g|e|d,a.vt200Mouse?f&=d:a.normalMouse||(f=0),32+(f<<2)+c}}(this),c=function(a){return function(b){var c,d,e,f;return e=b.pageX,f=b.pageY-window.scrollY,d=a.body.clientWidth,c=window.innerHeight,e=Math.ceil(e/d*a.cols),f=Math.ceil(f/c*a.rows),0>e&&(e=0),e>a.cols&&(e=a.cols),0>f&&(f=0),f>a.rows&&(f=a.rows),e+=32,f+=32,{x:e,y:f,type:b.type}}}(this),addEventListener("contextmenu",function(a){return function(b){return a.mouseEvents?d(b):void 0}}(this)),addEventListener("mousedown",function(a){return function(b){var c,e;if(a.mouseEvents)return f(b),c=h.bind(a),addEventListener("mousemove",c),a.x10Mouse||addEventListener("mouseup",e=function(a){return f(a),removeEventListener("mousemove",c),removeEventListener("mouseup",e),d(a)}),d(b)}}(this)),addEventListener("wheel",function(a){return function(b){if(a.mouseEvents){if(a.x10Mouse)return;return f(b),d(b)}}}(this))},a.prototype._resetClasses=function(){var a,b,c,d,e,f,g,h,i;for(g=this.body.querySelectorAll(".cursor"),c=0,d=g.length;d>c;c++)b=g[c],b.parentNode.replaceChild(this.document.createTextNode(b.textContent),b);for(h=this.body.querySelectorAll(".line.active"),i=[],f=0,e=h.length;e>f;f++)a=h[f],i.push(a.classList.remove("active"));return i},a.prototype._putChar=function(a,b,c,d){var e,f,g,h,i,j;if(h="",e=a.ch,this.equalAttr(a,b)||(this.equalAttr(b,this.defAttr)||(h+=""),this.equalAttr(a,this.defAttr)||(f=[],j=[],h+="g&&(g+=8),f.push("fg-color-"+g)),"string"==typeof a.fg&&j.push("color: "+a.fg),"number"==typeof a.bg&&f.push("bg-color-"+a.bg),"string"==typeof a.bg&&j.push("background-color: "+a.bg),h+='class="',h+=f.join(" "),h+='"',j.length&&(h+=' style="'+j.join("; ")+'"'),h+=">")),c===d&&(h+=''),e.length>1)h+=e;else switch(e){case"&":h+="&";break;case"<":h+="<";break;case">":h+=">";break;default:" "===e?h+='':" ">=e?h+=" ":!this.forceWidth||"~">=e?h+=e:e>"＀"&&"￯">e?(i=!0,h+=''+e+""):h+=''+e+""}return c===d&&(h+=""),h},a.prototype._putLine=function(a,b,c,d){var e;return this.screen[b].dirty=!1,this.children[b]?(this.children[b].innerHTML=c.join(""),this.emit("change",this.children[b]),a!==-(1/0)&&this.children[b].classList.add("active"),d.extra&&this.children[b].classList.add("extended"),null):(e=["line"],a!==-(1/0)&&e.push("active"),d.extra&&e.push("extended"),'
'+c.join("")+"
")},a.prototype._replotScreen=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p;for(l=this.screen,n=[],e=f=0,g=l.length;g>f;e=++f)if(h=l[e],h.dirty||a){for(p=null,e!==this.y+this.shift||this.cursorHidden||(p=this.x),b=this.cloneAttr(this.defAttr),o=!1,k=[],d=i=0,m=this.cols-1;m>=0?m>=i:i>=m;d=m>=0?++i:--i){if(c=h.chars[d],c.html){j+=c.html;break}o?o=!1:(k.push(this._putChar(c,b,d,p)),b=c)}j="",this.equalAttr(b,this.defAttr)||(j+="
"),h.wrap&&(j+="⏎"),h.extra&&(j+=''+h.extra+""),k.push(j),n.push(this._putLine(p,e,k,h))}return n},a.prototype._putGroup=function(a){var b,c,d,e,f,g,h,i,j;if(b=this.document.createElement("div"),b.className="group",b.innerHTML=a,this.body.appendChild(b),this.emit("change",b),this.screen=this.screen.slice(-this.rows),this.shift=0,g=document.querySelectorAll(".line"),g.length>this.scrollback){for(i=Array.prototype.slice.call(g,0,g.length-this.scrollback),c=0,d=i.length;d>c;c++)f=i[c],f.remove();for(j=document.querySelectorAll(".group:empty"),h=0,e=j.length;e>h;h++)b=j[h],b.remove();g=document.querySelectorAll(".line")}return this.children=Array.prototype.slice.call(g,-this.rows)},a.prototype.refresh=function(a){var b;return null==a&&(a=!1),this._resetClasses(),b=this._replotScreen(a).join(""),b&&this._putGroup(b),this.nativeScrollTo()},a.prototype._cursorBlink=function(){var a;return this.cursorState^=1,(a=this.body.querySelector(".cursor"))?a.classList.contains("reverse-video")?a.classList.remove("reverse-video"):a.classList.add("reverse-video"):void 0},a.prototype.showCursor=function(){return this.cursorState?void 0:(this.cursorState=1,this.screen[this.y+this.shift].dirty=!0,this.refresh())},a.prototype.startBlink=function(){return this.cursorBlink?(this._blinker=function(a){return function(){return a._cursorBlink()}}(this),this.t_blink=setInterval(this._blinker,500)):void 0},a.prototype.refreshBlink=function(){return this.cursorBlink?(clearInterval(this.t_blink),this.t_blink=setInterval(this._blinker,500)):void 0},a.prototype.scroll=function(){var a,b,c,d,e;if(this.normal||0!==this.scrollTop||this.scrollBottom!==this.rows-1){for(this.screen.splice(this.shift+this.scrollBottom+1,0,this.blankLine()),this.screen.splice(this.shift+this.scrollTop,1),e=[],a=b=c=this.scrollTop,d=this.scrollBottom;d>=c?d>=b:b>=d;a=d>=c?++b:--b)e.push(this.screen[a+this.shift].dirty=!0);return e}return this.screen.push(this.blankLine()),this.shift++},a.prototype.unscroll=function(){var a,b,c,d,e;for(this.screen.splice(this.shift+this.scrollTop,0,this.blankLine(!0)),this.screen.splice(this.shift+this.scrollBottom+1,1),e=[],a=b=c=this.scrollTop,d=this.scrollBottom;d>=c?d>=b:b>=d;a=d>=c?++b:--b)e.push(this.screen[a+this.shift].dirty=!0);return e},a.prototype.nativeScrollTo=function(a){return null==a&&(a=2e9),this.scrollLock?void 0:window.scrollTo(0,a)},a.prototype.scrollDisplay=function(a){return this.nativeScrollTo(window.scrollY+a*this.charSize.height)},a.prototype.nextLine=function(){return this.y++,this.y>this.scrollBottom?(this.y--,this.scroll()):void 0},a.prototype.prevLine=function(){return this.y--,this.yj;){switch(g=c.charAt(j),this.state){case b.normal:switch(g){case"":this.bell();break;case"\n":case"\x0B":case"\f":this.horizontalWrap?this.screen[this.y+this.shift].extra+=g:(this.screen[this.y+this.shift].dirty=!0,this.nextLine());break;case"\r":this.horizontalWrap||(this.x=0);break;case"\b":this.x>=this.cols&&this.x--,this.x>0&&this.x--;break;case" ":this.x=this.nextStop();break;case"":this.setgLevel(1);break;case"":this.setgLevel(0);break;case"":this.state=b.escaped;break;default:if(g>="̀"&&"ͯ">=g||g>="᪰"&&"᫿">=g||g>="᷀"&&"᷿">=g||g>="⃐"&&"⃿">=g||g>="︠"&&"︯">=g){if(z=this.x,A=this.y+this.shift,this.x>0)z-=1;else{if(!(this.y>0))break;A-=1,z=this.cols-1}this.screen[A].chars[z].ch+=g;break}if(g>=" "&&((null!=(s=this.charset)?s[g]:void 0)&&(g=this.charset[g]),this.x>=this.cols&&(this.horizontalWrap?this.screen[this.y+this.shift].extra+=g:(this.autowrap&&(this.screen[this.y+this.shift].wrap=!0,this.nextLine()),this.x=0)),this.putChar(g),this.x++,this.forceWidth&&g>"＀"&&"￯">g)){if(this.cols<2||this.x>=this.cols){this.putChar(" ");break}this.putChar(" "),this.x++}}break;case b.escaped:switch(g){case"[":this.params=[],this.currentParam=0,this.state=b.csi;break;case"]":this.params=[],this.currentParam=0,this.state=b.osc;break;case"P":this.params=[],this.currentParam=0,this.state=b.dcs;break;case"_":this.state=b.ignore;break;case"^":this.state=b.ignore;break;case"c":this.clearScrollback(),this.reset();break;case"E":this.x=0,this.index();break;case"D":this.index();break;case"M":this.reverseIndex();break;case"%":this.setgLevel(0),this.setgCharset(0,a.prototype.charsets.US),this.state=b.normal,j++;break;case"(":case")":case"*":case"+":case"-":case".":switch(g){case"(":this.gcharset=0;break;case")":case"-":this.gcharset=1;break;case"*":case".":this.gcharset=2;break;case"+":this.gcharset=3}this.state=b.charset;break;case"/":this.gcharset=3,this.state=b.charset,j--;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=b.normal;break;case"8":this.restoreCursor(),this.state=b.normal;break;case"#":switch(this.state=b.normal,j++,q=c.charAt(j)){case"3":break;case"4":break;case"5":break;case"6":break;case"8":for(t=this.screen,k=0,m=t.length;m>k;k++)for(n=t[k],n.dirty=!0,f=o=0,u=n.chars.length;u>=0?u>=o:o>=u;f=u>=0?++o:--o)n.chars[f]=this.cloneAttr(this.curAttr,"E");this.x=this.y=0}break;case"H":this.tabSet();break;case"=":this.applicationKeypad=!0,this.state=b.normal;break;case">":this.applicationKeypad=!1,this.state=b.normal;break;default:this.state=b.normal,console.log("Unknown ESC control:",g)}break;case b.charset:switch(g){case"0":i=a.prototype.charsets.SCLD;break;case"A":i=a.prototype.charsets.UK;break;case"B":i=a.prototype.charsets.US;break;case"4":i=a.prototype.charsets.Dutch;break;case"C":case"5":i=a.prototype.charsets.Finnish;break;case"R":i=a.prototype.charsets.French;break;case"Q":i=a.prototype.charsets.FrenchCanadian;break;case"K":i=a.prototype.charsets.German;break;case"Y":i=a.prototype.charsets.Italian;break;case"E":case"6":i=a.prototype.charsets.NorwegianDanish;break;case"Z":i=a.prototype.charsets.Spanish;break;case"H":case"7":i=a.prototype.charsets.Swedish;break;case"=":i=a.prototype.charsets.Swiss;break;case"/":i=a.prototype.charsets.ISOLatin,j++;break;default:i=a.prototype.charsets.US}this.setgCharset(this.gcharset,i),this.gcharset=null,this.state=b.normal;break;case b.osc:if(""===g||""===g){switch(""===g&&j++,this.params.push(this.currentParam),this.params[0]){case 0:case 1:case 2:this.params[1]&&(this.title=this.params[1]+" - ƸӜƷ butterfly",this.handleTitle(this.title))}this.params=[],this.currentParam=0,this.state=b.normal}else this.params.length?this.currentParam+=g:g>="0"&&"9">=g?this.currentParam=10*this.currentParam+g.charCodeAt(0)-48:";"===g&&(this.params.push(this.currentParam),this.currentParam="");break;case b.csi:if("?"===g||">"===g||"!"===g){this.prefix=g;break}if(g>="0"&&"9">=g){this.currentParam=10*this.currentParam+g.charCodeAt(0)-48;break}if("$"===g||'"'===g||" "===g||"'"===g)break;if(" ">=g||g>="~"){"\b"===g&&(this.currentParam=this.currentParam/10&1),"\r"===g&&(this.x=0),["\n","\x0B","\f"].indexOf(g)>=0&&(this.screen[this.y+this.shift].dirty=!0,this.nextLine());break}if(this.params.push(this.currentParam),this.currentParam=0,";"===g)break;switch(this.state=b.normal,g){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.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":"!"===this.prefix&&this.softReset(this.params);break;default:console.error("Unknown CSI code: %s (%d).",g,g.charCodeAt(0))}this.prefix="";break;case b.dcs:if(""===g||""===g){switch(""===g&&j++,this.prefix){case"":if(r=this.currentParam,";"!==r[0]){console.error("Unknown DECUDK: "+r);break}if(r=r.slice(1),v=r.split("|",2),x=v[0],h=v[1],!h){console.error("No type for inline DECUDK: "+r);break}switch(x){case"HTML":w=html_sanitize(h,function(a){return a}),d=this.cloneAttr(this.curAttr),d.html='
'+w+"
",this.screen[this.y+this.shift].chars[this.x]=d,this.resetLine(this.screen[this.y+this.shift]),this.nextLine();break;case"IMAGE":h=encodeURI(h),h.indexOf(";")?(p=h.slice(0,h.indexOf(";")),e=h.slice(h.indexOf(";")+1)):(p="image",e=h),d=this.cloneAttr(this.curAttr),d.html='',this.screen[this.y+this.shift].chars[this.x]=d,this.resetLine(this.screen[this.y+this.shift]);break;case"PROMPT":this.send(h);break;case"TEXT":l+=h.length,c=c.slice(0,j+1)+h+c.slice(j+1);break;default:console.error("Unknown type "+x+" for DECUDK")}break;case"$q":switch(r=this.currentParam,y=!1,r){case'"q':r='0"q';break;case'"p':r='61"p';break;case"r":r=""+(this.scrollTop+1)+";"+(this.scrollBottom+1)+"r";break;case"m":r="0m";break;default:console.error("Unknown DCS Pt: %s.",r),r=""}this.send("P"+ +y+"$r"+r+"\\");break;case"+q":r=this.currentParam,y=!1,this.send("P"+ +y+"+r"+r+"\\");break;default:console.error("Unknown DCS prefix: %s.",this.prefix)}this.currentParam=0,this.prefix="",this.state=b.normal}else this.currentParam?this.currentParam+=g:this.prefix||"$"===g||"+"===g?2===this.prefix.length?this.currentParam=g:this.prefix+=g:this.currentParam=g;break;case b.ignore:""!==g&&""!==g||(""===g&&j++,this.state=b.normal)}j++}return this.screen[this.y+this.shift].dirty=!0,this.refresh()},a.prototype.writeln=function(a){return this.write(a+"\r\n")},a.prototype.keyDown=function(a){var b,c;if(a.keyCode>15&&a.keyCode<19)return!0;if(19===a.keyCode)return this.body.classList.add("stopped"),this.out(""),this.ws.shell.close(),!1;if((a.shiftKey||a.ctrlKey)&&45===a.keyCode)return!0;if(a.shiftKey&&a.ctrlKey&&(67===(c=a.keyCode)||86===c))return!0;if(a.altKey&&90===a.keyCode&&!this.skipNextKey)return this.skipNextKey=!0,this.body.classList.add("skip"),d(a);if(this.skipNextKey)return this.skipNextKey=!1,this.body.classList.remove("skip"),!0;switch(a.keyCode){case 8:if(b=a.altKey?"":"",a.shiftKey){b+="\b";break}b+="";break;case 9:if(a.shiftKey){b="";break}b=" ";break;case 13:b="\r";break;case 27:b="";break;case 37:if(this.applicationCursor){b="OD";break}b="";break;case 39:if(this.applicationCursor){b="OC";break}b="";break;case 38:if(this.applicationCursor){b="OA";break}if(a.ctrlKey)return this.scrollDisplay(-1),d(a);b="";break;case 40:if(this.applicationCursor){b="OB";break}if(a.ctrlKey)return this.scrollDisplay(1),d(a);b="";break;case 46:b="[3~";break;case 45:b="[2~";break;case 36:if(this.applicationKeypad){b="OH";break}b="";break;case 35:if(this.applicationKeypad){b="OF";break}b="";break;case 33:if(a.shiftKey){if(a.ctrlKey)break;return this.scrollDisplay(-(this.rows-1)),d(a)}b="[5~";break;case 34:if(a.shiftKey){if(a.ctrlKey)break;return this.scrollDisplay(this.rows-1),d(a)}b="[6~";break;case 112:b="OP";break;case 113:b="OQ";break;case 114:b="OR";break;case 115:b="OS";break;case 116:b="[15~";break;case 117:b="[17~";break;case 118:b="[18~";break;case 119:b="[19~";break;case 120:b="[20~";break;case 121:b="[21~";break;case 122:b="[23~";break;case 123:b="[24~";break;case 145:return this.scrollLock=!this.scrollLock,this.scrollLock?this.body.classList.add("locked"):this.body.classList.remove("locked"),d(a);default:a.ctrlKey?a.keyCode>=65&&a.keyCode<=90?b=String.fromCharCode(a.keyCode-64):32===a.keyCode?b=String.fromCharCode(0):a.keyCode>=51&&a.keyCode<=55?b=String.fromCharCode(a.keyCode-51+27):56===a.keyCode?b=String.fromCharCode(127):219===a.keyCode?b=String.fromCharCode(27):221===a.keyCode&&(b=String.fromCharCode(29)):(a.altKey&&l.call(navigator.platform,"Mac")<0||a.metaKey&&l.call(navigator.platform,"Mac")>=0)&&(a.keyCode>=65&&a.keyCode<=90?b=""+String.fromCharCode(a.keyCode+32):192===a.keyCode?b="`":a.keyCode>=48&&a.keyCode<=57&&(b=""+(a.keyCode-48)))}return a.keyCode>=37&&a.keyCode<=40&&(a.ctrlKey?b=b.slice(0,-1)+"1;5"+b.slice(-1):a.altKey?b=b.slice(0,-1)+"1;3"+b.slice(-1):a.shiftKey&&(b=b.slice(0,-1)+"1;4"+b.slice(-1))),b?(this.showCursor(),this.send(b),d(a)):!0},a.prototype.setgLevel=function(a){return this.glevel=a,this.charset=this.charsets[a]},a.prototype.setgCharset=function(a,b){return this.charsets[a]=b,this.glevel===a?this.charset=b:void 0},a.prototype.keyPress=function(a){var b,c;if(this.skipNextKey===!1)return this.skipNextKey=null,!0;if(a.keyCode>15&&a.keyCode<19)return!0;if((a.shiftKey||a.ctrlKey)&&45===a.keyCode)return!0;if(a.shiftKey&&a.ctrlKey&&(67===(c=a.keyCode)||86===c))return!0;if(d(a),a.charCode)b=a.charCode;else if(null==a.which)b=a.keyCode;else{if(0===a.which||0===a.charCode)return!1;b=a.which}return!b||a.ctrlKey||a.altKey||a.metaKey?!1:(b=String.fromCharCode(b),this.showCursor(),this.send(b),!1)},a.prototype.bell=function(a){return null==a&&(a="bell"),this.visualBell?(this.body.classList.add(a),this.t_bell=setTimeout(function(b){return function(){return b.body.classList.remove(a)}}(this),this.visualBell)):void 0},a.prototype.resize=function(a,b,c){var d,e,f,g,h,i,j,k,l;if(null==a&&(a=null),null==b&&(b=null),null==c&&(c=!1),i=this.cols,j=this.rows,this.computeCharSize(),l=this.body.clientWidth,e=this.html.clientHeight-(this.html.offsetHeight-this.html.scrollHeight),this.cols=a||Math.floor(l/this.charSize.width),this.rows=b||Math.floor(e/this.charSize.height),k=e%this.charSize.height,this.body.style["padding-bottom"]=k+"px",this.cols=Math.max(1,this.cols),this.rows=Math.max(1,this.rows),this.nativeScrollTo(),a||b||i!==this.cols||j!==this.rows){if(c||this.ctl(JSON.stringify({cmd:"size",cols:this.cols,rows:this.rows})),ithis.cols)for(f=this.screen.length;f--;)for(;this.screen[f].chars.length>this.cols;)this.screen[f].chars.pop();if(this.setupStops(i),g=j,gthis.rows)for(;g-- >this.rows;)this.screen.length>this.rows&&this.screen.pop(),this.children.length>this.rows&&(d=this.children.pop(),null!=d&&d.parentNode.removeChild(d));if(this.normal){if(ithis.cols)for(f=this.normal.screen.length;f--;)for(;this.normal.screen[f].chars.length>this.cols;)this.normal.screen[f].chars.pop();if(g=j,gthis.rows)for(;g-- >this.rows;)this.normal.screen.length>this.rows&&this.normal.screen.pop()}return this.y>=this.rows&&(this.y=this.rows-1),this.x>=this.cols&&(this.x=this.cols-1),this.scrollTop=0,this.scrollBottom=this.rows-1,this.refresh(!0),c||!a&&!b?void 0:this.reset()}},a.prototype.resizeWindowPlease=function(a){var b,c;return b=window.innerWidth-this.body.clientWidth,c=a*this.charSize.width+b,resizeTo(c,window.innerHeight)},a.prototype.setupStops=function(a){var b;for(null!=a?this.tabs[a]||(a=this.prevStop(a)):(this.tabs={},a=0),b=[];a0;);return a>=this.cols?this.cols-1:0>a?0:a},a.prototype.nextStop=function(a){for(null==a&&(a=this.x);!this.tabs[++a]&&a=this.cols?this.cols-1:0>a?0:a},a.prototype.eraseRight=function(a,b){var c;for(c=this.screen[b+this.shift].chars;athis.rows){for(h=Array.prototype.slice.call(f,0,f.length-this.rows),b=0,c=h.length;c>b;b++)e=h[b],e.remove();for(i=document.querySelectorAll(".group:empty"),g=0,d=i.length;d>g;g++)a=i[g],a.remove();f=document.querySelectorAll(".line")}return this.children=Array.prototype.slice.call(f,-this.rows)},a.prototype.tabSet=function(){return this.tabs[this.x]=!0,this.state=b.normal},a.prototype.cursorUp=function(a){var b;return b=a[0],1>b&&(b=1),this.y-=b,this.y<0?this.y=0:void 0},a.prototype.cursorDown=function(a){var b;return b=a[0],1>b&&(b=1),this.y+=b,this.y>=this.rows?this.y=this.rows-1:void 0},a.prototype.cursorForward=function(a){var b;return b=a[0],1>b&&(b=1),this.x+=b,this.x>=this.cols?this.x=this.cols-1:void 0},a.prototype.cursorBackward=function(a){var b;return b=a[0],1>b&&(b=1),this.x-=b,this.x<0?this.x=0:void 0},a.prototype.cursorPos=function(a){var b,c;return c=a[0]-1,b=a.length>=2?a[1]-1:0,0>c?c=0:c>=this.rows&&(c=this.rows-1),0>b?b=0:b>=this.cols&&(b=this.cols-1),this.x=b,this.y=c+(this.originMode?this.scrollTop:0)},a.prototype.eraseInDisplay=function(a){var b,c,d,e;switch(a[0]){case 0:for(this.eraseRight(this.x,this.y),b=this.y+1,c=[];bb;)d=a[b],d>=30&&37>=d?this.curAttr.fg=d-30:d>=40&&47>=d?this.curAttr.bg=d-40:d>=90&&97>=d?(d+=8,this.curAttr.fg=d-90):d>=100&&107>=d?(d+=8,this.curAttr.bg=d-100):0===d?this.curAttr=this.cloneAttr(this.defAttr):1===d?this.curAttr.bold=!0:2===d?this.curAttr.faint=!0:3===d?this.curAttr.italic=!0:4===d?this.curAttr.underline=!0:5===d?this.curAttr.blink=1:6===d?this.curAttr.blink=2:7===d?this.curAttr.inverse=!0:8===d?this.curAttr.invisible=!0:9===d?this.curAttr.crossed=!0:10===d||(21===d?this.curAttr.bold=!1:22===d?(this.curAttr.bold=!1,this.curAttr.faint=!1):23===d?this.curAttr.italic=!1:24===d?this.curAttr.underline=!1:25===d?this.curAttr.blink=!1:27===d?this.curAttr.inverse=!1:28===d?this.curAttr.invisible=!1:29===d?this.curAttr.crossed=!1:39===d?this.curAttr.fg=257:49===d?this.curAttr.bg=256:38===d?2===a[b+1]?(b+=2,this.curAttr.fg="rgb("+a[b]+", "+a[b+1]+", "+a[b+2]+")",b+=2):5===a[b+1]&&(b+=2,this.curAttr.fg=255&a[b]):48===d?2===a[b+1]?(b+=2,this.curAttr.bg="rgb("+a[b]+", "+a[b+1]+", "+a[b+2]+")",b+=2):5===a[b+1]&&(b+=2, +this.curAttr.bg=255&a[b]):100===d?(this.curAttr.fg=257,this.curAttr.bg=256):console.error("Unknown SGR attribute: %d.",d)),e.push(b++);return e},a.prototype.deviceStatus=function(a){var b,c;if(this.prefix){if("?"===this.prefix&&(6===a[0]&&this.send("[?"+(this.y+1)+";"+(this.x+1)+"R"),99===a[0]))return null==(null!=(b=navigator.geolocation)?b.getCurrentPosition:void 0)?void this.send("[?R"):null!=(c=navigator.geolocation)?c.getCurrentPosition(function(a){return function(b){return a.send("[?"+b.coords.latitude+";"+b.coords.longitude+"R")}}(this),function(a){return function(b){return a.send("[?R")}}(this)):void 0}else switch(a[0]){case 5:return this.send("");case 6:return this.send("["+(this.y+1)+";"+(this.x+1)+"R")}},a.prototype.insertChars=function(a){var b,c,d;for(c=a[0],1>c&&(c=1),d=this.y,b=this.x;c--&&bb&&(b=1),this.y+=b,this.y>=this.rows&&(this.y=this.rows-1),this.x=0},a.prototype.cursorPrecedingLine=function(a){var b;return b=a[0],1>b&&(b=1),this.y-=b,this.y<0&&(this.y=0),this.x=0},a.prototype.cursorCharAbsolute=function(a){var b;return b=a[0],1>b&&(b=1),this.x=b-1},a.prototype.insertLines=function(a){var b,c,d,e,f,g;for(d=a[0],1>d&&(d=1);d--;)this.screen.splice(this.y+this.shift,0,this.blankLine(!0)),this.screen.splice(this.scrollBottom+1+this.shift,1);for(g=[],b=c=e=this.y+this.shift,f=this.screen.length-1;f>=e?f>=c:c>=f;b=f>=e?++c:--c)g.push(this.screen[b].dirty=!0);return g},a.prototype.deleteLines=function(a){var b,c,d,e,f,g;for(d=a[0],1>d&&(d=1);d--;)this.screen.splice(this.scrollBottom+this.shift,0,this.blankLine(!0)),this.screen.splice(this.y+this.shift,1),this.normal||0!==this.scrollTop||this.scrollBottom!==this.rows-1||(this.children[this.y+this.shift].remove(),this.children.splice(this.y+this.shift,1));if(this.normal||0!==this.scrollTop||this.scrollBottom!==this.rows-1){for(g=[],b=c=e=this.y+this.shift,f=this.screen.length-1;f>=e?f>=c:c>=f;b=f>=e?++c:--c)g.push(this.screen[b].dirty=!0);return g}},a.prototype.deleteChars=function(a){var b;for(b=a[0],1>b&&(b=1);b--;)this.screen[this.y+this.shift].chars.splice(this.x,1),this.screen[this.y+this.shift].chars.push(this.eraseAttr());return this.resetLine(this.screen[this.y+this.shift])},a.prototype.eraseChars=function(a){var b,c;for(c=a[0],1>c&&(c=1),b=this.x;c--&&bb&&(b=1),this.x=b-1,this.x>=this.cols?this.x=this.cols-1:void 0},a.prototype.HPositionRelative=function(a){var b;return b=a[0],1>b&&(b=1),this.x+=b,this.x>=this.cols?this.x=this.cols-1:void 0},a.prototype.sendDeviceAttributes=function(a){if(!(a[0]>0))if(this.prefix){if(">"===this.prefix){if(this.isterm("xterm"))return this.send("[>0;276;0c");if(this.isterm("rxvt-unicode"))return this.send("[>85;95;0c");if(this.isterm("linux"))return this.send(a[0]+"c");if(this.isterm("screen"))return this.send("[>83;40003;0c")}}else{if(this.isterm("xterm")||this.isterm("rxvt-unicode")||this.isterm("screen"))return this.send("[?1;2c");if(this.isterm("linux"))return this.send("[?6c")}},a.prototype.linePosAbsolute=function(a){var b;return b=a[0],1>b&&(b=1),this.y=b-1,this.y>=this.rows?this.y=this.rows-1:void 0},a.prototype.VPositionRelative=function(a){var b;return b=a[0],1>b&&(b=1),this.y+=b,this.y>=this.rows?this.y=this.rows-1:void 0},a.prototype.HVPosition=function(a){return a[0]<1&&(a[0]=1),a[1]<1&&(a[1]=1),this.y=a[0]-1,this.y>=this.rows&&(this.y=this.rows-1),this.x=a[1]-1,this.x>=this.cols?this.x=this.cols-1:void 0},a.prototype.setMode=function(b){var c,d,e;if("object"!=typeof b)if(this.prefix){if("?"===this.prefix)switch(b){case 1:return this.applicationCursor=!0;case 2:return this.setgCharset(0,a.prototype.charsets.US),this.setgCharset(1,a.prototype.charsets.US),this.setgCharset(2,a.prototype.charsets.US),this.setgCharset(3,a.prototype.charsets.US);case 3:return this.savedCols=this.cols,this.resize(132,this.rows),this.resizeWindowPlease(132),this.reset();case 6:return this.originMode=!0;case 7:return this.autowrap=!0;case 66:return this.applicationKeypad=!0;case 77:return this.horizontalWrap=!0;case 9:case 1e3:case 1002:case 1003:return this.x10Mouse=9===b,this.vt200Mouse=1e3===b,this.normalMouse=b>1e3,this.mouseEvents=!0,this.body.style.cursor="pointer";case 1004:return this.sendFocus=!0;case 1005:return this.utfMouse=!0;case 1006:return this.sgrMouse=!0;case 1015:return this.urxvtMouse=!0;case 25:return this.cursorHidden=!1;case 1049:case 47:case 1047:if(!this.normal)return e={screen:this.screen,x:this.x,y:this.y,shift:this.shift,scrollTop:this.scrollTop,scrollBottom:this.scrollBottom,tabs:this.tabs,curAttr:this.curAttr},this.reset(),this.normal=e,this.showCursor()}}else switch(b){case 4:this.insertMode=!0;break;case 20:this.convertEol=!0}else for(d=b.length,c=0;d>c;)this.setMode(b[c]),c++},a.prototype.resetMode=function(a){var b,c;if("object"!=typeof a)if(this.prefix){if("?"===this.prefix)switch(a){case 1:return this.applicationCursor=!1;case 3:return 132===this.cols&&this.savedCols&&this.resize(this.savedCols,this.rows),this.resizeWindowPlease(80),this.reset(),delete this.savedCols;case 6:return this.originMode=!1;case 7:return this.autowrap=!1;case 66:return this.applicationKeypad=!1;case 77:return this.horizontalWrap=!1;case 9:case 1e3:case 1002:case 1003:return this.x10Mouse=!1,this.vt200Mouse=!1,this.normalMouse=!1,this.mouseEvents=!1,this.body.style.cursor="";case 1004:return this.sendFocus=!1;case 1005:return this.utfMouse=!1;case 1006:return this.sgrMouse=!1;case 1015:return this.urxvtMouse=!1;case 25:return this.cursorHidden=!0;case 1049:case 47:case 1047:if(this.normal)return this.screen=this.normal.screen,this.x=this.normal.x,this.y=this.normal.y,this.shift=this.normal.shift,this.scrollTop=this.normal.scrollTop,this.scrollBottom=this.normal.scrollBottom,this.tabs=this.normal.tabs,this.curAttr=this.normal.curAttr,this.normal=null,this.refresh(!0),this.showCursor()}}else switch(a){case 4:this.insertMode=!1;break;case 20:this.convertEol=!1}else for(c=a.length,b=0;c>b;)this.resetMode(a[b]),b++},a.prototype.setScrollRegion=function(a){return this.prefix?void 0:(this.scrollTop=(a[0]||1)-1,this.scrollBottom=(a[1]||this.rows)-1,this.x=0,this.y=0)},a.prototype.saveCursor=function(a){return this.savedX=this.x,this.savedY=this.y},a.prototype.restoreCursor=function(a){return this.x=this.savedX||0,this.y=this.savedY||0},a.prototype.cursorForwardTab=function(a){var b,c;for(b=a[0]||1,c=[];b--;)c.push(this.x=this.nextStop());return c},a.prototype.scrollUp=function(a){var b,c,d,e,f,g;for(d=a[0]||1;d--;)this.screen.splice(this.scrollTop,1),this.screen.splice(this.scrollBottom,0,this.blankLine());for(g=[],b=c=e=this.scrollTop,f=this.scrollBottom;f>=e?f>=c:c>=f;b=f>=e?++c:--c)g.push(this.screen[b+this.shift].dirty=!0);return g},a.prototype.scrollDown=function(a){var b,c,d,e,f,g;for(d=a[0]||1;d--;)this.screen.splice(this.scrollBottom,1),this.screen.splice(this.scrollTop,0,this.blankLine());for(g=[],b=c=e=this.scrollTop,f=this.scrollBottom;f>=e?f>=c:c>=f;b=f>=e?++c:--c)g.push(this.screen[b+this.shift].dirty=!0);return g},a.prototype.initMouseTracking=function(a){},a.prototype.resetTitleModes=function(a){},a.prototype.cursorBackwardTab=function(a){var b,c;for(b=a[0]||1,c=[];b--;)c.push(this.x=this.prevStop());return c},a.prototype.repeatPrecedingCharacter=function(a){var b,c,d;for(d=a[0]||1,c=this.screen[this.y+this.shift].chars,b=c[this.x-1]||this.defAttr;d--;)c[this.x++]=b;return this.screen[this.y+this.shift].dirty=!0},a.prototype.tabClear=function(a){var b;return b=a[0],0>=b?delete this.tabs[this.x]:3===b?this.tabs={}:void 0},a.prototype.mediaCopy=function(a){},a.prototype.setResources=function(a){},a.prototype.disableModifiers=function(a){},a.prototype.setPointerMode=function(a){},a.prototype.softReset=function(a){return this.cursorHidden=!1,this.insertMode=!1,this.originMode=!1,this.autowrap=!0,this.applicationKeypad=!1,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]},a.prototype.requestAnsiMode=function(a){},a.prototype.requestPrivateMode=function(a){},a.prototype.setConformanceLevel=function(a){},a.prototype.loadLEDs=function(a){},a.prototype.setCursorStyle=function(a){},a.prototype.setCharProtectionAttr=function(a){},a.prototype.restorePrivateValues=function(a){},a.prototype.setAttrInRectangle=function(a){var b,c,d,e,f,g,h,i;for(i=a[0],e=a[1],c=a[2],g=a[3],b=a[4],h=[];c+1>i;){for(f=this.screen[i+this.shift].chars,this.screen[i+this.shift].dirty=!0,d=e;g>d;)f[d]=this.cloneAttr(b,f[d].ch),d++;h.push(i++)}return h},a.prototype.savePrivateValues=function(a){},a.prototype.manipulateWindow=function(a){},a.prototype.reverseAttrInRectangle=function(a){},a.prototype.setTitleModeFeature=function(a){},a.prototype.setWarningBellVolume=function(a){},a.prototype.setMarginBellVolume=function(a){},a.prototype.copyRectangle=function(a){},a.prototype.enableFilterRectangle=function(a){},a.prototype.requestParameters=function(a){},a.prototype.selectChangeExtent=function(a){},a.prototype.fillRectangle=function(a){var b,c,d,e,f,g,h,i;for(c=a[0],i=a[1],e=a[2],b=a[3],g=a[4],h=[];b+1>i;){for(f=this.screen[i+this.shift].chars,this.screen[i+this.shift].dirty=!0,d=e;g>d;)f[d]=this.cloneAttr(f[d][0],String.fromCharCode(c)),d++;h.push(i++)}return h},a.prototype.enableLocatorReporting=function(a){var b;return b=a[0]>0},a.prototype.eraseRectangle=function(a){var b,c,d,e,f,g,h;for(h=a[0],d=a[1],b=a[2],f=a[3],g=[];b+1>h;){for(e=this.screen[h+this.shift].chars,this.screen[h+this.shift].dirty=!0,c=d;f>c;)e[c]=this.eraseAttr(),c++;g.push(h++)}return g},a.prototype.setLocatorEvents=function(a){},a.prototype.selectiveEraseRectangle=function(a){},a.prototype.requestLocatorPosition=function(a){},a.prototype.insertColumns=function(){var a,b,c,d;for(c=params[0],b=this.rows+this.shift,d=[];c--;)a=this.shift,d.push(function(){var c;for(c=[];b>a;)this.screen[a].chars.splice(this.x+1,0,this.eraseAttr()),this.screen[a].chars.pop(),this.screen[a].dirty=!0,c.push(a++);return c}.call(this));return d},a.prototype.deleteColumns=function(){var a,b,c,d;for(c=params[0],b=this.rows+this.shift,d=[];c--;)a=this.shift,d.push(function(){var c;for(c=[];b>a;)this.screen[a].chars.splice(this.x,1),this.screen[a].chars.push(this.eraseAttr()),this.resetLine(this.screen[a].dirty),c.push(a++);return c}.call(this));return d},a.prototype.charsets={SCLD:{"`":"◆",a:"▒",b:" ",c:"\f",d:"\r",e:"\n",f:"°",g:"±",h:"␤",i:"\x0B",j:"┘",k:"┐",l:"┌",m:"└",n:"┼",o:"⎺",p:"⎻",q:"─",r:"⎼",s:"⎽",t:"├",u:"┤",v:"┴",w:"┬",x:"│",y:"≤",z:"≥","{":"π","|":"≠","}":"£","~":"·"},UK:null,US:null,Dutch:null,Finnish:null,French:null,FrenchCanadian:null,German:null,Italian:null,NorwegianDanish:null,Spanish:null,Swedish:null,Swiss:null,ISOLatin:null},a}(),window.Terminal=c}).call(this); //# sourceMappingURL=main.min.js.map \ No newline at end of file diff --git a/coffees/ext/expand_extended.coffee b/coffees/ext/expand_extended.coffee index 794a9b2..a842937 100644 --- a/coffees/ext/expand_extended.coffee +++ b/coffees/ext/expand_extended.coffee @@ -1,11 +1,10 @@ -Terminal.on 'change', (lines) -> - for line in lines - if 'extended' in line.classList - line.addEventListener 'click', do (line) -> -> - if 'expanded' in line.classList - line.classList.remove 'expanded' - else - before = line.getBoundingClientRect().height - line.classList.add 'expanded' - after = line.getBoundingClientRect().height - document.body.scrollTop += after - before +Terminal.on 'change', (line) -> + if 'extended' in line.classList + line.addEventListener 'click', do (line) -> -> + if 'expanded' in line.classList + line.classList.remove 'expanded' + else + before = line.getBoundingClientRect().height + line.classList.add 'expanded' + after = line.getBoundingClientRect().height + document.body.scrollTop += after - before diff --git a/coffees/ext/linkify.coffee b/coffees/ext/linkify.coffee index 7669f46..3c7dfbd 100644 --- a/coffees/ext/linkify.coffee +++ b/coffees/ext/linkify.coffee @@ -14,13 +14,12 @@ linkify = (text) -> .replace(pseudoUrlPattern, '$1$2') .replace(emailAddressPattern, '$&') -Terminal.on 'change', (lines) -> - for line in lines - walk line, -> - if @nodeType is 3 - linkified = linkify @nodeValue - if linkified isnt @nodeValue - newNode = document.createElement('span') - newNode.innerHTML = linkified - @parentElement.replaceChild newNode, @ - true +Terminal.on 'change', (line) -> + walk line, -> + if @nodeType is 3 + linkified = linkify @nodeValue + if linkified isnt @nodeValue + newNode = document.createElement('span') + newNode.innerHTML = linkified + @parentElement.replaceChild newNode, @ + true diff --git a/coffees/term.coffee b/coffees/term.coffee index 5f00243..d1e9f81 100644 --- a/coffees/term.coffee +++ b/coffees/term.coffee @@ -84,7 +84,7 @@ class Terminal px = window.innerHeight % @charSize.height @body.style['padding-bottom'] = "#{px}px" - @scrollback = 1000000 + @scrollback = 10000 @buffSize = 100000 @visualBell = 100 @@ -114,12 +114,17 @@ class Terminal @initmouse() addEventListener 'load', => @resize() @emit 'load' + @active = null + Terminal.on 'change', (line) => + @active = line if line.classList.contains 'active' - emit: (hook, args...) -> + emit: (hook, obj) -> unless Terminal.hooks[hook]? Terminal.hooks[hook] = [] for fun in Terminal.hooks[hook] - fun.apply(@, args) + # fun.call(@, obj) + setTimeout ((f) -> -> + f.call(@, obj))(fun), 10 cloneAttr: (a, char=null) -> bg: a.bg @@ -415,157 +420,170 @@ class Terminal sendButton ev cancel ev - refresh: (force=false) -> - for cursor in @body.querySelectorAll(".cursor") - cursor.parentNode.replaceChild( - @document.createTextNode(cursor.textContent), cursor) - for active in @body.querySelectorAll(".line.active") - active.classList.remove('active') + _putChar: (data, attr, i, x) -> + out = '' + ch = data.ch + unless @equalAttr data, attr + out += "" unless @equalAttr attr, @defAttr + unless @equalAttr data, @defAttr + classes = [] + styles = [] + out += "" if i is x + + # This is a temporary dirty hack for raw html insertion + if ch.length > 1 + out += ch + else + switch ch + when "&" + out += "&" + when "<" + out += "<" + when ">" + out += ">" + else + if ch == " " + out += '\u2007' + else if ch <= " " + out += " " + else if not @forceWidth or ch <= "~" # Ascii chars + out += ch + else if "\uff00" < ch < "\uffef" + skipnext = true + out += "#{ch}" + else + out += "#{ch}" + + out += "" if i is x + out + + _putLine: (x, j, outs, line) -> + @screen[j].dirty = false + if @children[j] + @children[j].innerHTML = outs.join('') + @emit 'change', @children[j] + if x isnt null + @children[j].classList.add 'active' + if line.extra + @children[j].classList.add 'extended' + null + else + cls = ['line'] + if x isnt null + cls.push 'active' + if line.extra + cls.push 'extended' + "
#{outs.join('')}
" + + _replotScreen: (force) -> + groups = [] for line, j in @screen continue unless line.dirty or force - out = "" - - if j is @y + @shift and not @cursorHidden - x = @x - else - x = -Infinity + x = null + x = @x if j is @y + @shift and not @cursorHidden attr = @cloneAttr @defAttr skipnext = false + outs = [] for i in [0..@cols - 1] data = line.chars[i] if data.html - out += data.html + outs.push data.html break if skipnext skipnext = false continue - ch = data.ch - unless @equalAttr data, attr - out += "" unless @equalAttr attr, @defAttr - unless @equalAttr data, @defAttr - classes = [] - styles = [] - out += "" if i is x - - # This is a temporary dirty hack for raw html insertion - if ch.length > 1 - out += ch - else - switch ch - when "&" - out += "&" - when "<" - out += "<" - when ">" - out += ">" - else - if ch == " " - out += '\u2007' - else if ch <= " " - out += " " - else if not @forceWidth or ch <= "~" # Ascii chars - out += ch - else if "\uff00" < ch < "\uffef" - skipnext = true - out += "#{ch}" - else - out += "#{ch}" - - out += "" if i is x + outs.push @_putChar data, attr, i, x attr = data + + out = '' out += "" unless @equalAttr attr, @defAttr out += '\u23CE' if line.wrap if line.extra out += '' + line.extra + '' - if @children[j] - @children[j].innerHTML = out - modified.push @children[j] - if x isnt -Infinity - @children[j].classList.add 'active' - if line.extra - @children[j].classList.add 'extended' - else - cls = ['line'] - if x isnt -Infinity - cls.push 'active' - if line.extra - cls.push 'extended' - newOut += "
#{out}
" - @screen[j].dirty = false + outs.push out - if newOut isnt '' - group = @document.createElement('div') - group.className = 'group' - group.innerHTML = newOut - modified.push group - @body.appendChild group - @screen = @screen.slice(-@rows) - @shift = 0 + group = @_putLine x, j, outs, line + groups.push group if group + @_putGroup groups if groups.length - lines = document.querySelectorAll('.line') - if lines.length > @scrollback - for line in Array.prototype.slice.call( - lines, 0, lines.length - @scrollback) - line.remove() - for group in document.querySelectorAll('.group:empty') - group.remove() - lines = document.querySelectorAll('.line') - @children = Array.prototype.slice.call( - lines, -@rows) + _putGroup: (groups) -> + group = @document.createElement('div') + group.className = 'group' + group.innerHTML = groups.join('') + if true or groups.length > 1 + nodes = group.childNodes + node = group + else + nodes = [group.firstChild] + node = group.firstChild + @body.appendChild node + for node in nodes + if @children.length >= @rows + @children.pop() + @emit 'change', node + @children.push node + @screen = @screen.slice(-@rows) + @shift = 0 + + if @body.childElementCount > @scrollback + @body.style.display = 'none' + for i in [0..@body.childElementCount - @scrollback] + @body.firstChild.remove() + @body.style.display = 'block' + + refresh: (force=false) -> + @active?.classList.remove('active') + @_replotScreen(force) @nativeScrollTo() - @emit 'change', modified _cursorBlink: -> @cursorState ^= 1 @@ -1607,6 +1625,7 @@ class Terminal j = oldRows if j < @rows el = @body + @body.style.display = 'none' while j++ < @rows @screen.push @blankLine() if @screen.length < @rows if @children.length < @rows @@ -1614,6 +1633,7 @@ class Terminal line.className = 'line' el.appendChild line @children.push line + @body.style.display = 'block' else if j > @rows while j-- > @rows @screen.pop() if @screen.length > @rows