diff --git a/butterfly/__init__.py b/butterfly/__init__.py index 298c72e..abbb694 100644 --- a/butterfly/__init__.py +++ b/butterfly/__init__.py @@ -14,7 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = '2.0.3' +__version__ = '2.1.0' import os diff --git a/butterfly/routes.py b/butterfly/routes.py index 60b6605..d7e4276 100644 --- a/butterfly/routes.py +++ b/butterfly/routes.py @@ -119,7 +119,6 @@ class TermCtlWebSocket(Route, tornado.websocket.WebSocketHandler): sessions_secure_users = {} def open(self, session): - self.set_nodelay(True) self.session = session self.closed = False self.log.info('Websocket /ctl opened %r' % self) @@ -145,18 +144,24 @@ class TermCtlWebSocket(Route, tornado.websocket.WebSocketHandler): # Certificate authed user secure_user = user - elif socket.local and socket.user == utils.User(): + elif socket.local and socket.user == utils.User() and not user: # Local to local returning browser user secure_user = socket.user + elif user: + try: + user = utils.User(name=user) + except LookupError: + raise Exception('Invalid user') if secure_user: - user = secure_user.name - if self.session in self.sessions: - if user != self.sessions_secure_users[self.session]: + user = secure_user + if self.session in self.sessions and self.session in ( + self.sessions_secure_users): + if user.name != self.sessions_secure_users[self.session]: # Restrict to authorized users raise tornado.web.HTTPError(403) else: - self.sessions_secure_users[self.session] = user + self.sessions_secure_users[self.session] = user.name self.sessions[self.session].append(self) @@ -192,7 +197,11 @@ class TermCtlWebSocket(Route, tornado.websocket.WebSocketHandler): if cmd['cmd'] == 'open': self.create_terminal() else: - Terminal.sessions[self.session].ctl(cmd) + try: + Terminal.sessions[self.session].ctl(cmd) + except Exception: + # FF strange bug + pass self.broadcast(self.session, message, self) def on_close(self): @@ -203,6 +212,14 @@ class TermCtlWebSocket(Route, tornado.websocket.WebSocketHandler): if self in self.sessions[self.session]: self.sessions[self.session].remove(self) + opts = tornado.options.options + if opts.one_shot or ( + self.application.systemd and + not sum([ + len(wsockets) + for session, wsockets in self.sessions.items()])): + sys.exit(0) + @url(r'/ws/session/(?P[^/]+)') class TermWebSocket(Route, tornado.websocket.WebSocketHandler): @@ -259,14 +276,6 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler): self.log.info('Websocket /ws closed %r' % self) self.sessions[self.session].remove(self) - opts = tornado.options.options - if opts.one_shot or ( - self.application.systemd and - not sum([ - len(wsockets) - for session, wsockets in self.sessions.items()])): - sys.exit(0) - @url(r'/sessions/list.json') class SessionsList(Route): diff --git a/butterfly/static/ext.min.js b/butterfly/static/ext.min.js index ac2d16c..6f6d94d 100644 --- a/butterfly/static/ext.min.js +++ b/butterfly/static/ext.min.js @@ -1,4 +1,4 @@ -/*! butterfly 2016-08-08 */ +/*! butterfly 2016-08-19 */ -(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=[].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},o=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.removeEventListener("message",c)):void 0},butterfly.ws.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 o("granted"===Notification.permission,b)}):o("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;return butterfly.bell("pasted"),b=a.clipboardData.getData("text/plain"),b=b.replace(/\r\n/g,"\n").replace(/\n/g,"\r"),butterfly.send(b),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?"}),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}(),l=new a,n=null,f=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},m=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},k=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||q.call(this.startLine.classList,"line")<0;)this.startLine=this.startLine.parentNode;for(this.endLine=this.end.node,c=[];!this.endLine.classList||q.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=m(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&&!n&&!getSelection().isCollapsed)return butterfly.send(getSelection().toString()),getSelection().removeAllRanges(),f(a);if(n){if(n.reset(),!a.ctrlKey&&a.shiftKey&&37<=(d=a.keyCode)&&40>=d)return!0;if(a.shiftKey&&a.ctrlKey)38===a.keyCode?n.up():40===a.keyCode&&n.down();else if(39===a.keyCode)n.shrinkLeft();else if(38===a.keyCode)n.expandLeft();else if(37===a.keyCode)n.shrinkRight();else{if(40!==a.keyCode)return f(a);n.expandRight()}return null!=n&&n.apply(),f(a)}return!n&&a.ctrlKey&&a.shiftKey&&38===a.keyCode?(n=new b,n.selectLine(butterfly.y-1),n.apply(),f(a)):!0}),document.addEventListener("keyup",function(a){var b,c;if(b=a.keyCode,q.call([16,17,18,19],b)>=0)return!0;if(n){if(13===a.keyCode)return butterfly.send(n.text()),n.destroy(),n=null,f(a);if(c=a.keyCode,q.call([37,38,39,40],c)<0)return n.destroy(),n=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+="
",l.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,m,n;if(i=JSON.parse(this.responseText),a=i.builtin_themes,m=i.themes,b='
\n

Pick a theme:

\n \n \n
",l.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,p=document.createElement("input"),p.type="password",p.style.position="fixed",p.style.top=0,p.style.left=0,p.style.border="none",p.style.outline="none",p.style.opacity=0,p.value="0",document.body.appendChild(p),p.addEventListener("blur",function(){return setTimeout(function(a){return function(){return a.focus()}}(this),10)}),addEventListener("click",function(){return p.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}),p.addEventListener("keydown",function(a){return butterfly.keyDown(a),!0}),p.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=[].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},o=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 o("granted"===Notification.permission,b)}):o("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;return butterfly.bell("pasted"),b=a.clipboardData.getData("text/plain"),b=b.replace(/\r\n/g,"\n").replace(/\n/g,"\r"),butterfly.send(b),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?"}),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}(),l=new a,n=null,f=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},m=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},k=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||q.call(this.startLine.classList,"line")<0;)this.startLine=this.startLine.parentNode;for(this.endLine=this.end.node,c=[];!this.endLine.classList||q.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=m(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&&!n&&!getSelection().isCollapsed)return butterfly.send(getSelection().toString()),getSelection().removeAllRanges(),f(a);if(n){if(n.reset(),!a.ctrlKey&&a.shiftKey&&37<=(d=a.keyCode)&&40>=d)return!0;if(a.shiftKey&&a.ctrlKey)38===a.keyCode?n.up():40===a.keyCode&&n.down();else if(39===a.keyCode)n.shrinkLeft();else if(38===a.keyCode)n.expandLeft();else if(37===a.keyCode)n.shrinkRight();else{if(40!==a.keyCode)return f(a);n.expandRight()}return null!=n&&n.apply(),f(a)}return!n&&a.ctrlKey&&a.shiftKey&&38===a.keyCode?(n=new b,n.selectLine(butterfly.y-1),n.apply(),f(a)):!0}),document.addEventListener("keyup",function(a){var b,c;if(b=a.keyCode,q.call([16,17,18,19],b)>=0)return!0;if(n){if(13===a.keyCode)return butterfly.send(n.text()),n.destroy(),n=null,f(a);if(c=a.keyCode,q.call([37,38,39,40],c)<0)return n.destroy(),n=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+="
",l.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,m,n;if(i=JSON.parse(this.responseText),a=i.builtin_themes,m=i.themes,b='
\n

