(function(){var a,c={}.hasOwnProperty,d=function(h,f){for(var e in f){if(c.call(f,e)){h[e]=f[e]}}function g(){this.constructor=h}g.prototype=f.prototype;h.prototype=new g();h.__super__=f.prototype;return h},b=function(e,f){return function(){return e.apply(f,arguments)}};window.Controls.terminal__thumbnail=(function(e){d(f,e);function f(){return f.__super__.constructor.apply(this,arguments)}f.prototype.createDom=function(){var g=this;this.dom=$('<div class="control terminal-thumbnail">\n    <img src="/ajenti:terminal/'+this.properties.tid+'/thumbnail" />\n    <a class="close">&#x2715;</a>\n</div>');this.dom.click(function(){return Tabs.addTab("/ajenti:terminal/"+g.properties.tid,"Terminal "+g.properties.tid)});return this.dom.find("a").click(function(h){g.event("close");return h.stopPropagation()})};return f})(window.Control);a={black:"#073642",green:"#859900",white:"#eee8d5",yellow:"#b58900",red:"#dc322f",magenta:"#d33682",violet:"#6c71c4",blue:"#268bd2",cyan:"#2aa198"};window.Terminal=(function(){function e(){this.send=b(this.send,this);this.select=b(this.select,this);var f=this;this.id=document.location.href.split("/")[4];this.term=$("#term");this.socket=ajentiConnectSocket("/terminal");$(document).keypress(function(h){var g;g=f.filter_key(h,$.browser.mozilla);if(h.which!==13){f.send(RawDeflate.Base64.encode(g))}return h.preventDefault()});$(document).keyup(function(h){var g;g=f.filter_key(h);f.send(RawDeflate.Base64.encode(g));return h.preventDefault()});this.socket.on("set",function(g){Loading.hide();return f.draw(g)});this.socket.on("re-select",function(g){return f.select()})}e.prototype.select=function(){return this.socket.send(JSON.stringify({type:"select",tid:this.id}))};e.prototype.send=function(f){return this.socket.send(JSON.stringify({type:"key",key:f,tid:this.id}))};e.prototype.draw=function(i){var h,g,f,j=this;i=RawDeflate.inflate(RawDeflate.Base64.decode(i));i=JSON.parse(i);$("#term pre.cursor").removeClass("cursor");this.cursor=i.cursor;if(i.cursor){this.cursx=i.cx;this.cursy=i.cy}else{this.cursx=-1}g=$("#term div");f=[];for(h in i.lines){f.push((function(l){var m;if(g.length<=l){return $("#term").append(j.row(i.lines[l],l))}else{m=$(g[l]);return m.html(j.cells(i.lines[l],l))}})(h))}return f};e.prototype.row=function(g,f){return"<div>"+this.cells(g,f)+"</div>"};e.prototype.cells=function(m,t){var y,j,v,g,p,w,s,x,k,l,n,u,q,f,h,o;u="<pre>";s=0;j=0;v=0;l=0;f=0;for(x=h=0,o=m.length;0<=o?h<o:h>o;x=0<=o?++h:--h){g=m[x];k=parseInt(t);if(true||j!==g[2]||s!==g[1]||(k===this.cursy&&x===this.cursx)||(k===this.cursy&&x===this.cursx+1)){n="";q="";if(k===this.cursy&&x===this.cursx){n=' class="cursor" '}if(g[3]||g[4]||g[5]){if(g[4]){q+="font-style: italic;"}if(g[5]){q+="text-decoration: underline;"}}w=g[1];if(w==="default"){w="white"}w=a[w];if(w==null){w=g[1]}y=g[2];if(y==="default"){y="black"}y=a[y];if(y==null){y=g[2]}u+="</pre><pre"+n+' style="color:'+w+";background:"+y+";"+q+'">';s=g[1];j=g[2];v=g[3];l=g[4];f=g[5]}p=g[0];if(p==="<"){p="&lt"}if(p===">"){p="&gt"}u+=g[0]}u+="</pre>";return u};e.prototype.filter_key=function(h,f){var g;g=h.charCode;if(h.ctrlKey){g=String.fromCharCode(h.keyCode-64);return g}if(!g&&h.keyCode>=112&&h.keyCode<=123){g="\x1b"+(h.keyCode-111);return g}if(g){if(h.ctrlKey){g=String.fromCharCode(g-96)}else{g=String.fromCharCode(g);if(g==="\r"){g="\n"}}}else{switch(h.keyCode){case 8:g="\b";break;case 9:if(!f){g="\t"}break;case 13:case 10:g="\r";break;case 38:if(!f){g="\x1b[A"}break;case 40:if(!f){g="\x1b[B"}break;case 39:if(!f){g="\x1b[C"}break;case 37:if(!f){g="\x1b[D"}break;case 46:g="\x1b[3~";break;case 35:g="\x1b[F";break;case 36:g="\x1b[H";break;case 34:g="\x1b[6~";break;case 33:g="\x1b[5~";break;case 27:g="\x1b";break;default:return""}}h.preventDefault();return g};return e})()}).call(this);