diff --git a/butterfly/static/main.js b/butterfly/static/main.js index 556c405..2d5a397 100644 --- a/butterfly/static/main.js +++ b/butterfly/static/main.js @@ -180,7 +180,11 @@ addEventListener('keypress', this.keyPress.bind(this)); addEventListener('focus', this.focus.bind(this)); addEventListener('blur', this.blur.bind(this)); - addEventListener('resize', this.resize.bind(this)); + addEventListener('resize', (function(_this) { + return function() { + return _this.resize(); + }; + })(this)); if (typeof InstallTrigger !== "undefined") { this.body.contentEditable = 'true'; } @@ -663,8 +667,8 @@ Terminal.prototype.scroll = function() { var i, k, ref, ref1, results; if (this.normal || this.scrollTop !== 0 || this.scrollBottom !== this.rows - 1) { - this.screen.splice(this.scrollBottom + 1, 0, [this.blank_line(), true]); - this.screen.splice(this.scrollTop, 1); + this.screen.splice(this.shift + this.scrollBottom + 1, 0, [this.blank_line(), true]); + this.screen.splice(this.shift + this.scrollTop, 1); results = []; for (i = k = ref = this.scrollTop, ref1 = this.scrollBottom; ref <= ref1 ? k <= ref1 : k >= ref1; i = ref <= ref1 ? ++k : --k) { results.push(this.screen[i + this.shift][1] = true); @@ -676,6 +680,17 @@ } }; + Terminal.prototype.unscroll = function() { + var i, k, ref, ref1, results; + this.screen.splice(this.shift + this.scrollTop, 0, [this.blank_line(true), true]); + this.screen.splice(this.shift + this.scrollBottom + 1, 1); + results = []; + for (i = k = ref = this.scrollTop, ref1 = this.scrollBottom; ref <= ref1 ? k <= ref1 : k >= ref1; i = ref <= ref1 ? ++k : --k) { + results.push(this.screen[i + this.shift][1] = true); + } + return results; + }; + Terminal.prototype.native_scroll_to = function(scroll) { if (scroll == null) { scroll = 2000000000; @@ -695,8 +710,16 @@ } }; + Terminal.prototype.prev_line = function() { + this.y--; + if (this.y < this.scrollTop) { + this.y++; + return this.unscroll(); + } + }; + Terminal.prototype.write = function(data) { - var attr, ch, content, cs, i, l, pt, ref, ref1, type, valid; + var attr, c, ch, content, cs, i, k, l, len, line, m, num, pt, ref, ref1, ref2, ref3, type, valid; i = 0; l = data.length; while (i < l) { @@ -710,9 +733,6 @@ case "\n": case "\x0b": case "\x0c": - if (this.convertEol) { - this.x = 0; - } this.next_line(); break; case "\r": @@ -858,6 +878,27 @@ case "#": this.state = State.normal; i++; + num = data.charAt(i); + switch (num) { + case "3": + break; + case "4": + break; + case "5": + break; + case "6": + break; + case "8": + ref1 = this.screen; + for (k = 0, len = ref1.length; k < len; k++) { + line = ref1[k]; + line[1] = true; + for (c = m = 0, ref2 = line[0].length; 0 <= ref2 ? m <= ref2 : m >= ref2; c = 0 <= ref2 ? ++m : --m) { + line[0][c] = this.cloneAttr(this.curAttr, "E"); + } + } + this.x = this.y = 0; + } break; case "H": this.tabSet(); @@ -1111,7 +1152,7 @@ break; } pt = pt.slice(1); - ref1 = pt.split('|', 2), type = ref1[0], content = ref1[1]; + ref3 = pt.split('|', 2), type = ref3[0], content = ref3[1]; if (!content) { console.error("No type for inline DECUDK: " + pt); break; @@ -1124,14 +1165,14 @@ } attr = this.cloneAttr(this.curAttr); attr.html = "
" + content + "
"; - this.screen[this.y][0][this.x] = attr; - this.screen[this.y][1] = true; + this.screen[this.y + this.shift][0][this.x] = attr; + this.screen[this.y + this.shift][1] = true; break; case "IMAGE": attr = this.cloneAttr(this.curAttr); attr.html = ""; - this.screen[this.y][0][this.x] = attr; - this.screen[this.y][1] = true; + this.screen[this.y + this.shift][0][this.x] = attr; + this.screen[this.y + this.shift][1] = true; break; case "PROMPT": this.send(content); @@ -1199,7 +1240,7 @@ } i++; } - this.screen[this.y][1] = true; + this.screen[this.y + this.shift][1] = true; return this.refresh(); }; @@ -1483,16 +1524,22 @@ })(this)), this.visualBell); }; - Terminal.prototype.resize = function() { + Terminal.prototype.resize = function(x, y) { var el, i, j, line, old_cols, old_rows, px; + if (x == null) { + x = null; + } + if (y == null) { + y = null; + } old_cols = this.cols; old_rows = this.rows; this.compute_char_size(); - this.cols = Math.floor(this.element.clientWidth / this.char_size.width); - this.rows = Math.floor(window.innerHeight / this.char_size.height); + this.cols = x || Math.floor(this.element.clientWidth / this.char_size.width); + this.rows = y || Math.floor(window.innerHeight / this.char_size.height); px = window.innerHeight % this.char_size.height; this.element.style['padding-bottom'] = px + "px"; - if (old_cols === this.cols && old_rows === this.rows) { + if ((!x && !y) && old_cols === this.cols && old_rows === this.rows) { return; } this.ctl('Resize', this.cols, this.rows); @@ -1548,7 +1595,10 @@ this.scrollTop = 0; this.scrollBottom = this.rows - 1; this.refresh(true); - return this.normal = null; + this.normal = null; + if (x || y) { + return this.reset(); + } }; Terminal.prototype.setupStops = function(i) { @@ -1665,12 +1715,7 @@ }; Terminal.prototype.reverseIndex = function() { - var i, k, ref, ref1; - this.screen.splice(this.scrollBottom, 1); - this.screen.splice(this.scrollTop, 0, [this.blank_line(true), true]); - for (i = k = ref = this.scrollTop, ref1 = this.scrollBottom; ref <= ref1 ? k <= ref1 : k >= ref1; i = ref <= ref1 ? ++k : --k) { - this.screen[i + this.shift][1] = true; - } + this.prev_line(); return this.state = State.normal; }; @@ -2113,6 +2158,16 @@ } return; } + if (!this.prefix) { + switch (params) { + case 4: + this.insertMode = true; + break; + case 20: + this.convertEol = true; + } + return; + } if (this.prefix === "?") { switch (params) { case 1: @@ -2182,6 +2237,16 @@ } return; } + if (!this.prefix) { + switch (params) { + case 4: + this.insertMode = false; + break; + case 20: + this.convertEol = false; + } + return; + } if (this.prefix === "?") { switch (params) { case 1: @@ -2377,8 +2442,8 @@ attr = params[4]; results = []; while (t < b + 1) { - line = this.screen[t][0]; - this.screen[t][1] = true; + line = this.screen[t + this.shift][0]; + this.screen[t + this.shift][1] = true; i = l; while (i < r) { line[i] = this.cloneAttr(attr, line[i].ch); @@ -2418,8 +2483,8 @@ r = params[4]; results = []; while (t < b + 1) { - line = this.screen[t][0]; - this.screen[t][1] = true; + line = this.screen[t + this.shift][0]; + this.screen[t + this.shift][1] = true; i = l; while (i < r) { line[i] = this.cloneAttr(line[i][0], String.fromCharCode(ch)); @@ -2443,8 +2508,8 @@ r = params[3]; results = []; while (t < b + 1) { - line = this.screen[t][0]; - this.screen[t][1] = true; + line = this.screen[t + this.shift][0]; + this.screen[t + this.shift][1] = true; i = l; while (i < r) { line[i] = this.eraseAttr(); @@ -2464,9 +2529,9 @@ Terminal.prototype.insertColumns = function() { var i, l, param; param = params[0]; - l = this.rows; + l = this.rows + this.shift; while (param--) { - i = 0; + i = this.shift; while (i < l) { this.screen[i][0].splice(this.x + 1, 0, this.eraseAttr()); this.screen[i][0].pop(); @@ -2479,9 +2544,9 @@ Terminal.prototype.deleteColumns = function() { var i, l, param; param = params[0]; - l = this.rows; + l = this.rows + this.shift; while (param--) { - i = 0; + i = this.shift; while (i < l) { this.screen[i][0].splice(this.x, 1); this.screen[i][0].push(this.eraseAttr()); diff --git a/butterfly/static/main.min.js b/butterfly/static/main.min.js index 90aefde..3f86c17 100644 --- a/butterfly/static/main.min.js +++ b/butterfly/static/main.min.js @@ -1,5 +1,6 @@ /*! butterfly 2015-04-21 */ -(function(){var a,b,c,d,e,f,g,h,i,j=[].slice,k=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};e=h=null,g=!1,f=(new Date).getTime(),a=document.querySelectorAll.bind(document),document.addEventListener("DOMContentLoaded",function(){var a,b,d,e,h,i,k,l,m;return e=function(a){return l.send("S"+a)},a=function(){var a,b,c;return c=arguments[0],a=2<=arguments.length?j.call(arguments,1):[],b=a.join(","),"Resize"===c?l.send("R"+b):void 0},m="https:"===location.protocol?"wss://":"ws://",m+=document.location.host+"/ws"+location.pathname,l=new WebSocket(m),l.addEventListener("open",function(){return console.log("WebSocket open",arguments),l.send("R"+i.cols+","+i.rows),f=(new Date).getTime()}),l.addEventListener("error",function(){return console.log("WebSocket error",arguments)}),b="",h=null,d="",l.addEventListener("message",function(a){return h&&clearTimeout(h),d+=a.data,i.stop&&(d=d.slice(-10240)),d.length>i.buff_size?k():h=setTimeout(k,1)}),k=function(){return i.write(d),i.stop&&(i.stop=!1,i.element.classList.remove("stopped")),d=""},l.addEventListener("close",function(){return console.log("WebSocket closed",arguments),setTimeout(function(){return i.write("Closed"),i.skipNextKey=!0,i.element.classList.add("dead")},1),g=!0,(new Date).getTime()-f>6e4?open("","_self").close():void 0}),i=new c(document.body,e,a),addEventListener("beforeunload",function(){return g?void 0:"This will exit the terminal session"}),i.ws=l,window.butterfly=i,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){var e;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,void b.send("[<"+(3===(3&c)?-4&c:c)+";"+d.x+";"+d.y+(3===(3&c)?"m":"M"))):(e=[],a(e,c),a(e,d.x),a(e,d.y),b.send(""+String.fromCharCode.apply(String,e)))}}(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.element.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),a.normalMouse&&addEventListener("mousemove",c),a.x10Mouse||addEventListener("mouseup",e=function(b){return f(b),a.normalMouse&&removeEventListener("mousemove",c),removeEventListener("mouseup",e),d(b)}),d(b)}}(this)),addEventListener("wheel",function(a){return function(b){if(a.mouseEvents){if(a.x10Mouse)return;return f(b),d(b)}}}(this))},a.prototype.refresh=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F;for(null==a&&(a=!1),x=this.element.querySelectorAll(".cursor"),l=0,m=x.length;m>l;l++)e=x[l],e.parentNode.replaceChild(this.document.createTextNode(e.textContent),e);for(t="",y=this.screen,k=s=0,n=y.length;n>s;k=++s)if(z=y[k],q=z[0],g=z[1],g||a){for(v="",F=k!==this.y+this.shift||this.cursorHidden?-(1/0):this.x,b=this.cloneAttr(this.defAttr),j=u=0,A=this.cols-1;A>=0?A>=u:u>=A;j=A>=0?++u:--u)if(f=q[j],f.html)v+=f.html;else{if(c=f.ch,this.equalAttr(f,b)||(this.equalAttr(b,this.defAttr)||(v+=""),this.equalAttr(f,this.defAttr)||(d=[],D=[],v+="h&&(h+=8),d.push("fg-color-"+h)),"string"==typeof f.fg&&D.push("color: "+f.fg),"number"==typeof f.bg&&d.push("bg-color-"+f.bg),"string"==typeof f.bg&&D.push("background-color: "+f.bg),v+='class="',v+=d.join(" "),v+='"',D.length&&(v+=' style="'+D.join("; ")+'"'),v+=">")),j===F&&(v+=''),c.length>1)v+=c;else switch(c){case"&":v+="&";break;case"<":v+="<";break;case">":v+=">";break;default:" "===c?v+='':" ">=c?v+=" ":(c>"＀"&&"￯">c&&j++,v+=c)}j===F&&(v+=""),b=f}this.equalAttr(b,this.defAttr)||(v+=""),this.children[k]?this.children[k].innerHTML=v:t+='
'+v+"
",this.screen[k][1]=!1}if(""!==t){if(i=this.document.createElement("div"),i.className="group",i.innerHTML=t,this.element.appendChild(i),this.screen=this.screen.slice(-this.rows),this.shift=0,r=document.querySelectorAll(".line"),r.length>this.scrollback){for(B=Array.prototype.slice.call(r,0,r.length-this.scrollback),w=0,o=B.length;o>w;w++)q=B[w],q.remove();for(C=document.querySelectorAll(".group:empty"),E=0,p=C.length;p>E;E++)i=C[E],i.remove();r=document.querySelectorAll(".line")}this.children=Array.prototype.slice.call(r,-this.rows)}return this.native_scroll_to()},a.prototype._cursorBlink=function(){var a;return this.cursorState^=1,(a=this.element.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][1]=!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.scrollBottom+1,0,[this.blank_line(),!0]),this.screen.splice(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][1]=!0);return e}return this.screen.push([this.blank_line(),!0]),this.shift++},a.prototype.native_scroll_to=function(a){return null==a&&(a=2e9),window.scrollTo(0,a)},a.prototype.scroll_display=function(a){return this.native_scroll_to(window.scrollY+a*this.char_size.height)},a.prototype.next_line=function(){return this.y++,this.y>this.scrollBottom?(this.y--,this.scroll()):void 0},a.prototype.write=function(c){var d,e,f,g,h,i,j,k,l,m,n;for(h=0,i=c.length;i>h;){switch(e=c.charAt(h),this.state){case b.normal:switch(e){case"":this.bell();break;case"\n":case" ":case"\f":this.convertEol&&(this.x=0),this.next_line();break;case"\r":this.x=0;break;case"\b":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(e>=" "&&((null!=(k=this.charset)?k[e]:void 0)&&(e=this.charset[e]),this.x>=this.cols&&(this.screen[this.y+this.shift][0][this.x]=this.cloneAttr(this.curAttr,"⏎"),this.screen[this.y+this.shift][1]=!0,this.x=0,this.next_line()),this.screen[this.y+this.shift][0][this.x]=this.cloneAttr(this.curAttr,e),this.screen[this.y+this.shift][1]=!0,this.x++,e>"＀"&&"￯">e)){if(this.cols<2||this.x>=this.cols){this.screen[this.y+this.shift][0][this.x-1]=this.cloneAttr(this.curAttr," "),this.screen[this.y+this.shift][1]=!0;break}this.screen[this.y+this.shift][0][this.x]=this.cloneAttr(this.curAttr," "),this.screen[this.y+this.shift][1]=!0,this.x++}}break;case b.escaped:switch(e){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.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,h++;break;case"(":case")":case"*":case"+":case"-":case".":switch(e){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,h--;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"#":this.state=b.normal,h++;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:",e)}break;case b.charset:switch(e){case"0":g=a.prototype.charsets.SCLD;break;case"A":g=a.prototype.charsets.UK;break;case"B":g=a.prototype.charsets.US;break;case"4":g=a.prototype.charsets.Dutch;break;case"C":case"5":g=a.prototype.charsets.Finnish;break;case"R":g=a.prototype.charsets.French;break;case"Q":g=a.prototype.charsets.FrenchCanadian;break;case"K":g=a.prototype.charsets.German;break;case"Y":g=a.prototype.charsets.Italian;break;case"E":case"6":g=a.prototype.charsets.NorwegianDanish;break;case"Z":g=a.prototype.charsets.Spanish;break;case"H":case"7":g=a.prototype.charsets.Swedish;break;case"=":g=a.prototype.charsets.Swiss;break;case"/":g=a.prototype.charsets.ISOLatin,h++;break;default:g=a.prototype.charsets.US}this.setgCharset(this.gcharset,g),this.gcharset=null,this.state=b.normal;break;case b.osc:if(""===e||""===e){switch(""===e&&h++,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+=e:e>="0"&&"9">=e?this.currentParam=10*this.currentParam+e.charCodeAt(0)-48:";"===e&&(this.params.push(this.currentParam),this.currentParam="");break;case b.csi:if("?"===e||">"===e||"!"===e){this.prefix=e;break}if(e>="0"&&"9">=e){this.currentParam=10*this.currentParam+e.charCodeAt(0)-48;break}if("$"===e||'"'===e||" "===e||"'"===e)break;if(this.params.push(this.currentParam),this.currentParam=0,";"===e)break;switch(this.state=b.normal,e){case"A":this.cursorUp(this.params);break;case"B":this.cursorDown(this.params);break;case"C":this.cursorForward(this.params);break;case"D":this.cursorBackward(this.params);break;case"H":this.cursorPos(this.params);break;case"J":this.eraseInDisplay(this.params);break;case"K":this.eraseInLine(this.params);break;case"m":this.prefix||this.charAttributes(this.params);break;case"n":this.prefix||this.deviceStatus(this.params);break;case"@":this.insertChars(this.params);break;case"E":this.cursorNextLine(this.params);break;case"F":this.cursorPrecedingLine(this.params);break;case"G":this.cursorCharAbsolute(this.params);break;case"L":this.insertLines(this.params);break;case"M":this.deleteLines(this.params);break;case"P":this.deleteChars(this.params);break;case"X":this.eraseChars(this.params);break;case"`":this.charPosAbsolute(this.params);break;case"a":this.HPositionRelative(this.params);break;case"c":this.sendDeviceAttributes(this.params);break;case"d":this.linePosAbsolute(this.params);break;case"e":this.VPositionRelative(this.params);break;case"f":this.HVPosition(this.params);break;case"h":this.setMode(this.params);break;case"l":this.resetMode(this.params);break;case"r":this.setScrollRegion(this.params);break;case"s":this.saveCursor(this.params);break;case"u":this.restoreCursor(this.params);break;case"I":this.cursorForwardTab(this.params);break;case"S":this.scrollUp(this.params);break;case"T":this.params.length<2&&!this.prefix&&this.scrollDown(this.params);break;case"Z":this.cursorBackwardTab(this.params);break;case"b":this.repeatPrecedingCharacter(this.params);break;case"g":this.tabClear(this.params);break;case"p":"!"===this.prefix&&this.softReset(this.params);break;default:console.error("Unknown CSI code: %s.",e)}this.prefix="";break;case b.dcs:if(""===e||""===e){switch(""===e&&h++,this.prefix){case"":if(j=this.currentParam,";"!==j[0]){console.error("Unknown DECUDK: "+j);break}if(j=j.slice(1),l=j.split("|",2),m=l[0],f=l[1],!f){console.error("No type for inline DECUDK: "+j);break}switch(m){case"HTML":if(!this.html_escapes_enabled){console.log("HTML escapes are disabled");break}d=this.cloneAttr(this.curAttr),d.html='
'+f+"
",this.screen[this.y][0][this.x]=d,this.screen[this.y][1]=!0;break;case"IMAGE":d=this.cloneAttr(this.curAttr),d.html='',this.screen[this.y][0][this.x]=d,this.screen[this.y][1]=!0;break;case"PROMPT":this.send(f);break;case"TEXT":i+=f.length,c=c.slice(0,h+1)+f+c.slice(h+1);break;default:console.error("Unknown type "+m+" for DECUDK")}break;case"$q":switch(j=this.currentParam,n=!1,j){case'"q':j='0"q';break;case'"p':j='61"p';break;case"r":j=""+(this.scrollTop+1)+";"+(this.scrollBottom+1)+"r";break;case"m":j="0m";break;default:console.error("Unknown DCS Pt: %s.",j),j=""}this.send("P"+ +n+"$r"+j+"\\");break;case"+q":j=this.currentParam,n=!1,this.send("P"+ +n+"+r"+j+"\\");break;default:console.error("Unknown DCS prefix: %s.",this.prefix)}this.currentParam=0,this.prefix="",this.state=b.normal}else this.currentParam?this.currentParam+=e:this.prefix||"$"===e||"+"===e?2===this.prefix.length?this.currentParam=e:this.prefix+=e:this.currentParam=e;break;case b.ignore:(""===e||""===e)&&(""===e&&h++,this.state=b.normal)}h++}return this.screen[this.y][1]=!0,this.refresh()},a.prototype.writeln=function(a){return this.write(a+"\r\n")},a.prototype.keyDown=function(a){var b,c,e,f;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===(e=a.keyCode)||86===e))return!0;if(a.altKey&&90===a.keyCode&&!this.skipNextKey)return this.skipNextKey=!0,this.element.classList.add("skip"),d(a);if(this.skipNextKey)return this.skipNextKey=!1,this.element.classList.remove("skip"),!0;switch(a.keyCode){case 8:if(c=a.altKey?"":"",a.shiftKey){c+="\b";break}c+="";break;case 9:if(a.shiftKey){c="";break}c=" ";break;case 13:c="\r";break;case 27:c="";break;case 37:if(this.applicationCursor){c="OD";break}c="";break;case 39:if(this.applicationCursor){c="OC";break}c="";break;case 38:if(this.applicationCursor){c="OA";break}if(a.ctrlKey)return this.scroll_display(-1),d(a);c="";break;case 40:if(this.applicationCursor){c="OB";break}if(a.ctrlKey)return this.scroll_display(1),d(a);c="";break;case 46:c="[3~";break;case 45:c="[2~";break;case 36:if(this.applicationKeypad){c="OH";break}c="OH";break;case 35:if(this.applicationKeypad){c="OF";break}c="OF";break;case 33:if(a.shiftKey)return this.scroll_display(-(this.rows-1)),d(a);c="[5~";break;case 34:if(a.shiftKey)return this.scroll_display(this.rows-1),d(a);c="[6~";break;case 112:c="OP";break;case 113:c="OQ";break;case 114:c="OR";break;case 115:c="OS";break;case 116:c="[15~";break;case 117:c="[17~";break;case 118:c="[18~";break;case 119:c="[19~";break;case 120:c="[20~";break;case 121:c="[21~";break;case 122:c="[23~";break;case 123:c="[24~";break;default:if(a.ctrlKey)if(a.keyCode>=65&&a.keyCode<=90){if(67===a.keyCode){if(f=(new Date).getTime(),f-this.last_cc<500&&!this.stop){for(b=setTimeout(function(){});b--;)b!==this.t_bell&&b!==this.t_queue&&b!==this.t_blink&&clearTimeout(b);this.element.classList.add("stopped"),this.stop=!0}else if(this.stop)return!0;this.last_cc=f}c=String.fromCharCode(a.keyCode-64)}else 32===a.keyCode?c=String.fromCharCode(0):a.keyCode>=51&&a.keyCode<=55?c=String.fromCharCode(a.keyCode-51+27):56===a.keyCode?c=String.fromCharCode(127):219===a.keyCode?c=String.fromCharCode(27):221===a.keyCode&&(c=String.fromCharCode(29));else(a.altKey&&k.call(navigator.platform,"Mac")<0||a.metaKey&&k.call(navigator.platform,"Mac")>=0)&&(a.keyCode>=65&&a.keyCode<=90?c=""+String.fromCharCode(a.keyCode+32):192===a.keyCode?c="`":a.keyCode>=48&&a.keyCode<=57&&(c=""+(a.keyCode-48)))}return a.keyCode>=37&&a.keyCode<=40&&(a.ctrlKey?c=c.slice(0,-1)+"1;5"+c.slice(-1):a.altKey?c=c.slice(0,-1)+"1;3"+c.slice(-1):a.shiftKey&&(c=c.slice(0,-1)+"1;4"+c.slice(-1))),c?(this.showCursor(),this.send(c),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.element.classList.add(a),this.t_bell=setTimeout(function(b){return function(){return b.element.classList.remove(a)}}(this),this.visualBell)):void 0},a.prototype.resize=function(){var a,b,c,d,e,f,g;if(e=this.cols,f=this.rows,this.compute_char_size(),this.cols=Math.floor(this.element.clientWidth/this.char_size.width),this.rows=Math.floor(window.innerHeight/this.char_size.height),g=window.innerHeight%this.char_size.height,this.element.style["padding-bottom"]=g+"px",e!==this.cols||f!==this.rows){if(this.ctl("Resize",this.cols,this.rows),ethis.cols)for(b=this.screen.length;b--;)for(;this.screen[b][0].length>this.cols;)this.screen[b][0].pop();if(this.setupStops(e),c=f,cthis.rows)for(;c-->this.rows;)this.screen.length>this.rows&&this.screen.pop(),this.children.length>this.rows&&(a=this.children.pop(),null!=a&&a.parentNode.removeChild(a));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),this.normal=null}},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][0];a=d?e>=c:c>=e;a=e>=d?++c:--c)this.screen[a+this.shift][1]=!0;return this.state=b.normal},a.prototype.reset=function(){return this.reset_vars(),this.refresh(!0)},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},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:4===d?this.curAttr.underline=!0:5===d?this.curAttr.blink=!0:7===d?this.curAttr.inverse=!0:8===d?this.curAttr.invisible=!0:10===d||(22===d?this.curAttr.bold=!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: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){if(this.prefix){if("?"===this.prefix&&6===a[0])return this.send("[?"+(this.y+1)+";"+(this.x+1)+"R")}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.blank_line(!0),!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][1]=!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.blank_line(!0),!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][1]=!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][0].splice(this.x,1),this.screen[this.y+this.shift][0].push(this.eraseAttr());return this.screen[this.y+this.shift][1]=!0},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)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);case 6:return this.originMode=!0;case 7:return this.wraparoundMode=!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.element.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},this.reset(),this.normal=e,this.showCursor()}}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)switch(a){case 1:return this.applicationCursor=!1;case 3:return 132===this.cols&&this.savedCols&&this.resize(this.savedCols,this.rows),delete this.savedCols;case 6:return this.originMode=!1;case 7:return this.wraparoundMode=!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.element.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.normal=null,this.refresh(!0),this.showCursor()}}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.blank_line(),!0]);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][1]=!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.blank_line(),!0]);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][1]=!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][0],b=c[this.x-1]||this.defAttr;d--;)c[this.x++]=b;return this.screen[this.y+this.shift][1]=!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.wraparoundMode=!1,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][0],this.screen[i][1]=!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][0],this.screen[i][1]=!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][0],this.screen[h][1]=!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;for(c=params[0],b=this.rows;c--;)for(a=0;b>a;)this.screen[a][0].splice(this.x+1,0,this.eraseAttr()),this.screen[a][0].pop(),a++;return this.screen[a][1]=!0},a.prototype.deleteColumns=function(){var a,b,c;for(c=params[0],b=this.rows;c--;)for(a=0;b>a;)this.screen[a][0].splice(this.x,1),this.screen[a][0].push(this.eraseAttr()),a++;return this.screen[a][1]=!0},a.prototype.charsets={SCLD:{"`":"◆",a:"▒",b:" ",c:"\f",d:"\r",e:"\n",f:"°",g:"±",h:"␤",i:" ",j:"┘",k:"┐",l:"┌",m:"└",n:"┼",o:"⎺",p:"⎻",q:"─",r:"⎼",s:"⎽",t:"├",u:"┤",v:"┴",w:"┬",x:"│",y:"≤",z:"≥","{":"π","|":"≠","}":"£","~":"·"},UK:null,US:null,Dutch:null,Finnish:null,French:null,FrenchCanadian:null,German:null,Italian:null,NorwegianDanish:null,Spanish:null,Swedish:null,Swiss:null,ISOLatin:null},a}(),window.Terminal=c}).call(this); +(function(){var a,b,c,d,e,f,g,h,i,j=[].slice,k=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};e=h=null,g=!1,f=(new Date).getTime(),a=document.querySelectorAll.bind(document),document.addEventListener("DOMContentLoaded",function(){var a,b,d,e,h,i,k,l,m;return e=function(a){return l.send("S"+a)},a=function(){var a,b,c;return c=arguments[0],a=2<=arguments.length?j.call(arguments,1):[],b=a.join(","),"Resize"===c?l.send("R"+b):void 0},m="https:"===location.protocol?"wss://":"ws://",m+=document.location.host+"/ws"+location.pathname,l=new WebSocket(m),l.addEventListener("open",function(){return console.log("WebSocket open",arguments),l.send("R"+i.cols+","+i.rows),f=(new Date).getTime()}),l.addEventListener("error",function(){return console.log("WebSocket error",arguments)}),b="",h=null,d="",l.addEventListener("message",function(a){return h&&clearTimeout(h),d+=a.data,i.stop&&(d=d.slice(-10240)),d.length>i.buff_size?k():h=setTimeout(k,1)}),k=function(){return i.write(d),i.stop&&(i.stop=!1,i.element.classList.remove("stopped")),d=""},l.addEventListener("close",function(){return console.log("WebSocket closed",arguments),setTimeout(function(){return i.write("Closed"),i.skipNextKey=!0,i.element.classList.add("dead")},1),g=!0,(new Date).getTime()-f>6e4?open("","_self").close():void 0}),i=new c(document.body,e,a),addEventListener("beforeunload",function(){return g?void 0:"This will exit the terminal session"}),i.ws=l,window.butterfly=i,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){var e;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,void b.send("[<"+(3===(3&c)?-4&c:c)+";"+d.x+";"+d.y+(3===(3&c)?"m":"M"))):(e=[],a(e,c),a(e,d.x),a(e,d.y),b.send(""+String.fromCharCode.apply(String,e)))}}(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.element.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),a.normalMouse&&addEventListener("mousemove",c),a.x10Mouse||addEventListener("mouseup",e=function(b){return f(b),a.normalMouse&&removeEventListener("mousemove",c),removeEventListener("mouseup",e),d(b)}),d(b)}}(this)),addEventListener("wheel",function(a){return function(b){if(a.mouseEvents){if(a.x10Mouse)return;return f(b),d(b)}}}(this))},a.prototype.refresh=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F;for(null==a&&(a=!1),x=this.element.querySelectorAll(".cursor"),l=0,m=x.length;m>l;l++)e=x[l],e.parentNode.replaceChild(this.document.createTextNode(e.textContent),e);for(t="",y=this.screen,k=s=0,n=y.length;n>s;k=++s)if(z=y[k],q=z[0],g=z[1],g||a){for(v="",F=k!==this.y+this.shift||this.cursorHidden?-(1/0):this.x,b=this.cloneAttr(this.defAttr),j=u=0,A=this.cols-1;A>=0?A>=u:u>=A;j=A>=0?++u:--u)if(f=q[j],f.html)v+=f.html;else{if(c=f.ch,this.equalAttr(f,b)||(this.equalAttr(b,this.defAttr)||(v+=""),this.equalAttr(f,this.defAttr)||(d=[],D=[],v+="h&&(h+=8),d.push("fg-color-"+h)),"string"==typeof f.fg&&D.push("color: "+f.fg),"number"==typeof f.bg&&d.push("bg-color-"+f.bg),"string"==typeof f.bg&&D.push("background-color: "+f.bg),v+='class="',v+=d.join(" "),v+='"',D.length&&(v+=' style="'+D.join("; ")+'"'),v+=">")),j===F&&(v+=''),c.length>1)v+=c;else switch(c){case"&":v+="&";break;case"<":v+="<";break;case">":v+=">";break;default:" "===c?v+='':" ">=c?v+=" ":(c>"＀"&&"￯">c&&j++,v+=c)}j===F&&(v+=""),b=f}this.equalAttr(b,this.defAttr)||(v+=""),this.children[k]?this.children[k].innerHTML=v:t+='
'+v+"
",this.screen[k][1]=!1}if(""!==t){if(i=this.document.createElement("div"),i.className="group",i.innerHTML=t,this.element.appendChild(i),this.screen=this.screen.slice(-this.rows),this.shift=0,r=document.querySelectorAll(".line"),r.length>this.scrollback){for(B=Array.prototype.slice.call(r,0,r.length-this.scrollback),w=0,o=B.length;o>w;w++)q=B[w],q.remove();for(C=document.querySelectorAll(".group:empty"),E=0,p=C.length;p>E;E++)i=C[E],i.remove();r=document.querySelectorAll(".line")}this.children=Array.prototype.slice.call(r,-this.rows)}return this.native_scroll_to()},a.prototype._cursorBlink=function(){var a;return this.cursorState^=1,(a=this.element.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][1]=!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.blank_line(),!0]),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][1]=!0);return e}return this.screen.push([this.blank_line(),!0]),this.shift++},a.prototype.unscroll=function(){var a,b,c,d,e;for(this.screen.splice(this.shift+this.scrollTop,0,[this.blank_line(!0),!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][1]=!0);return e},a.prototype.native_scroll_to=function(a){return null==a&&(a=2e9),window.scrollTo(0,a)},a.prototype.scroll_display=function(a){return this.native_scroll_to(window.scrollY+a*this.char_size.height)},a.prototype.next_line=function(){return this.y++,this.y>this.scrollBottom?(this.y--,this.scroll()):void 0},a.prototype.prev_line=function(){return this.y--,this.yi;){switch(f=c.charAt(i),this.state){case b.normal:switch(f){case"":this.bell();break;case"\n":case" ":case"\f":this.next_line();break;case"\r":this.x=0;break;case"\b":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(f>=" "&&((null!=(q=this.charset)?q[f]:void 0)&&(f=this.charset[f]),this.x>=this.cols&&(this.screen[this.y+this.shift][0][this.x]=this.cloneAttr(this.curAttr,"⏎"),this.screen[this.y+this.shift][1]=!0,this.x=0,this.next_line()),this.screen[this.y+this.shift][0][this.x]=this.cloneAttr(this.curAttr,f),this.screen[this.y+this.shift][1]=!0,this.x++,f>"＀"&&"￯">f)){if(this.cols<2||this.x>=this.cols){this.screen[this.y+this.shift][0][this.x-1]=this.cloneAttr(this.curAttr," "),this.screen[this.y+this.shift][1]=!0;break}this.screen[this.y+this.shift][0][this.x]=this.cloneAttr(this.curAttr," "),this.screen[this.y+this.shift][1]=!0,this.x++}}break;case b.escaped:switch(f){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.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,i++;break;case"(":case")":case"*":case"+":case"-":case".":switch(f){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,i--;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,i++,o=c.charAt(i)){case"3":break;case"4":break;case"5":break;case"6":break;case"8":for(r=this.screen,j=0,l=r.length;l>j;j++)for(m=r[j],m[1]=!0,e=n=0,s=m[0].length;s>=0?s>=n:n>=s;e=s>=0?++n:--n)m[0][e]=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:",f)}break;case b.charset:switch(f){case"0":h=a.prototype.charsets.SCLD;break;case"A":h=a.prototype.charsets.UK;break;case"B":h=a.prototype.charsets.US;break;case"4":h=a.prototype.charsets.Dutch;break;case"C":case"5":h=a.prototype.charsets.Finnish;break;case"R":h=a.prototype.charsets.French;break;case"Q":h=a.prototype.charsets.FrenchCanadian;break;case"K":h=a.prototype.charsets.German;break;case"Y":h=a.prototype.charsets.Italian;break;case"E":case"6":h=a.prototype.charsets.NorwegianDanish;break;case"Z":h=a.prototype.charsets.Spanish;break;case"H":case"7":h=a.prototype.charsets.Swedish;break;case"=":h=a.prototype.charsets.Swiss;break;case"/":h=a.prototype.charsets.ISOLatin,i++;break;default:h=a.prototype.charsets.US}this.setgCharset(this.gcharset,h),this.gcharset=null,this.state=b.normal;break;case b.osc:if(""===f||""===f){switch(""===f&&i++,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+=f:f>="0"&&"9">=f?this.currentParam=10*this.currentParam+f.charCodeAt(0)-48:";"===f&&(this.params.push(this.currentParam),this.currentParam="");break;case b.csi:if("?"===f||">"===f||"!"===f){this.prefix=f;break}if(f>="0"&&"9">=f){this.currentParam=10*this.currentParam+f.charCodeAt(0)-48;break}if("$"===f||'"'===f||" "===f||"'"===f)break;if(this.params.push(this.currentParam),this.currentParam=0,";"===f)break;switch(this.state=b.normal,f){case"A":this.cursorUp(this.params);break;case"B":this.cursorDown(this.params);break;case"C":this.cursorForward(this.params);break;case"D":this.cursorBackward(this.params);break;case"H":this.cursorPos(this.params);break;case"J":this.eraseInDisplay(this.params);break;case"K":this.eraseInLine(this.params);break;case"m":this.prefix||this.charAttributes(this.params);break;case"n":this.prefix||this.deviceStatus(this.params);break;case"@":this.insertChars(this.params);break;case"E":this.cursorNextLine(this.params);break;case"F":this.cursorPrecedingLine(this.params);break;case"G":this.cursorCharAbsolute(this.params);break;case"L":this.insertLines(this.params);break;case"M":this.deleteLines(this.params);break;case"P":this.deleteChars(this.params);break;case"X":this.eraseChars(this.params);break;case"`":this.charPosAbsolute(this.params);break;case"a":this.HPositionRelative(this.params);break;case"c":this.sendDeviceAttributes(this.params);break;case"d":this.linePosAbsolute(this.params);break;case"e":this.VPositionRelative(this.params);break;case"f":this.HVPosition(this.params);break;case"h":this.setMode(this.params);break;case"l":this.resetMode(this.params);break;case"r":this.setScrollRegion(this.params);break;case"s":this.saveCursor(this.params);break;case"u":this.restoreCursor(this.params);break;case"I":this.cursorForwardTab(this.params);break;case"S":this.scrollUp(this.params);break;case"T":this.params.length<2&&!this.prefix&&this.scrollDown(this.params);break;case"Z":this.cursorBackwardTab(this.params);break;case"b":this.repeatPrecedingCharacter(this.params);break;case"g":this.tabClear(this.params);break;case"p":"!"===this.prefix&&this.softReset(this.params);break;default:console.error("Unknown CSI code: %s.",f)}this.prefix="";break;case b.dcs:if(""===f||""===f){switch(""===f&&i++,this.prefix){case"":if(p=this.currentParam,";"!==p[0]){console.error("Unknown DECUDK: "+p);break}if(p=p.slice(1),t=p.split("|",2),u=t[0],g=t[1],!g){console.error("No type for inline DECUDK: "+p);break}switch(u){case"HTML":if(!this.html_escapes_enabled){console.log("HTML escapes are disabled");break}d=this.cloneAttr(this.curAttr),d.html='
'+g+"
",this.screen[this.y+this.shift][0][this.x]=d,this.screen[this.y+this.shift][1]=!0;break;case"IMAGE":d=this.cloneAttr(this.curAttr),d.html='',this.screen[this.y+this.shift][0][this.x]=d,this.screen[this.y+this.shift][1]=!0;break;case"PROMPT":this.send(g);break;case"TEXT":k+=g.length,c=c.slice(0,i+1)+g+c.slice(i+1);break;default:console.error("Unknown type "+u+" for DECUDK")}break;case"$q":switch(p=this.currentParam,v=!1,p){case'"q':p='0"q';break;case'"p':p='61"p';break;case"r":p=""+(this.scrollTop+1)+";"+(this.scrollBottom+1)+"r";break;case"m":p="0m";break;default:console.error("Unknown DCS Pt: %s.",p),p=""}this.send("P"+ +v+"$r"+p+"\\");break;case"+q":p=this.currentParam,v=!1,this.send("P"+ +v+"+r"+p+"\\");break;default:console.error("Unknown DCS prefix: %s.",this.prefix)}this.currentParam=0,this.prefix="",this.state=b.normal}else this.currentParam?this.currentParam+=f:this.prefix||"$"===f||"+"===f?2===this.prefix.length?this.currentParam=f:this.prefix+=f:this.currentParam=f;break;case b.ignore:(""===f||""===f)&&(""===f&&i++,this.state=b.normal)}i++}return this.screen[this.y+this.shift][1]=!0,this.refresh()},a.prototype.writeln=function(a){return this.write(a+"\r\n")},a.prototype.keyDown=function(a){var b,c,e,f;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===(e=a.keyCode)||86===e))return!0;if(a.altKey&&90===a.keyCode&&!this.skipNextKey)return this.skipNextKey=!0,this.element.classList.add("skip"),d(a);if(this.skipNextKey)return this.skipNextKey=!1,this.element.classList.remove("skip"),!0;switch(a.keyCode){case 8:if(c=a.altKey?"":"",a.shiftKey){c+="\b";break}c+="";break;case 9:if(a.shiftKey){c="";break}c=" ";break;case 13:c="\r";break;case 27:c="";break;case 37:if(this.applicationCursor){c="OD";break}c="";break;case 39:if(this.applicationCursor){c="OC";break}c="";break;case 38:if(this.applicationCursor){c="OA";break}if(a.ctrlKey)return this.scroll_display(-1),d(a);c="";break;case 40:if(this.applicationCursor){c="OB";break}if(a.ctrlKey)return this.scroll_display(1),d(a);c="";break;case 46:c="[3~";break;case 45:c="[2~";break;case 36:if(this.applicationKeypad){c="OH";break}c="OH";break;case 35:if(this.applicationKeypad){c="OF";break}c="OF";break;case 33:if(a.shiftKey)return this.scroll_display(-(this.rows-1)),d(a);c="[5~";break;case 34:if(a.shiftKey)return this.scroll_display(this.rows-1),d(a);c="[6~";break;case 112:c="OP";break;case 113:c="OQ";break;case 114:c="OR";break;case 115:c="OS";break;case 116:c="[15~";break;case 117:c="[17~";break;case 118:c="[18~";break;case 119:c="[19~";break;case 120:c="[20~";break;case 121:c="[21~";break;case 122:c="[23~";break;case 123:c="[24~";break;default:if(a.ctrlKey)if(a.keyCode>=65&&a.keyCode<=90){if(67===a.keyCode){if(f=(new Date).getTime(),f-this.last_cc<500&&!this.stop){for(b=setTimeout(function(){});b--;)b!==this.t_bell&&b!==this.t_queue&&b!==this.t_blink&&clearTimeout(b);this.element.classList.add("stopped"),this.stop=!0}else if(this.stop)return!0;this.last_cc=f}c=String.fromCharCode(a.keyCode-64)}else 32===a.keyCode?c=String.fromCharCode(0):a.keyCode>=51&&a.keyCode<=55?c=String.fromCharCode(a.keyCode-51+27):56===a.keyCode?c=String.fromCharCode(127):219===a.keyCode?c=String.fromCharCode(27):221===a.keyCode&&(c=String.fromCharCode(29));else(a.altKey&&k.call(navigator.platform,"Mac")<0||a.metaKey&&k.call(navigator.platform,"Mac")>=0)&&(a.keyCode>=65&&a.keyCode<=90?c=""+String.fromCharCode(a.keyCode+32):192===a.keyCode?c="`":a.keyCode>=48&&a.keyCode<=57&&(c=""+(a.keyCode-48)))}return a.keyCode>=37&&a.keyCode<=40&&(a.ctrlKey?c=c.slice(0,-1)+"1;5"+c.slice(-1):a.altKey?c=c.slice(0,-1)+"1;3"+c.slice(-1):a.shiftKey&&(c=c.slice(0,-1)+"1;4"+c.slice(-1))),c?(this.showCursor(),this.send(c),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.element.classList.add(a),this.t_bell=setTimeout(function(b){return function(){return b.element.classList.remove(a)}}(this),this.visualBell)):void 0},a.prototype.resize=function(a,b){var c,d,e,f,g,h,i;if(null==a&&(a=null),null==b&&(b=null),g=this.cols,h=this.rows,this.compute_char_size(),this.cols=a||Math.floor(this.element.clientWidth/this.char_size.width),this.rows=b||Math.floor(window.innerHeight/this.char_size.height),i=window.innerHeight%this.char_size.height,this.element.style["padding-bottom"]=i+"px",a||b||g!==this.cols||h!==this.rows){if(this.ctl("Resize",this.cols,this.rows),gthis.cols)for(d=this.screen.length;d--;)for(;this.screen[d][0].length>this.cols;)this.screen[d][0].pop();if(this.setupStops(g),e=h,ethis.rows)for(;e-->this.rows;)this.screen.length>this.rows&&this.screen.pop(),this.children.length>this.rows&&(c=this.children.pop(),null!=c&&c.parentNode.removeChild(c));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),this.normal=null,a||b?this.reset():void 0}},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][0];ab&&(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},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:4===d?this.curAttr.underline=!0:5===d?this.curAttr.blink=!0:7===d?this.curAttr.inverse=!0:8===d?this.curAttr.invisible=!0:10===d||(22===d?this.curAttr.bold=!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: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){if(this.prefix){if("?"===this.prefix&&6===a[0])return this.send("[?"+(this.y+1)+";"+(this.x+1)+"R")}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.blank_line(!0),!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][1]=!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.blank_line(!0),!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][1]=!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][0].splice(this.x,1),this.screen[this.y+this.shift][0].push(this.eraseAttr());return this.screen[this.y+this.shift][1]=!0},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);case 6:return this.originMode=!0;case 7:return this.wraparoundMode=!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.element.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},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),delete this.savedCols;case 6:return this.originMode=!1;case 7:return this.wraparoundMode=!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.element.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.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.blank_line(),!0]);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][1]=!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.blank_line(),!0]);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][1]=!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][0],b=c[this.x-1]||this.defAttr;d--;)c[this.x++]=b;return this.screen[this.y+this.shift][1]=!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.wraparoundMode=!1,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][0],this.screen[i+this.shift][1]=!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][0],this.screen[i+this.shift][1]=!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][0],this.screen[h+this.shift][1]=!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;for(c=params[0],b=this.rows+this.shift;c--;)for(a=this.shift;b>a;)this.screen[a][0].splice(this.x+1,0,this.eraseAttr()),this.screen[a][0].pop(),a++;return this.screen[a][1]=!0},a.prototype.deleteColumns=function(){var a,b,c;for(c=params[0],b=this.rows+this.shift;c--;)for(a=this.shift;b>a;)this.screen[a][0].splice(this.x,1),this.screen[a][0].push(this.eraseAttr()),a++;return this.screen[a][1]=!0},a.prototype.charsets={SCLD:{"`":"◆",a:"▒",b:" ",c:"\f",d:"\r",e:"\n",f:"°",g:"±",h:"␤",i:" ",j:"┘",k:"┐",l:"┌",m:"└",n:"┼",o:"⎺",p:"⎻",q:"─",r:"⎼",s:"⎽",t:"├",u:"┤",v:"┴",w:"┬",x:"│",y:"≤",z:"≥","{":"π","|":"≠","}":"£","~":"·"},UK:null,US:null,Dutch:null,Finnish:null,French:null,FrenchCanadian:null,German:null,Italian:null,NorwegianDanish:null,Spanish:null,Swedish:null,Swiss:null,ISOLatin:null},a}(),window.Terminal=c}).call(this); //# sourceMappingURL=main.min.js.map \ No newline at end of file diff --git a/coffees/term.coffee b/coffees/term.coffee index 2e165bb..f946e97 100644 --- a/coffees/term.coffee +++ b/coffees/term.coffee @@ -93,7 +93,7 @@ class Terminal addEventListener 'keypress', @keyPress.bind(@) addEventListener 'focus', @focus.bind(@) addEventListener 'blur', @blur.bind(@) - addEventListener 'resize', @resize.bind(@) + addEventListener 'resize', => @resize() # # Horrible Firefox paste workaround if typeof InstallTrigger isnt "undefined" @@ -523,8 +523,8 @@ class Terminal # Use emulated scroll in alternate buffer or when scroll region is defined if @normal or @scrollTop isnt 0 or @scrollBottom isnt @rows - 1 # inner scroll - @screen.splice @scrollBottom + 1, 0, [@blank_line(), true] - @screen.splice @scrollTop, 1 + @screen.splice @shift + @scrollBottom + 1, 0, [@blank_line(), true] + @screen.splice @shift + @scrollTop, 1 for i in [@scrollTop..@scrollBottom] @screen[i + @shift][1] = true @@ -532,6 +532,14 @@ class Terminal @screen.push [@blank_line(), true] @shift++ + unscroll: -> + @screen.splice @shift + @scrollTop , 0, [@blank_line(true), true] + @screen.splice @shift + @scrollBottom + 1, 1 + + for i in [@scrollTop..@scrollBottom] + @screen[i + @shift][1] = true + + native_scroll_to: (scroll=2000000000) -> # ~ Max ff number window.scrollTo 0, scroll @@ -544,6 +552,12 @@ class Terminal @y-- @scroll() + prev_line: -> + @y-- + if @y < @scrollTop + @y++ + @unscroll() + write: (data) -> i = 0 l = data.length @@ -559,7 +573,7 @@ class Terminal # '\n', '\v', '\f' when "\n", "\x0b", "\x0c" - @x = 0 if @convertEol + # @x = 0 if @convertEol @next_line() # '\r' @@ -723,6 +737,22 @@ class Terminal when "#" @state = State.normal i++ + num = data.charAt(i) + switch num + when "3" # DECDHL + break + when "4" # DECDHL + break + when "5" # DECSWL + break + when "6" # DECDWL + break + when "8" # DECALN + for line in @screen + line[1] = true + for c in [0..line[0].length] + line[0][c] = @cloneAttr @curAttr, "E" + @x = @y = 0 # ESC H Tab Set (HTS is 0x88). when "H" @@ -1041,16 +1071,16 @@ class Terminal attr = @cloneAttr @curAttr attr.html = ( "
#{content}
") - @screen[@y][0][@x] = attr - @screen[@y][1] = true + @screen[@y + @shift][0][@x] = attr + @screen[@y + @shift][1] = true when "IMAGE" attr = @cloneAttr @curAttr attr.html = ( "") - @screen[@y][0][@x] = attr - @screen[@y][1] = true + @screen[@y + @shift][0][@x] = attr + @screen[@y + @shift][1] = true when "PROMPT" @send content @@ -1119,7 +1149,7 @@ class Terminal @state = State.normal i++ - @screen[@y][1] = true + @screen[@y + @shift][1] = true @refresh() writeln: (data) -> @@ -1409,16 +1439,16 @@ class Terminal @element.classList.remove cls ), @visualBell - resize: -> + resize: (x=null, y=null) -> old_cols = @cols old_rows = @rows @compute_char_size() - @cols = Math.floor(@element.clientWidth / @char_size.width) - @rows = Math.floor(window.innerHeight / @char_size.height) + @cols = x or Math.floor(@element.clientWidth / @char_size.width) + @rows = y or Math.floor(window.innerHeight / @char_size.height) px = window.innerHeight % @char_size.height @element.style['padding-bottom'] = "#{px}px" - if old_cols == @cols and old_rows == @rows + if (not x and not y) and old_cols == @cols and old_rows == @rows return @ctl 'Resize', @cols, @rows @@ -1468,6 +1498,7 @@ class Terminal # screen buffer. just set it # to null for now. @normal = null + @reset() if x or y setupStops: (i) -> if i? @@ -1540,11 +1571,7 @@ class Terminal # ESC M Reverse Index (RI is 0x8d). reverseIndex: -> - @screen.splice @scrollBottom, 1 - @screen.splice @scrollTop, 0, [@blank_line(true), true] - for i in [@scrollTop..@scrollBottom] - @screen[i + @shift][1] = true - + @prev_line() @state = State.normal # ESC c Full Reset (RIS). @@ -2154,6 +2181,13 @@ class Terminal @setMode params[i] i++ return + if not @prefix + switch params + when 4 + @insertMode = true + when 20 + @convertEol = true + return if @prefix is "?" switch params when 1 @@ -2310,6 +2344,13 @@ class Terminal @resetMode params[i] i++ return + if not @prefix + switch params + when 4 + @insertMode = false + when 20 + @convertEol = false + return if @prefix is "?" switch params @@ -2615,8 +2656,8 @@ class Terminal r = params[3] attr = params[4] while t < b + 1 - line = @screen[t][0] - @screen[t][1] = true + line = @screen[t + @shift][0] + @screen[t + @shift][1] = true i = l while i < r line[i] = @cloneAttr attr, line[i].ch @@ -2772,8 +2813,8 @@ class Terminal b = params[3] r = params[4] while t < b + 1 - line = @screen[t][0] - @screen[t][1] = true + line = @screen[t + @shift][0] + @screen[t + @shift][1] = true i = l while i < r line[i] = @cloneAttr line[i][0], String.fromCharCode(ch) @@ -2807,8 +2848,8 @@ class Terminal b = params[2] r = params[3] while t < b + 1 - line = @screen[t][0] - @screen[t][1] = true + line = @screen[t + @shift][0] + @screen[t + @shift][1] = true i = l while i < r line[i] = @eraseAttr() @@ -2883,9 +2924,9 @@ class Terminal # NOTE: xterm doesn't enable this code by default. insertColumns: -> param = params[0] - l = @rows + l = @rows + @shift while param-- - i = 0 + i = @shift while i < l @screen[i][0].splice @x + 1, 0, @eraseAttr() @screen[i][0].pop() @@ -2898,9 +2939,9 @@ class Terminal # NOTE: xterm doesn't enable this code by default. deleteColumns: -> param = params[0] - l = @rows + l = @rows + @shift while param-- - i = 0 + i = @shift while i < l @screen[i][0].splice @x, 1 @screen[i][0].push @eraseAttr()