diff --git a/butterfly/static/ext.min.js b/butterfly/static/ext.min.js index c717acc..8e2cce3 100644 --- a/butterfly/static/ext.min.js +++ b/butterfly/static/ext.min.js @@ -1,4 +1,4 @@ -/*! butterfly 2016-10-12 */ +/*! butterfly 2016-10-13 */ -(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); +(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){return s.call(a.classList,"extended")>=0?a.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)}}(a)):void 0}),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){return r(a,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})}),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 c91c94c..bb5ad42 100644 --- a/butterfly/static/main.js +++ b/butterfly/static/main.js @@ -177,6 +177,7 @@ this.document = this.parent.ownerDocument; this.html = this.document.getElementsByTagName('html')[0]; this.body = this.document.getElementsByTagName('body')[0]; + this.term = this.document.getElementById('term'); this.forceWidth = this.body.getAttribute('data-force-unicode-width') === 'yes'; this.body.className = 'terminal focus'; this.body.style.outline = 'none'; @@ -184,13 +185,11 @@ this.body.setAttribute('spellcheck', 'false'); div = this.document.createElement('div'); div.className = 'line'; - this.body.appendChild(div); - this.children = [div]; + this.term.appendChild(div); this.computeCharSize(); this.cols = Math.floor(this.body.clientWidth / this.charSize.width); this.rows = Math.floor(window.innerHeight / this.charSize.height); px = window.innerHeight % this.charSize.height; - this.body.style['padding-bottom'] = px + "px"; this.scrollback = 10000; this.buffSize = 100000; this.visualBell = 100; @@ -280,7 +279,7 @@ }; Terminal.prototype.resetVars = function() { - var i; + var k, ref, row; this.x = 0; this.y = 0; this.cursorHidden = false; @@ -317,9 +316,8 @@ this.currentParam = 0; this.prefix = ""; this.screen = []; - i = this.rows; this.shift = 0; - while (i--) { + for (row = k = 0, ref = this.rows; 0 <= ref ? k <= ref : k >= ref; row = 0 <= ref ? ++k : --k) { this.screen.push(this.blankLine(false, false)); } this.setupStops(); @@ -327,15 +325,16 @@ }; Terminal.prototype.computeCharSize = function() { - var testSpan; + var line, testSpan; testSpan = document.createElement('span'); testSpan.textContent = '0123456789'; - this.children[0].appendChild(testSpan); + line = this.term.firstChild; + line.appendChild(testSpan); this.charSize = { width: testSpan.getBoundingClientRect().width / 10, - height: this.children[0].getBoundingClientRect().height + height: line.getBoundingClientRect().height }; - return this.children[0].removeChild(testSpan); + return line.removeChild(testSpan); }; Terminal.prototype.eraseAttr = function() { @@ -705,34 +704,31 @@ }; Terminal.prototype.writeDom = function(dom) { - var i, k, len, line, m, ref, y; + var frag, i, k, len, line, m, r, ref, results, y; + r = Math.max(this.term.childElementCount - this.rows, 0); for (y = k = 0, len = dom.length; k < len; y = ++k) { line = dom[y]; if (!line) { continue; } this.screen[y].dirty = false; - if (y < this.children.length) { - this.body.replaceChild(line, this.children[y]); - this.children[y] = line; - this.emit('change', this.children[y]); + if (y < this.rows && y < this.term.childElementCount) { + this.term.replaceChild(line, this.term.childNodes[r + y]); } else { - if (this.children.length >= this.rows) { - this.children.shift(); - } - this.body.appendChild(line); - this.children.push(line); - this.emit('change', line); + frag = frag || document.createDocumentFragment('fragment'); + frag.appendChild(line); } + this.emit('change', line); } - this.screen = this.screen.slice(-this.rows); + frag && this.term.appendChild(frag); 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(); + this.screen = this.screen.slice(-this.rows); + if (this.term.childElementCount > this.scrollback) { + results = []; + for (i = m = 0, ref = this.term.childElementCount - this.scrollback; 0 <= ref ? m <= ref : m >= ref; i = 0 <= ref ? ++m : --m) { + results.push(this.term.firstChild.remove()); } - return this.body.style.display = 'block'; + return results; } }; @@ -752,7 +748,7 @@ Terminal.prototype._cursorBlink = function() { var cursor; this.cursorState ^= 1; - cursor = this.body.querySelector(".cursor"); + cursor = this.term.querySelector(".cursor"); if (!cursor) { return; } @@ -1705,7 +1701,7 @@ }; Terminal.prototype.resize = function(x, y, notif) { - var h, i, j, oldCols, oldRows, px, w; + var h, insert, k, len, len1, len2, len3, line, m, n, o, oldCols, oldRows, ref, ref1, ref2, ref3, w; if (x == null) { x = null; } @@ -1726,8 +1722,6 @@ } this.cols = x || Math.floor(w / this.charSize.width); this.rows = y || Math.floor(h / this.charSize.height); - px = h % this.charSize.height; - this.body.style['padding-bottom'] = px + "px"; this.cols = Math.max(1, this.cols); this.rows = Math.max(1, this.rows); this.nativeScrollTo(); @@ -1741,67 +1735,62 @@ rows: this.rows })); } - if (oldCols < this.cols) { - i = this.screen.length; - while (i--) { - while (this.screen[i].chars.length < this.cols) { - this.screen[i].chars.push(this.defAttr); + if (this.cols > oldCols) { + ref = this.screen; + for (k = 0, len = ref.length; k < len; k++) { + line = ref[k]; + while (line.chars.length < this.cols) { + line.chars.push(this.defAttr); } - this.screen[i].wrap = false; + line.wrap = false; } - } else if (oldCols > this.cols) { - i = this.screen.length; - while (i--) { - while (this.screen[i].chars.length > this.cols) { - this.screen[i].chars.pop(); + if (this.normal) { + ref1 = this.normal.screen; + for (m = 0, len1 = ref1.length; m < len1; m++) { + line = ref1[m]; + while (line.chars.length < this.cols) { + line.chars.push(this.defAttr); + } + line.wrap = false; + } + } + } else if (this.cols < oldCols) { + ref2 = this.screen; + for (n = 0, len2 = ref2.length; n < len2; n++) { + line = ref2[n]; + while (line.chars.length > this.cols) { + line.chars.pop(); + } + } + if (this.normal) { + ref3 = this.normal.screen; + for (o = 0, len3 = ref3.length; o < len3; o++) { + line = ref3[o]; + while (line.chars.length > this.cols) { + line.chars.pop(); + } } } } this.setupStops(oldCols); - j = oldRows; - if (j < this.rows) { - while (j++ < this.rows) { - if (this.screen.length < this.rows) { - this.screen.push(this.blankLine()); - } - } - } else if (j > this.rows) { - while (j-- > this.rows) { - if (this.screen.length > this.rows) { - this.screen.pop(); - } - } + if (this.term.childElementCount >= this.rows) { + this.y += this.rows - oldRows; + insert = 'unshift'; + } else { + insert = 'push'; + } + while (this.screen.length > this.rows) { + this.screen.shift(); + } + while (this.screen.length < this.rows) { + this.screen[insert](this.blankLine(false, false)); } if (this.normal) { - if (oldCols < this.cols) { - i = this.normal.screen.length; - while (i--) { - while (this.normal.screen[i].chars.length < this.cols) { - this.normal.screen[i].chars.push(this.defAttr); - } - this.normal.screen[i].wrap = false; - } - } else if (oldCols > this.cols) { - i = this.normal.screen.length; - while (i--) { - while (this.normal.screen[i].chars.length > this.cols) { - this.normal.screen[i].chars.pop(); - } - } + while (this.normal.screen.length > this.rows) { + this.normal.screen.shift(); } - j = oldRows; - if (j < this.rows) { - while (j++ < this.rows) { - if (this.normal.screen.length < this.rows) { - this.normal.screen.push(this.blankLine()); - } - } - } else if (j > this.rows) { - while (j-- > this.rows) { - if (this.normal.screen.length > this.rows) { - this.normal.screen.pop(); - } - } + while (this.normal.screen.length < this.rows) { + this.normal.screen[insert](this.blankLine(false, false)); } } if (this.y >= this.rows) { @@ -1812,7 +1801,7 @@ } this.scrollTop = 0; this.scrollBottom = this.rows - 1; - this.refresh(true); + this.refresh(); if (!notif && (x || y)) { return this.reset(); } @@ -1966,22 +1955,12 @@ }; Terminal.prototype.clearScrollback = function() { - var group, k, len, len1, line, lines, m, ref, ref1; - lines = document.querySelectorAll('.line'); - if (lines.length > this.rows) { - ref = Array.prototype.slice.call(lines, 0, lines.length - this.rows); - for (k = 0, len = ref.length; k < len; k++) { - line = ref[k]; - line.remove(); - } - ref1 = document.querySelectorAll('.group:empty'); - for (m = 0, len1 = ref1.length; m < len1; m++) { - group = ref1[m]; - group.remove(); - } - lines = document.querySelectorAll('.line'); + var results; + results = []; + while (this.term.childElementCount > this.rows) { + results.push(this.term.firstChild.remove()); } - return this.children = Array.prototype.slice.call(lines, -this.rows); + return results; }; Terminal.prototype.tabSet = function() { @@ -2298,7 +2277,7 @@ }; Terminal.prototype.deleteLines = function(params) { - var i, k, param, ref, ref1, results; + var i, k, node, param, ref, ref1, results; param = params[0]; if (param < 1) { param = 1; @@ -2307,8 +2286,8 @@ this.screen.splice(this.scrollBottom + this.shift, 0, this.blankLine(true)); this.screen.splice(this.y + this.shift, 1); if (!(this.normal || this.scrollTop !== 0 || this.scrollBottom !== this.rows - 1)) { - this.children[this.y + this.shift].remove(); - this.children.splice(this.y + this.shift, 1); + node = this.term.childElementCount - this.rows + this.y + this.shift; + this.term.childNodes[node].remove(); } } if (this.normal || this.scrollTop !== 0 || this.scrollBottom !== this.rows - 1) { diff --git a/butterfly/static/main.min.js b/butterfly/static/main.min.js index 8e531ea..1d2c5ff 100644 --- a/butterfly/static/main.min.js +++ b/butterfly/static/main.min.js @@ -1,5 +1,5 @@ -/*! butterfly 2016-10-12 */ +/*! butterfly 2016-10-13 */ -(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); +(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.term=this.document.getElementById("term"),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.term.appendChild(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.scrollback=1e4,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"),this.active=null}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(setTimeout(function(a){return function(){return a.call(this,c)}}(d),10));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,c,d;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=[],this.shift=0,d=a=0,c=this.rows;c>=0?c>=a:a>=c;d=c>=0?++a:--a)this.screen.push(this.blankLine(!1,!1));return this.setupStops(),this.skipNextKey=null},a.prototype.computeCharSize=function(){var a,b;return b=document.createElement("span"),b.textContent="0123456789",a=this.term.firstChild,a.appendChild(b),this.charSize={width:b.getBoundingClientRect().width/10,height:a.getBoundingClientRect().height},a.removeChild(b)},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.getClasses=function(a){var b,c,d;return b=[],d=[],a.bold&&b.push("bold"),a.underline&&b.push("underline"),1===a.blink&&b.push("blink"),2===a.blink&&b.push("blink-fast"),a.inverse&&b.push("reverse-video"),a.invisible&&b.push("invisible"),a.italic&&b.push("italic"),a.faint&&b.push("faint"),a.crossed&&b.push("crossed"),"number"==typeof a.fg?(c=a.fg,a.bold&&8>c&&(c+=8),b.push("fg-color-"+c)):"string"==typeof a.fg&&d.push("color: "+a.fg),"number"==typeof a.bg?b.push("bg-color-"+a.bg):"string"==typeof a.bg&&d.push("background-color: "+a.bg),[b,d]},a.prototype.charToDom=function(a,b,c){var d,e,f,g,h;if(a.html)return a.html;switch(b=b||this.cloneAttr(this.defAttr),d=a.ch,e="",this.equalAttr(a,b)||(this.equalAttr(b,this.defAttr)||(e+=""),this.equalAttr(a,this.defAttr)||(g=this.getClasses(a),f=g[0],h=g[1],e+=''),d){case"&":e+="&";break;case"<":e+="<";break;case">":e+=">";break;case" ":e+='';break;default:e+=" ">=d?" ":this.forceWidth?"~">=d?d:d>"＀"&&"￯">d?''+d+"":''+d+"":d}return c&&(e+=""),e},a.prototype.lineToDom=function(a,b,c){var d,e,f,g,h,i;for(c&&(d=this.x),h=[],i=f=0,g=this.cols;g>=0?g>=f:f>=g;i=g>=0?++f:--f)i!==this.cols?h.push(this.charToDom(b.chars[i],b.chars[i-1],i===d)):(e="",this.equalAttr(b.chars[i-1],this.defAttr)||(e+=""),b.wrap&&(e+="⏎"),b.extra?h.push(e+=''+b.extra+""):h.push(void 0));return h},a.prototype.screenToDom=function(a){var b,c,d,e,f,g,h,i;for(g=this.screen,h=[],i=d=0,e=g.length;e>d;i=++d)f=g[i],f.dirty||a?(b=i===this.y+this.shift&&!this.cursorHidden,c=document.createElement("div"),c.classList.add("line"),b&&c.classList.add("active"),f.extra&&c.classList.add("extended"),c.innerHTML=this.lineToDom(i,f,b).join(""),h.push(this.active=c)):h.push(void 0);return h},a.prototype.writeDom=function(a){var b,c,d,e,f,g,h,i,j,k;for(h=Math.max(this.term.childElementCount-this.rows,0),k=d=0,e=a.length;e>d;k=++d)f=a[k],f&&(this.screen[k].dirty=!1,kthis.scrollback){for(j=[],c=g=0,i=this.term.childElementCount-this.scrollback;i>=0?i>=g:g>=i;c=i>=0?++g:--g)j.push(this.term.firstChild.remove());return j}},a.prototype.refresh=function(a){var b,c;return null==a&&(a=!1),null!=(c=this.active)&&c.classList.remove("active"),b=this.screenToDom(a),this.writeDom(b),this.nativeScrollTo()},a.prototype._cursorBlink=function(){var a;return this.cursorState^=1,(a=this.term.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,m,n,o,p,q,r,s,t,u;if(null==a&&(a=null),null==b&&(b=null),null==c&&(c=!1),o=this.cols,p=this.rows,this.computeCharSize(),u=this.body.clientWidth,d=this.html.clientHeight,0===this.charSize.width||0===this.charSize.height)return void console.error("Null size in refresh");if(this.cols=a||Math.floor(u/this.charSize.width),this.rows=b||Math.floor(d/this.charSize.height),this.cols=Math.max(1,this.cols),this.rows=Math.max(1,this.rows),this.nativeScrollTo(),a||b||o!==this.cols||p!==this.rows){if(c||this.ctl(JSON.stringify({cmd:"size",cols:this.cols,rows:this.rows})),this.cols>o){for(q=this.screen,f=0,g=q.length;g>f;f++){for(k=q[f];k.chars.lengthl;l++){for(k=r[l];k.chars.lengthm;m++)for(k=s[m];k.chars.length>this.cols;)k.chars.pop();if(this.normal)for(t=this.normal.screen,n=0,j=t.length;j>n;n++)for(k=t[n];k.chars.length>this.cols;)k.chars.pop()}for(this.setupStops(o),this.term.childElementCount>=this.rows?(this.y+=this.rows-p,e="unshift"):e="push";this.screen.length>this.rows;)this.screen.shift();for(;this.screen.lengththis.rows;)this.normal.screen.shift();for(;this.normal.screen.length=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(),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;)a.push(this.term.firstChild.remove());return a},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,h;for(e=a[0],1>e&&(e=1);e--;)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||(d=this.term.childElementCount-this.rows+this.y+this.shift,this.term.childNodes[d].remove());if(this.normal||0!==this.scrollTop||this.scrollBottom!==this.rows-1){for(h=[],b=c=f=this.y+this.shift,g=this.screen.length-1;g>=f?g>=c:c>=g;b=g>=f?++c:--c)h.push(this.screen[b].dirty=!0);return h}},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/butterfly/templates/index.html b/butterfly/templates/index.html index b501bab..898f40b 100644 --- a/butterfly/templates/index.html +++ b/butterfly/templates/index.html @@ -24,5 +24,6 @@ +
diff --git a/coffees/term.coffee b/coffees/term.coffee index 5cc50de..6d505cc 100644 --- a/coffees/term.coffee +++ b/coffees/term.coffee @@ -63,6 +63,7 @@ class Terminal @document = @parent.ownerDocument @html = @document.getElementsByTagName('html')[0] @body = @document.getElementsByTagName('body')[0] + @term = @document.getElementById('term') @forceWidth = @body.getAttribute( 'data-force-unicode-width') is 'yes' @@ -75,14 +76,12 @@ class Terminal # Adding one line to compute char size div = @document.createElement('div') div.className = 'line' - @body.appendChild(div) - @children = [div] + @term.appendChild(div) @computeCharSize() @cols = Math.floor(@body.clientWidth / @charSize.width) @rows = Math.floor(window.innerHeight / @charSize.height) px = window.innerHeight % @charSize.height - @body.style['padding-bottom'] = "#{px}px" @scrollback = 10000 @buffSize = 100000 @@ -198,20 +197,21 @@ class Terminal @currentParam = 0 @prefix = "" @screen = [] - i = @rows @shift = 0 - @screen.push @blankLine(false, false) while i-- + for row in [0..@rows] + @screen.push @blankLine(false, false) @setupStops() @skipNextKey = null computeCharSize: -> testSpan = document.createElement('span') testSpan.textContent = '0123456789' - @children[0].appendChild(testSpan) + line = @term.firstChild + line.appendChild(testSpan) @charSize = width: testSpan.getBoundingClientRect().width / 10 - height: @children[0].getBoundingClientRect().height - @children[0].removeChild(testSpan) + height: line.getBoundingClientRect().height + line.removeChild(testSpan) eraseAttr: -> erased = @cloneAttr @defAttr @@ -520,29 +520,24 @@ class Terminal @active = div writeDom: (dom) -> - # frag = document.createDocumentFragment('fragment') + r = Math.max @term.childElementCount - @rows, 0 for line, y in dom continue unless line @screen[y].dirty = false - if y < @children.length - @body.replaceChild line, @children[y] - @children[y] = line - @emit 'change', @children[y] + if y < @rows and y < @term.childElementCount + @term.replaceChild(line, @term.childNodes[r + y]) else - @children.shift() if @children.length >= @rows - @body.appendChild line - @children.push line - @emit 'change', line + frag = frag or document.createDocumentFragment('fragment') + frag.appendChild line + @emit 'change', line - # @body.appendChild frag + frag and @term.appendChild frag - @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' + @screen = @screen.slice -@rows + if @term.childElementCount > @scrollback + for i in [0..@term.childElementCount - @scrollback] + @term.firstChild.remove() refresh: (force=false) -> @active?.classList.remove('active') @@ -552,7 +547,7 @@ class Terminal _cursorBlink: -> @cursorState ^= 1 - cursor = @body.querySelector(".cursor") + cursor = @term.querySelector(".cursor") return unless cursor if cursor.classList.contains("reverse-video") cursor.classList.remove "reverse-video" @@ -1558,8 +1553,6 @@ class Terminal return @cols = x or Math.floor(w / @charSize.width) @rows = y or Math.floor(h / @charSize.height) - px = h % @charSize.height - @body.style['padding-bottom'] = "#{px}px" @cols = Math.max 1, @cols @rows = Math.max 1, @rows @@ -1572,72 +1565,50 @@ class Terminal cmd: 'size', cols: @cols, rows: @rows)) unless notif # resize cols - if oldCols < @cols + if @cols > oldCols # does xterm use the default attr? - i = @screen.length - while i-- - @screen[i].chars.push @defAttr while @screen[i].chars.length < @cols - @screen[i].wrap = false + for line in @screen + line.chars.push @defAttr while line.chars.length < @cols + line.wrap = false + if @normal + for line in @normal.screen + line.chars.push @defAttr while line.chars.length < @cols + line.wrap = false - else if oldCols > @cols - i = @screen.length - while i-- - @screen[i].chars.pop() while @screen[i].chars.length > @cols + else if @cols < oldCols + for line in @screen + line.chars.pop() while line.chars.length > @cols + if @normal + for line in @normal.screen + line.chars.pop() while line.chars.length > @cols @setupStops oldCols + if @term.childElementCount >= @rows + @y += @rows - oldRows + insert = 'unshift' + else + insert = 'push' + # resize rows - j = oldRows - if j < @rows - # @body.style.display = 'none' - while j++ < @rows - @screen.push @blankLine() if @screen.length < @rows - # if @children.length < @rows - # line = @document.createElement("div") - # line.className = 'line' - # @body.appendChild line - # @children.push line - # @body.style.display = 'block' - else if j > @rows - while j-- > @rows - @screen.pop() if @screen.length > @rows - # if @children.length > @rows - # el = @children.pop() - # el?.parentNode.removeChild el + while @screen.length > @rows + @screen.shift() + while @screen.length < @rows + @screen[insert] @blankLine(false, false) if @normal - # resize cols - if oldCols < @cols - # does xterm use the default attr? - i = @normal.screen.length - while i-- - while @normal.screen[i].chars.length < @cols - @normal.screen[i].chars.push @defAttr - @normal.screen[i].wrap = false - - else if oldCols > @cols - i = @normal.screen.length - while i-- - while @normal.screen[i].chars.length > @cols - @normal.screen[i].chars.pop() - - # resize rows - j = oldRows - if j < @rows - while j++ < @rows - @normal.screen.push @blankLine() if @normal.screen.length < @rows - else if j > @rows - while j-- > @rows - @normal.screen.pop() if @normal.screen.length > @rows + while @normal.screen.length > @rows + @normal.screen.shift() + while @normal.screen.length < @rows + @normal.screen[insert] @blankLine(false, false) # make sure the cursor stays on screen @y = @rows - 1 if @y >= @rows @x = @cols - 1 if @x >= @cols - @scrollTop = 0 @scrollBottom = @rows - 1 - @refresh(true) + @refresh() @reset() if not notif and (x or y) resizeWindowPlease: (cols) -> @@ -1737,17 +1708,8 @@ class Terminal clearScrollback: -> # In case of real hard reset # Drop DOM history - lines = document.querySelectorAll('.line') - if lines.length > @rows - for line in Array.prototype.slice.call( - lines, 0, lines.length - @rows) - line.remove() - for group in document.querySelectorAll('.group:empty') - group.remove() - lines = document.querySelectorAll('.line') - @children = Array.prototype.slice.call( - lines, -@rows) - + while @term.childElementCount > @rows + @term.firstChild.remove() # ESC H Tab Set (HTS is 0x88). tabSet: -> @@ -2168,8 +2130,8 @@ class Terminal @screen.splice @scrollBottom + @shift, 0, @blankLine(true) @screen.splice @y + @shift, 1 unless @normal or @scrollTop isnt 0 or @scrollBottom isnt @rows - 1 - @children[@y + @shift].remove() - @children.splice @y + @shift, 1 + node = @term.childElementCount - @rows + @y + @shift + @term.childNodes[node].remove() if @normal or @scrollTop isnt 0 or @scrollBottom isnt @rows - 1 for i in [@y + @shift..@screen.length - 1]