Pick a theme:

\n \n \n
",l.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,p=document.createElement("input"),p.type="password",p.style.position="fixed",p.style.top=0,p.style.left=0,p.style.border="none",p.style.outline="none",p.style.opacity=0,p.value="0",document.body.appendChild(p),p.addEventListener("blur",function(){return setTimeout(function(a){return function(){return a.focus()}}(this),10)}),addEventListener("click",function(){return p.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}),p.addEventListener("keydown",function(a){return butterfly.keyDown(a),!0}),p.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 c135b69..0c5f703 100644 --- a/butterfly/static/main.js +++ b/butterfly/static/main.js @@ -1,6 +1,5 @@ (function() { - var $, State, Terminal, cancel, cols, cutMessage, openTs, quit, rows, s, uuid, ws, - slice = [].slice, + var $, State, Terminal, cancel, cols, openTs, quit, rows, s, uuid, ws, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; cols = rows = null; @@ -9,11 +8,9 @@ openTs = (new Date()).getTime(); - cutMessage = '\r\nCutting...... 8< ...... 8< ...... ' + '\r\nYou can release when there is no more output.' + '\r\nCutting...... 8< ...... 8< ......' + '\r\nCutting...... 8< ...... 8< ......'; - ws = { shell: null, - termctl: null + ctl: null }; $ = document.querySelectorAll.bind(document); @@ -28,22 +25,8 @@ }; document.addEventListener('DOMContentLoaded', function() { - var close, ctl, error, open, path, rootPath, send, term, wsUrl; + var close, ctl, error, init_ctl_ws, init_shell_ws, open, path, reopenOnClose, rootPath, term, write, write_request, wsUrl; term = null; - send = function(data) { - return ws.shell.send(data); - }; - ctl = function() { - var args, type; - type = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : []; - if (type === 'Resize') { - return ws.termctl.send(JSON.stringify({ - cmd: 'size', - cols: args[0], - rows: args[1] - })); - } - }; if (location.protocol === 'https:') { wsUrl = 'wss://'; } else { @@ -60,104 +43,88 @@ } path += location.search; ws.shell = new WebSocket(wsUrl + '/ws' + path); - ws.termctl = new WebSocket(wsUrl + '/ctl' + path); + ws.ctl = new WebSocket(wsUrl + '/ctl' + path); open = function() { console.log("WebSocket open", arguments); - if (ws.shell.readyState === WebSocket.OPEN && ws.termctl.readyState === WebSocket.OPEN) { - term = new Terminal(document.body, send, ctl); + if (term) { + term.body.classList.remove('stopped'); + term.out = ws.shell.send.bind(ws.shell); + term.out('\x03\n'); + return; + } + if (ws.shell.readyState === WebSocket.OPEN && ws.ctl.readyState === WebSocket.OPEN) { + term = new Terminal(document.body, ws.shell.send.bind(ws.shell), ws.ctl.send.bind(ws.ctl)); term.ws = ws; window.butterfly = term; - ws.termctl.send(JSON.stringify({ + ws.ctl.send(JSON.stringify({ cmd: 'open' })); - ws.termctl.send(JSON.stringify({ + ws.ctl.send(JSON.stringify({ cmd: 'size', cols: term.cols, rows: term.rows })); - return openTs = (new Date()).getTime(); + openTs = (new Date()).getTime(); } + return console.log("WebSocket open end", arguments); }; error = function() { - return console.log("WebSocket error", arguments); + return console.error("WebSocket error", arguments); }; close = function() { console.log("WebSocket closed", arguments); if (quit) { return; } - setTimeout(function() { - term.write('Closed'); - term.skipNextKey = true; - term.body.classList.add('dead'); - if ((new Date()).getTime() - openTs > 60 * 1000) { - return window.open('', '_self').close(); - } - }, 1); - return quit = true; - }; - ws.shell.addEventListener('open', open); - ws.termctl.addEventListener('open', open); - ws.shell.addEventListener('error', error); - ws.termctl.addEventListener('error', error); - ws.shell.addEventListener('close', close); - ws.termctl.addEventListener('close', close); - ws.shell.addEventListener('message', function(e) { - var letter; - if (term.stop == null) { - return term.write(e.data); - } else { - if (term.stop < cutMessage.length) { - letter = cutMessage[term.stop++]; - } else { - letter = '.'; - } - return term.write(letter); + quit = true; + term.write('Closed'); + term.skipNextKey = true; + term.body.classList.add('dead'); + if ((new Date()).getTime() - openTs > 60 * 1000) { + return window.open('', '_self').close(); } - }); - ws.termctl.addEventListener('message', function(e) { + }; + reopenOnClose = function() { + if (quit) { + return; + } + ws.shell = new WebSocket(wsUrl + '/ws' + path); + return init_shell_ws(); + }; + write = function(data) { + if (term) { + return term.write(data); + } + }; + write_request = function(e) { + return setTimeout(write, 1, e.data); + }; + ctl = function() { var cmd; cmd = JSON.parse(e.data); if (cmd.cmd === 'size') { return term.resize(cmd.cols, cmd.rows, true); } - }); - addEventListener('beforeunload', function() { + }; + init_shell_ws = function() { + ws.shell.addEventListener('open', open); + ws.shell.addEventListener('message', write_request); + ws.shell.addEventListener('error', error); + return ws.shell.addEventListener('close', reopenOnClose); + }; + init_ctl_ws = function() { + ws.ctl.addEventListener('open', open); + ws.ctl.addEventListener('message', ctl); + ws.ctl.addEventListener('error', error); + return ws.ctl.addEventListener('close', close); + }; + init_shell_ws(); + init_ctl_ws(); + return addEventListener('beforeunload', function() { if (!quit) { return 'This will exit the terminal session'; } }); - window.bench = function(n) { - var rnd; - if (n == null) { - n = 100000000; - } - rnd = ''; - while (rnd.length < n) { - rnd += Math.random().toString(36).substring(2); - } - console.time('bench'); - console.profile('bench'); - term.write(rnd); - console.profileEnd(); - return console.timeEnd('bench'); - }; - return window.cbench = function(n) { - var rnd; - if (n == null) { - n = 100000000; - } - rnd = ''; - while (rnd.length < n) { - rnd += "\x1b[" + (30 + parseInt(Math.random() * 20)) + "m"; - rnd += Math.random().toString(36).substring(2); - } - console.time('cbench'); - console.profile('cbench'); - term.write(rnd); - console.profileEnd(); - return console.timeEnd('cbench'); - }; }); cancel = function(ev) { @@ -217,7 +184,6 @@ this.focus(); this.startBlink(); addEventListener('keydown', this.keyDown.bind(this)); - addEventListener('keyup', this.keyUp.bind(this)); addEventListener('keypress', this.keyPress.bind(this)); addEventListener('focus', this.focus.bind(this)); addEventListener('blur', this.blur.bind(this)); @@ -559,7 +525,7 @@ }; Terminal.prototype.refresh = function(force) { - var active, attr, ch, classes, cursor, data, fg, group, i, j, k, len, len1, len2, len3, len4, line, lines, m, newOut, o, out, q, ref, ref1, ref2, ref3, ref4, ref5, skipnext, styles, u, x, z; + var active, attr, ch, classes, cursor, data, fg, group, i, j, k, len, len1, len2, len3, len4, line, lines, m, n, newOut, o, out, q, ref, ref1, ref2, ref3, ref4, ref5, skipnext, styles, u, x; if (force == null) { force = false; } @@ -575,7 +541,7 @@ } newOut = ''; ref2 = this.screen; - for (j = o = 0, len2 = ref2.length; o < len2; j = ++o) { + for (j = n = 0, len2 = ref2.length; n < len2; j = ++n) { line = ref2[j]; if (!(line.dirty || force)) { continue; @@ -588,7 +554,7 @@ } attr = this.cloneAttr(this.defAttr); skipnext = false; - for (i = q = 0, ref3 = this.cols - 1; 0 <= ref3 ? q <= ref3 : q >= ref3; i = 0 <= ref3 ? ++q : --q) { + for (i = o = 0, ref3 = this.cols - 1; 0 <= ref3 ? o <= ref3 : o >= ref3; i = 0 <= ref3 ? ++o : --o) { data = line.chars[i]; if (data.html) { out += data.html; @@ -724,13 +690,13 @@ lines = document.querySelectorAll('.line'); if (lines.length > this.scrollback) { ref4 = Array.prototype.slice.call(lines, 0, lines.length - this.scrollback); - for (u = 0, len3 = ref4.length; u < len3; u++) { - line = ref4[u]; + for (q = 0, len3 = ref4.length; q < len3; q++) { + line = ref4[q]; line.remove(); } ref5 = document.querySelectorAll('.group:empty'); - for (z = 0, len4 = ref5.length; z < len4; z++) { - group = ref5[z]; + for (u = 0, len4 = ref5.length; u < len4; u++) { + group = ref5[u]; group.remove(); } lines = document.querySelectorAll('.line'); @@ -1407,29 +1373,15 @@ return this.write(data + "\r\n"); }; - Terminal.prototype.keyUp = function(ev) { - if (ev.keyCode === 19) { - if (this.stop == null) { - return; - } - this.body.classList.remove('stopped'); - this.stop = null; - return this.out('\x03\n'); - } - }; - Terminal.prototype.keyDown = function(ev) { var key, ref; if (ev.keyCode > 15 && ev.keyCode < 19) { return true; } if (ev.keyCode === 19) { - if (this.stop != null) { - return; - } this.body.classList.add('stopped'); - this.stop = 0; this.out('\x03'); + this.ws.shell.close(); return false; } if ((ev.shiftKey || ev.ctrlKey) && ev.keyCode === 45) { @@ -1728,7 +1680,11 @@ return; } if (!notif) { - this.ctl('Resize', this.cols, this.rows); + this.ctl(JSON.stringify({ + cmd: 'size', + cols: this.cols, + rows: this.rows + })); } if (oldCols < this.cols) { i = this.screen.length; diff --git a/butterfly/static/main.min.js b/butterfly/static/main.min.js index 1944b3a..bc2bff1 100644 --- a/butterfly/static/main.min.js +++ b/butterfly/static/main.min.js @@ -1,5 +1,5 @@ -/*! butterfly 2016-08-08 */ +/*! butterfly 2016-08-19 */ -(function(){var a,b,c,d,e,f,g,h,i,j,k=[].slice,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=i=null,h=!1,g=(new Date).getTime(),f="\r\nCutting...... 8< ...... 8< ...... \r\nYou can release when there is no more output.\r\nCutting...... 8< ...... 8< ......\r\nCutting...... 8< ...... 8< ......",a=document.querySelectorAll.bind(document),document.addEventListener("DOMContentLoaded",function(){var a,b,d,j,l,m;return j=null,d=function(a){return l.send("S"+a)},a=function(){var a,b,c;return c=arguments[0],a=2<=arguments.length?k.call(arguments,1):[],b=a.join(","),"Resize"===c?l.send("R"+b):void 0},m="https:"===location.protocol?"wss://":"ws://",b=document.body.getAttribute("data-root-path"),b.length&&(b="/"+b),m+=document.location.host+b+"/ws"+location.pathname,l=new WebSocket(m),l.addEventListener("open",function(){return console.log("WebSocket open",arguments),j=new c(document.body,d,a),j.ws=l,window.butterfly=j,l.send("R"+j.cols+","+j.rows),g=(new Date).getTime()}),l.addEventListener("error",function(){return console.log("WebSocket error",arguments)}),l.addEventListener("message",function(a){var b,c;return"R"===a.data[0]?(c=a.data.slice(1).split(","),e=c[0],i=c[1],void j.resize(e,i,!0)):"S"!==a.data[0]?void console.error("Garbage message"):null==j.stop?j.write(a.data.slice(1)):(b=j.stop6e4?open("","_self").close():void 0},1),h=!0}),addEventListener("beforeunload",function(){return h?void 0:"This will exit the terminal session"}),window.bench=function(a){var b;for(null==a&&(a=1e8),b="";b.lengthc?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.linkify=function(a){var b,c,d,e;return e=/\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim,d=/(^|[^\/])(www\.[\S]+(\b|$))/gim,b=/[\w.]+@[a-zA-Z_-]+?(?:\.[a-zA-Z]{2,6})+/gim,function(){var f,g,h,i;for(h=a.split(" "),i=[],f=0,g=h.length;g>f;f++)c=h[f],i.push(c.replace(e,'$&').replace(d,'$1$2').replace(b,'$&'));return i}().join(" ")},a.prototype.refresh=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I;for(null==a&&(a=!1),y=this.body.querySelectorAll(".cursor"),l=0,m=y.length;m>l;l++)f=y[l],f.parentNode.replaceChild(this.document.createTextNode(f.textContent),f);for(z=this.body.querySelectorAll(".line.active"),t=0,n=z.length;n>t;t++)b=z[t],b.classList.remove("active");for(u="",A=this.screen,k=v=0,o=A.length;o>v;k=++v)if(r=A[k],r.dirty||a){for(w="",I=k!==this.y+this.shift||this.cursorHidden?-(1/0):this.x,c=this.cloneAttr(this.defAttr),E=!1,j=x=0,B=this.cols-1;B>=0?B>=x:x>=B;j=B>=0?++x:--x){if(g=r.chars[j],g.html){w+=g.html;break}if(E)E=!1;else{if(d=g.ch,this.equalAttr(g,c)||(this.equalAttr(c,this.defAttr)||(w+=""),this.equalAttr(g,this.defAttr)||(e=[],F=[],w+="h&&(h+=8),e.push("fg-color-"+h)),"string"==typeof g.fg&&F.push("color: "+g.fg),"number"==typeof g.bg&&e.push("bg-color-"+g.bg),"string"==typeof g.bg&&F.push("background-color: "+g.bg),w+='class="',w+=e.join(" "),w+='"',F.length&&(w+=' style="'+F.join("; ")+'"'),w+=">")),j===I&&(w+=''),d.length>1)w+=d;else switch(d){case"&":w+="&";break;case"<":w+="<";break;case">":w+=">";break;default:" "===d?w+='':" ">=d?w+=" ":!this.forceWidth||"~">=d?w+=d:d>"＀"&&"￯">d?(E=!0,w+=''+d+""):w+=''+d+""}j===I&&(w+=""),c=g}}this.equalAttr(c,this.defAttr)||(w+=""),k===this.y+this.shift||g.html||(w=this.linkify(w)),r.wrap&&(w+="⏎"),this.children[k]?(this.children[k].innerHTML=w,I!==-(1/0)&&this.children[k].classList.add("active")):u+='
'+w+"
",this.screen[k].dirty=!1}if(""!==u){if(i=this.document.createElement("div"),i.className="group",i.innerHTML=u,this.body.appendChild(i),this.screen=this.screen.slice(-this.rows),this.shift=0,s=document.querySelectorAll(".line"),s.length>this.scrollback){for(C=Array.prototype.slice.call(s,0,s.length-this.scrollback),G=0,p=C.length;p>G;G++)r=C[G],r.remove();for(D=document.querySelectorAll(".group:empty"),H=0,q=D.length;q>H;H++)i=D[H],i.remove();s=document.querySelectorAll(".line")}this.children=Array.prototype.slice.call(s,-this.rows)}return 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.screen[this.y+this.shift].dirty=!0,this.nextLine();break;case"\r":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.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.screen[this.y+this.shift].dirty=!0,this.screen[this.y+this.shift].wrap=!1,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.screen[this.y+this.shift].dirty=!0,this.screen[this.y+this.shift].wrap=!1;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.keyUp=function(a){if(19===a.keyCode){if(null==this.stop)return;return this.body.classList.remove("stopped"),this.stop=null,this.out("\n")}},a.prototype.keyDown=function(a){var b,c;if(a.keyCode>15&&a.keyCode<19)return!0;if(19===a.keyCode){if(null!=this.stop)return;return this.body.classList.add("stopped"),this.stop=0,this.out(""),!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("Resize",this.cols,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.screen[this.y+this.shift].dirty=!0,this.screen[this.y+this.shift].wrap=!1},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 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 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.screen[a].dirty=!0,this.screen[a].wrap=!1,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,f,g,h,i,j,k,l,m=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};f=i=null,h=!1,g=(new Date).getTime(),l={shell:null,ctl:null},a=document.querySelectorAll.bind(document),k=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,f,i,j,m,n,o,p,q,r,s;return p=null,s="https:"===location.protocol?"wss://":"ws://",o=document.body.getAttribute("data-root-path"),o.length&&(o="/"+o),s+=document.location.host+o,m=location.pathname,m.indexOf("/session")<0&&(m+="session/"+k()),m+=location.search,l.shell=new WebSocket(s+"/ws"+m),l.ctl=new WebSocket(s+"/ctl"+m),j=function(){return console.log("WebSocket open",arguments),p?(p.body.classList.remove("stopped"),p.out=l.shell.send.bind(l.shell),void p.out("\n")):(l.shell.readyState===WebSocket.OPEN&&l.ctl.readyState===WebSocket.OPEN&&(p=new c(document.body,l.shell.send.bind(l.shell),l.ctl.send.bind(l.ctl)),p.ws=l,window.butterfly=p,l.ctl.send(JSON.stringify({cmd:"open"})),l.ctl.send(JSON.stringify({cmd:"size",cols:p.cols,rows:p.rows})),g=(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),h?void 0:(h=!0,p.write("Closed"),p.skipNextKey=!0,p.body.classList.add("dead"),(new Date).getTime()-g>6e4?window.open("","_self").close():void 0)},n=function(){return h?void 0:(l.shell=new WebSocket(s+"/ws"+m),i())},q=function(a){return p?p.write(a):void 0},r=function(a){return setTimeout(q,1,a.data)},b=function(){var a;return a=JSON.parse(e.data),"size"===a.cmd?p.resize(a.cols,a.rows,!0):void 0},i=function(){return l.shell.addEventListener("open",j),l.shell.addEventListener("message",r),l.shell.addEventListener("error",d),l.shell.addEventListener("close",n)},f=function(){return l.ctl.addEventListener("open",j),l.ctl.addEventListener("message",b),l.ctl.addEventListener("error",d),l.ctl.addEventListener("close",a)},i(),f(),addEventListener("beforeunload",function(){return h?void 0:"This will exit the terminal session"})}),d=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},j=0,b={normal:j++,escaped:j++,csi:j++,osc:j++,charset:j++,dcs:j++,ignore:j++},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))}return 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.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.linkify=function(a){var b,c,d,e;return e=/\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim,d=/(^|[^\/])(www\.[\S]+(\b|$))/gim,b=/[\w.]+@[a-zA-Z_-]+?(?:\.[a-zA-Z]{2,6})+/gim,function(){var f,g,h,i;for(h=a.split(" "),i=[],f=0,g=h.length;g>f;f++)c=h[f],i.push(c.replace(e,'$&').replace(d,'$1$2').replace(b,'$&'));return i}().join(" ")},a.prototype.refresh=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I;for(null==a&&(a=!1),z=this.body.querySelectorAll(".cursor"),l=0,m=z.length;m>l;l++)f=z[l],f.parentNode.replaceChild(this.document.createTextNode(f.textContent),f);for(A=this.body.querySelectorAll(".line.active"),t=0,n=A.length;n>t;t++)b=A[t],b.classList.remove("active");for(v="",B=this.screen,k=u=0,o=B.length;o>u;k=++u)if(r=B[k],r.dirty||a){for(x="",I=k!==this.y+this.shift||this.cursorHidden?-(1/0):this.x,c=this.cloneAttr(this.defAttr),F=!1,j=w=0,C=this.cols-1;C>=0?C>=w:w>=C;j=C>=0?++w:--w){if(g=r.chars[j],g.html){x+=g.html;break}if(F)F=!1;else{if(d=g.ch,this.equalAttr(g,c)||(this.equalAttr(c,this.defAttr)||(x+=""),this.equalAttr(g,this.defAttr)||(e=[],G=[],x+="h&&(h+=8),e.push("fg-color-"+h)),"string"==typeof g.fg&&G.push("color: "+g.fg),"number"==typeof g.bg&&e.push("bg-color-"+g.bg),"string"==typeof g.bg&&G.push("background-color: "+g.bg),x+='class="',x+=e.join(" "),x+='"',G.length&&(x+=' style="'+G.join("; ")+'"'),x+=">")),j===I&&(x+=''),d.length>1)x+=d;else switch(d){case"&":x+="&";break;case"<":x+="<";break;case">":x+=">";break;default:" "===d?x+='':" ">=d?x+=" ":!this.forceWidth||"~">=d?x+=d:d>"＀"&&"￯">d?(F=!0,x+=''+d+""):x+=''+d+""}j===I&&(x+=""),c=g}}this.equalAttr(c,this.defAttr)||(x+=""),k===this.y+this.shift||(null!=g?g.html:0)||(x=this.linkify(x)),r.wrap&&(x+="⏎"),this.children[k]?(this.children[k].innerHTML=x,I!==-(1/0)&&this.children[k].classList.add("active")):v+='
'+x+"
",this.screen[k].dirty=!1}if(""!==v){if(i=this.document.createElement("div"),i.className="group",i.innerHTML=v,this.body.appendChild(i),this.screen=this.screen.slice(-this.rows),this.shift=0,s=document.querySelectorAll(".line"),s.length>this.scrollback){for(D=Array.prototype.slice.call(s,0,s.length-this.scrollback),y=0,p=D.length;p>y;y++)r=D[y],r.remove();for(E=document.querySelectorAll(".group:empty"),H=0,q=E.length;q>H;H++)i=E[H],i.remove();s=document.querySelectorAll(".line")}this.children=Array.prototype.slice.call(s,-this.rows)}return 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.screen[this.y+this.shift].dirty=!0,this.nextLine();break;case"\r":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.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.screen[this.y+this.shift].dirty=!0,this.screen[this.y+this.shift].wrap=!1,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.screen[this.y+this.shift].dirty=!0,this.screen[this.y+this.shift].wrap=!1;break;case"PROMPT":this.send(h);break;case"TEXT":l+=h.length,c=c.slice(0,j+1)+h+c.slice(j+1);break;default:console.error("Unknown type "+x+" for DECUDK")}break;case"$q":switch(r=this.currentParam,y=!1,r){case'"q':r='0"q';break;case'"p':r='61"p';break;case"r":r=""+(this.scrollTop+1)+";"+(this.scrollBottom+1)+"r";break;case"m":r="0m";break;default:console.error("Unknown DCS Pt: %s.",r),r=""}this.send("P"+ +y+"$r"+r+"\\");break;case"+q":r=this.currentParam,y=!1,this.send("P"+ +y+"+r"+r+"\\");break;default:console.error("Unknown DCS prefix: %s.",this.prefix)}this.currentParam=0,this.prefix="",this.state=b.normal}else this.currentParam?this.currentParam+=g:this.prefix||"$"===g||"+"===g?2===this.prefix.length?this.currentParam=g:this.prefix+=g:this.currentParam=g;break;case b.ignore:""!==g&&""!==g||(""===g&&j++,this.state=b.normal)}j++}return this.screen[this.y+this.shift].dirty=!0,this.refresh()},a.prototype.writeln=function(a){return this.write(a+"\r\n")},a.prototype.keyDown=function(a){var b,c;if(a.keyCode>15&&a.keyCode<19)return!0;if(19===a.keyCode)return this.body.classList.add("stopped"),this.out(""),this.ws.shell.close(),!1;if((a.shiftKey||a.ctrlKey)&&45===a.keyCode)return!0;if(a.shiftKey&&a.ctrlKey&&(67===(c=a.keyCode)||86===c))return!0;if(a.altKey&&90===a.keyCode&&!this.skipNextKey)return this.skipNextKey=!0,this.body.classList.add("skip"),d(a);if(this.skipNextKey)return this.skipNextKey=!1,this.body.classList.remove("skip"),!0;switch(a.keyCode){case 8:if(b=a.altKey?"":"",a.shiftKey){b+="\b";break}b+="";break;case 9:if(a.shiftKey){b="";break}b=" ";break;case 13:b="\r";break;case 27:b="";break;case 37:if(this.applicationCursor){b="OD";break}b="";break;case 39:if(this.applicationCursor){b="OC";break}b="";break;case 38:if(this.applicationCursor){b="OA";break}if(a.ctrlKey)return this.scrollDisplay(-1),d(a);b="";break;case 40:if(this.applicationCursor){b="OB";break}if(a.ctrlKey)return this.scrollDisplay(1),d(a);b="";break;case 46:b="[3~";break;case 45:b="[2~";break;case 36:if(this.applicationKeypad){b="OH";break}b="";break;case 35:if(this.applicationKeypad){b="OF";break}b="";break;case 33:if(a.shiftKey){if(a.ctrlKey)break;return this.scrollDisplay(-(this.rows-1)),d(a)}b="[5~";break;case 34:if(a.shiftKey){if(a.ctrlKey)break;return this.scrollDisplay(this.rows-1),d(a)}b="[6~";break;case 112:b="OP";break;case 113:b="OQ";break;case 114:b="OR";break;case 115:b="OS";break;case 116:b="[15~";break;case 117:b="[17~";break;case 118:b="[18~";break;case 119:b="[19~";break;case 120:b="[20~";break;case 121:b="[21~";break;case 122:b="[23~";break;case 123:b="[24~";break;case 145:return this.scrollLock=!this.scrollLock,this.scrollLock?this.body.classList.add("locked"):this.body.classList.remove("locked"),d(a);default:a.ctrlKey?a.keyCode>=65&&a.keyCode<=90?b=String.fromCharCode(a.keyCode-64):32===a.keyCode?b=String.fromCharCode(0):a.keyCode>=51&&a.keyCode<=55?b=String.fromCharCode(a.keyCode-51+27):56===a.keyCode?b=String.fromCharCode(127):219===a.keyCode?b=String.fromCharCode(27):221===a.keyCode&&(b=String.fromCharCode(29)):(a.altKey&&m.call(navigator.platform,"Mac")<0||a.metaKey&&m.call(navigator.platform,"Mac")>=0)&&(a.keyCode>=65&&a.keyCode<=90?b=""+String.fromCharCode(a.keyCode+32):192===a.keyCode?b="`":a.keyCode>=48&&a.keyCode<=57&&(b=""+(a.keyCode-48)))}return a.keyCode>=37&&a.keyCode<=40&&(a.ctrlKey?b=b.slice(0,-1)+"1;5"+b.slice(-1):a.altKey?b=b.slice(0,-1)+"1;3"+b.slice(-1):a.shiftKey&&(b=b.slice(0,-1)+"1;4"+b.slice(-1))),b?(this.showCursor(),this.send(b),d(a)):!0},a.prototype.setgLevel=function(a){return this.glevel=a,this.charset=this.charsets[a]},a.prototype.setgCharset=function(a,b){return this.charsets[a]=b,this.glevel===a?this.charset=b:void 0},a.prototype.keyPress=function(a){var b,c;if(this.skipNextKey===!1)return this.skipNextKey=null,!0;if(a.keyCode>15&&a.keyCode<19)return!0;if((a.shiftKey||a.ctrlKey)&&45===a.keyCode)return!0;if(a.shiftKey&&a.ctrlKey&&(67===(c=a.keyCode)||86===c))return!0;if(d(a),a.charCode)b=a.charCode;else if(null==a.which)b=a.keyCode;else{if(0===a.which||0===a.charCode)return!1;b=a.which}return!b||a.ctrlKey||a.altKey||a.metaKey?!1:(b=String.fromCharCode(b),this.showCursor(),this.send(b),!1)},a.prototype.bell=function(a){return null==a&&(a="bell"),this.visualBell?(this.body.classList.add(a),this.t_bell=setTimeout(function(b){return function(){return b.body.classList.remove(a)}}(this),this.visualBell)):void 0},a.prototype.resize=function(a,b,c){var d,e,f,g,h,i,j,k,l;if(null==a&&(a=null),null==b&&(b=null),null==c&&(c=!1),i=this.cols,j=this.rows,this.computeCharSize(),l=this.body.clientWidth,e=this.html.clientHeight-(this.html.offsetHeight-this.html.scrollHeight),this.cols=a||Math.floor(l/this.charSize.width),this.rows=b||Math.floor(e/this.charSize.height),k=e%this.charSize.height,this.body.style["padding-bottom"]=k+"px",this.cols=Math.max(1,this.cols),this.rows=Math.max(1,this.rows),this.nativeScrollTo(),a||b||i!==this.cols||j!==this.rows){if(c||this.ctl(JSON.stringify({cmd:"size",cols:this.cols,rows:this.rows})),ithis.cols)for(f=this.screen.length;f--;)for(;this.screen[f].chars.length>this.cols;)this.screen[f].chars.pop();if(this.setupStops(i),g=j,gthis.rows)for(;g-- >this.rows;)this.screen.length>this.rows&&this.screen.pop(),this.children.length>this.rows&&(d=this.children.pop(),null!=d&&d.parentNode.removeChild(d));if(this.normal){if(ithis.cols)for(f=this.normal.screen.length;f--;)for(;this.normal.screen[f].chars.length>this.cols;)this.normal.screen[f].chars.pop();if(g=j,gthis.rows)for(;g-- >this.rows;)this.normal.screen.length>this.rows&&this.normal.screen.pop()}return this.y>=this.rows&&(this.y=this.rows-1),this.x>=this.cols&&(this.x=this.cols-1),this.scrollTop=0,this.scrollBottom=this.rows-1,this.refresh(!0),c||!a&&!b?void 0:this.reset()}},a.prototype.resizeWindowPlease=function(a){var b,c;return b=window.innerWidth-this.body.clientWidth,c=a*this.charSize.width+b,resizeTo(c,window.innerHeight)},a.prototype.setupStops=function(a){var b;for(null!=a?this.tabs[a]||(a=this.prevStop(a)):(this.tabs={},a=0),b=[];a0;);return a>=this.cols?this.cols-1:0>a?0:a},a.prototype.nextStop=function(a){for(null==a&&(a=this.x);!this.tabs[++a]&&a=this.cols?this.cols-1:0>a?0:a},a.prototype.eraseRight=function(a,b){var c;for(c=this.screen[b+this.shift].chars;athis.rows){for(h=Array.prototype.slice.call(f,0,f.length-this.rows),b=0,c=h.length;c>b;b++)e=h[b],e.remove();for(i=document.querySelectorAll(".group:empty"),g=0,d=i.length;d>g;g++)a=i[g],a.remove();f=document.querySelectorAll(".line")}return this.children=Array.prototype.slice.call(f,-this.rows)},a.prototype.tabSet=function(){return this.tabs[this.x]=!0,this.state=b.normal},a.prototype.cursorUp=function(a){var b;return b=a[0],1>b&&(b=1),this.y-=b,this.y<0?this.y=0:void 0},a.prototype.cursorDown=function(a){var b;return b=a[0],1>b&&(b=1),this.y+=b,this.y>=this.rows?this.y=this.rows-1:void 0},a.prototype.cursorForward=function(a){var b;return b=a[0],1>b&&(b=1),this.x+=b,this.x>=this.cols?this.x=this.cols-1:void 0},a.prototype.cursorBackward=function(a){var b;return b=a[0],1>b&&(b=1),this.x-=b,this.x<0?this.x=0:void 0},a.prototype.cursorPos=function(a){var b,c;return c=a[0]-1,b=a.length>=2?a[1]-1:0,0>c?c=0:c>=this.rows&&(c=this.rows-1),0>b?b=0:b>=this.cols&&(b=this.cols-1),this.x=b,this.y=c+(this.originMode?this.scrollTop:0)},a.prototype.eraseInDisplay=function(a){var b,c,d,e;switch(a[0]){case 0:for(this.eraseRight(this.x,this.y),b=this.y+1,c=[];bb;)d=a[b],d>=30&&37>=d?this.curAttr.fg=d-30:d>=40&&47>=d?this.curAttr.bg=d-40:d>=90&&97>=d?(d+=8,this.curAttr.fg=d-90):d>=100&&107>=d?(d+=8,this.curAttr.bg=d-100):0===d?this.curAttr=this.cloneAttr(this.defAttr):1===d?this.curAttr.bold=!0:2===d?this.curAttr.faint=!0:3===d?this.curAttr.italic=!0:4===d?this.curAttr.underline=!0:5===d?this.curAttr.blink=1:6===d?this.curAttr.blink=2:7===d?this.curAttr.inverse=!0:8===d?this.curAttr.invisible=!0:9===d?this.curAttr.crossed=!0:10===d||(21===d?this.curAttr.bold=!1:22===d?(this.curAttr.bold=!1,this.curAttr.faint=!1):23===d?this.curAttr.italic=!1:24===d?this.curAttr.underline=!1:25===d?this.curAttr.blink=!1:27===d?this.curAttr.inverse=!1:28===d?this.curAttr.invisible=!1:29===d?this.curAttr.crossed=!1:39===d?this.curAttr.fg=257:49===d?this.curAttr.bg=256:38===d?2===a[b+1]?(b+=2,this.curAttr.fg="rgb("+a[b]+", "+a[b+1]+", "+a[b+2]+")",b+=2):5===a[b+1]&&(b+=2,this.curAttr.fg=255&a[b]):48===d?2===a[b+1]?(b+=2,this.curAttr.bg="rgb("+a[b]+", "+a[b+1]+", "+a[b+2]+")",b+=2):5===a[b+1]&&(b+=2,this.curAttr.bg=255&a[b]):100===d?(this.curAttr.fg=257,this.curAttr.bg=256):console.error("Unknown SGR attribute: %d.",d)),e.push(b++);return e},a.prototype.deviceStatus=function(a){var b,c;if(this.prefix){if("?"===this.prefix&&(6===a[0]&&this.send("[?"+(this.y+1)+";"+(this.x+1)+"R"),99===a[0]))return null==(null!=(b=navigator.geolocation)?b.getCurrentPosition:void 0)?void this.send("[?R"):null!=(c=navigator.geolocation)?c.getCurrentPosition(function(a){return function(b){return a.send("[?"+b.coords.latitude+";"+b.coords.longitude+"R")}}(this),function(a){return function(b){return a.send("[?R")}}(this)):void 0}else switch(a[0]){case 5:return this.send("");case 6: +return this.send("["+(this.y+1)+";"+(this.x+1)+"R")}},a.prototype.insertChars=function(a){var b,c,d;for(c=a[0],1>c&&(c=1),d=this.y,b=this.x;c--&&bb&&(b=1),this.y+=b,this.y>=this.rows&&(this.y=this.rows-1),this.x=0},a.prototype.cursorPrecedingLine=function(a){var b;return b=a[0],1>b&&(b=1),this.y-=b,this.y<0&&(this.y=0),this.x=0},a.prototype.cursorCharAbsolute=function(a){var b;return b=a[0],1>b&&(b=1),this.x=b-1},a.prototype.insertLines=function(a){var b,c,d,e,f,g;for(d=a[0],1>d&&(d=1);d--;)this.screen.splice(this.y+this.shift,0,this.blankLine(!0)),this.screen.splice(this.scrollBottom+1+this.shift,1);for(g=[],b=c=e=this.y+this.shift,f=this.screen.length-1;f>=e?f>=c:c>=f;b=f>=e?++c:--c)g.push(this.screen[b].dirty=!0);return g},a.prototype.deleteLines=function(a){var b,c,d,e,f,g;for(d=a[0],1>d&&(d=1);d--;)this.screen.splice(this.scrollBottom+this.shift,0,this.blankLine(!0)),this.screen.splice(this.y+this.shift,1),this.normal||0!==this.scrollTop||this.scrollBottom!==this.rows-1||(this.children[this.y+this.shift].remove(),this.children.splice(this.y+this.shift,1));if(this.normal||0!==this.scrollTop||this.scrollBottom!==this.rows-1){for(g=[],b=c=e=this.y+this.shift,f=this.screen.length-1;f>=e?f>=c:c>=f;b=f>=e?++c:--c)g.push(this.screen[b].dirty=!0);return g}},a.prototype.deleteChars=function(a){var b;for(b=a[0],1>b&&(b=1);b--;)this.screen[this.y+this.shift].chars.splice(this.x,1),this.screen[this.y+this.shift].chars.push(this.eraseAttr());return this.screen[this.y+this.shift].dirty=!0,this.screen[this.y+this.shift].wrap=!1},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 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 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.screen[a].dirty=!0,this.screen[a].wrap=!1,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/terminal.py b/butterfly/terminal.py index a814b66..6b0188b 100644 --- a/butterfly/terminal.py +++ b/butterfly/terminal.py @@ -73,7 +73,7 @@ class Terminal(object): if tornado.options.options.unsecure: if self.user: try: - self.callee = utils.User(name=self.user) + self.callee = self.user except LookupError: log.debug( "Can't switch to user %s" % self.user, exc_info=True) @@ -198,7 +198,7 @@ class Terminal(object): self.socket.local and self.caller == self.callee and server == self.callee - ) or not tornado.options.options.login: + ) and not tornado.options.options.login: # User has been auth with ssl or is the same user as server # or login is explicitly turned off if ( diff --git a/coffees/main.coffee b/coffees/main.coffee index d020efe..db44383 100644 --- a/coffees/main.coffee +++ b/coffees/main.coffee @@ -10,7 +10,7 @@ # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU General Public License for more details.s # # You should have received a copy of the GNU General Public License # along with this program. If not, see . @@ -18,13 +18,10 @@ cols = rows = null quit = false openTs = (new Date()).getTime() -cutMessage = '\r\nCutting...... 8< ...... 8< ...... ' + - '\r\nYou can release when there is no more output.' + - '\r\nCutting...... 8< ...... 8< ......' + - '\r\nCutting...... 8< ...... 8< ......' + ws = shell: null - termctl: null + ctl: null $ = document.querySelectorAll.bind(document) @@ -36,13 +33,6 @@ uuid = -> document.addEventListener 'DOMContentLoaded', -> term = null - send = (data) -> - ws.shell.send data - - ctl = (type, args...) -> - if type == 'Resize' - ws.termctl.send JSON.stringify( - cmd: 'size', cols: args[0], rows: args[1]) if location.protocol == 'https:' wsUrl = 'wss://' @@ -61,87 +51,78 @@ document.addEventListener 'DOMContentLoaded', -> path += location.search ws.shell = new WebSocket wsUrl + '/ws' + path - ws.termctl = new WebSocket wsUrl + '/ctl' + path + ws.ctl = new WebSocket wsUrl + '/ctl' + path open = -> console.log "WebSocket open", arguments - if (ws.shell.readyState is WebSocket.OPEN and - ws.termctl.readyState is WebSocket.OPEN) - term = new Terminal document.body, send, ctl + if term + term.body.classList.remove 'stopped' + term.out = ws.shell.send.bind(ws.shell) + term.out '\x03\n' + return + + if (ws.shell.readyState is WebSocket.OPEN and + ws.ctl.readyState is WebSocket.OPEN) + + term = new Terminal( + document.body, ws.shell.send.bind(ws.shell), ws.ctl.send.bind(ws.ctl)) term.ws = ws window.butterfly = term - ws.termctl.send JSON.stringify(cmd: 'open') - ws.termctl.send JSON.stringify( + ws.ctl.send JSON.stringify(cmd: 'open') + ws.ctl.send JSON.stringify( cmd: 'size', cols: term.cols, rows: term.rows) openTs = (new Date()).getTime() + console.log "WebSocket open end", arguments error = -> - console.log "WebSocket error", arguments + console.error "WebSocket error", arguments close = -> console.log "WebSocket closed", arguments return if quit - - setTimeout -> - term.write 'Closed' - # Allow quick reload - term.skipNextKey = true - term.body.classList.add('dead') - # Don't autoclose if websocket didn't last 1 minute - if (new Date()).getTime() - openTs > 60 * 1000 - window.open('','_self').close() - , 1 quit = true - ws.shell.addEventListener 'open', open - ws.termctl.addEventListener 'open', open + term.write 'Closed' + # Allow quick reload + term.skipNextKey = true + term.body.classList.add('dead') + # Don't autoclose if websocket didn't last 1 minute + if (new Date()).getTime() - openTs > 60 * 1000 + window.open('','_self').close() - ws.shell.addEventListener 'error', error - ws.termctl.addEventListener 'error', error + reopenOnClose = -> + return if quit + ws.shell = new WebSocket wsUrl + '/ws' + path + init_shell_ws() - ws.shell.addEventListener 'close', close - ws.termctl.addEventListener 'close', close + write = (data) -> + if term + term.write data - ws.shell.addEventListener 'message', (e) -> - unless term.stop? - term.write e.data - else - if term.stop < cutMessage.length - letter = cutMessage[term.stop++] - else - letter = '.' - term.write letter + write_request = (e) -> + setTimeout write, 1, e.data - ws.termctl.addEventListener 'message', (e) -> + ctl = -> cmd = JSON.parse(e.data) if cmd.cmd is 'size' term.resize cmd.cols, cmd.rows, true + init_shell_ws = -> + ws.shell.addEventListener 'open', open + ws.shell.addEventListener 'message', write_request + ws.shell.addEventListener 'error', error + ws.shell.addEventListener 'close', reopenOnClose + + init_ctl_ws = -> + ws.ctl.addEventListener 'open', open + ws.ctl.addEventListener 'message', ctl + ws.ctl.addEventListener 'error', error + ws.ctl.addEventListener 'close', close + + init_shell_ws() + init_ctl_ws() + addEventListener 'beforeunload', -> if not quit 'This will exit the terminal session' - - window.bench = (n=100000000) -> - rnd = '' - while rnd.length < n - rnd += Math.random().toString(36).substring(2) - - console.time('bench') - console.profile('bench') - term.write rnd - console.profileEnd() - console.timeEnd('bench') - - - window.cbench = (n=100000000) -> - rnd = '' - while rnd.length < n - rnd += "\x1b[#{30 + parseInt(Math.random() * 20)}m" - rnd += Math.random().toString(36).substring(2) - - console.time('cbench') - console.profile('cbench') - term.write rnd - console.profileEnd() - console.timeEnd('cbench') diff --git a/coffees/term.coffee b/coffees/term.coffee index fd64c04..38d7f3c 100644 --- a/coffees/term.coffee +++ b/coffees/term.coffee @@ -87,7 +87,6 @@ class Terminal @startBlink() addEventListener 'keydown', @keyDown.bind(@) - addEventListener 'keyup', @keyUp.bind(@) addEventListener 'keypress', @keyPress.bind(@) addEventListener 'focus', @focus.bind(@) addEventListener 'blur', @blur.bind(@) @@ -1258,13 +1257,6 @@ class Terminal writeln: (data) -> @write "#{data}\r\n" - keyUp: (ev) -> - if ev.keyCode is 19 # Pause break - return unless @stop? - @body.classList.remove 'stopped' - @stop = null - @out '\x03\n' - keyDown: (ev) -> # Key Resources: # https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent @@ -1272,10 +1264,9 @@ class Terminal return true if ev.keyCode > 15 and ev.keyCode < 19 if ev.keyCode is 19 # Pause break - return if @stop? @body.classList.add 'stopped' - @stop = 0 @out '\x03' + @ws.shell.close() return false # Handle shift insert and ctrl insert @@ -1574,7 +1565,8 @@ class Terminal if (not x and not y) and oldCols == @cols and oldRows == @rows return - @ctl 'Resize', @cols, @rows unless notif + @ctl(JSON.stringify( + cmd: 'size', cols: @cols, rows: @rows)) unless notif # resize cols if oldCols < @cols