/**
 * term.js - an xterm emulator
 * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
 * https://github.com/chjj/term.js
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * Originally forked from (with the author's permission):
 *   Fabrice Bellard's javascript vt100 for jslinux:
 *   http://bellard.org/jslinux/
 *   Copyright (c) 2011 Fabrice Bellard
 *   The original design remains. The terminal itself
 *   has been extended to include xterm CSI codes, among
 *   other features.
 */

define("themes",[],function(){return{blazer:{palette:["#262626","#dbbdbd","#bddbbd","#dbdbbd","#bdbddb","#dbbddb","#bddbdb","#ffffff"],name:"blazer"},chalkboard:{foreground:"#d9e6f2",background:"#29262f",cursor:"#d9e6f2",cursor_text:"#29262f",palette:["#000000","#c37372","#72c373","#c2c372","#7372c3","#c372c2","#72c2c3","#d9d9d9","#323232","#dbaaaa","#aadbaa","#dadbaa","#aaaadb","#dbaada","#aadadb","#ffffff"],name:"chalkboard"},dark_pastel:{foreground:"#ffffff",background:"#000000",cursor:"#bbbbbb",cursor_text:"#ffffff",palette:["#000000","#ff5555","#55ff55","#ffff55","#5555ff","#ff55ff","#55ffff","#bbbbbb","#555555","#ff5555","#55ff55","#ffff55","#5555ff","#ff55ff","#55ffff","#ffffff"],name:"dark_pastel"},desert:{foreground:"#ffffff",background:"#333333",cursor:"#00ff00",cursor_text:"#000000",palette:["#4d4d4d","#ff2b2b","#98fb98","#f0e68c","#cd853f","#ffdead","#ffa0a0","#f5deb3","#555555","#ff5555","#55ff55","#ffff55","#87ceff","#ff55ff","#ffd700","#ffffff"],name:"desert"},espresso:{foreground:"#ffffff",background:"#323232",cursor:"#d6d6d6",cursor_text:"#ffffff",palette:["#343434","#d25151","#a5c261","#ffc66d","#6c99bb","#d197d9","#bed6ff","#eeeeec","#535353","#f00c0c","#c2e075","#e1e38b","#8ab7d9","#efb5f7","#dcf3ff","#ffffff"],name:"espresso"},github:{foreground:"#3e3e3e",background:"#f4f4f4",cursor:"#3f3f3f",cursor_text:"#f4f4f4",palette:["#3e3e3e","#970b16","#07962a","#f8eec7","#003e8a","#e94691","#89d1ec","#ffffff","#666666","#de0000","#87d5a2","#f1d007","#2e6cba","#ffa29f","#1cfafe","#ffffff"],name:"github"},grass:{foreground:"#fff0a5",background:"#13773c",cursor:"#8c2800",cursor_text:"#ffffff",palette:["#000000","#bb0000","#00bb00","#e7b000","#0000a3","#950061","#00bbbb","#bbbbbb","#555555","#bb0000","#00bb00","#e7b000","#0000bb","#ff55ff","#55ffff","#ffffff"],name:"grass"},homebrew:{foreground:"#00ff00",background:"#000000",cursor:"#23ff18",cursor_text:"#ff0017",palette:["#000000","#990000","#00a600","#999900","#0000b2","#b200b2","#00a6b2","#bfbfbf","#666666","#e50000","#00d900","#e5e500","#0000ff","#e500e5","#00e5e5","#e5e5e5"],name:"homebrew"},hurtado:{foreground:"#dadbda",background:"#000000",cursor:"#bbbbbb",cursor_text:"#ffffff",palette:["#575757","#ff1b00","#a5df55","#fbe74a","#486387","#fc5ef0","#85e9fe","#cbcbcb","#252525","#d41c00","#a5df55","#fbe749","#89bdff","#bf00c0","#85e9fe","#dbdbdb"],name:"hurtado"},idletoes:{foreground:"#ffffff",background:"#323232",cursor:"#d6d6d6",cursor_text:"#000000",palette:["#323232","#d25252","#7fe173","#ffc66d","#4098ff","#f57fff","#bed6ff","#eeeeec","#535353","#f07070","#9dff90","#ffe48b","#5eb7f7","#ff9dff","#dcf4ff","#ffffff"],name:"idletoes"},kibble:{foreground:"#f7f7f7",background:"#0e100a",cursor:"#9fda9c",cursor_text:"#000000",palette:["#4d4d4d","#c70031","#29cf13","#d8e30e","#3449d1","#8400ff","#0798ab","#e2d1e3","#5a5a5a","#f01578","#6ce05c","#f3f79e","#97a4f7","#c495f0","#68f2e0","#ffffff"],name:"kibble"},man_page:{foreground:"#000000",background:"#fef49c",cursor:"#7f7f7f",cursor_text:"#000000",palette:["#000000","#cc0000","#00a600","#999900","#0000b2","#b200b2","#00a6b2","#cccccc","#666666","#e50000","#00d900","#e5e500","#0000ff","#e500e5","#00e5e5","#e5e5e5"],name:"man_page"},monokai_soda:{foreground:"#c4c4b5",background:"#191919",cursor:"#f6f6ec",cursor_text:"#c4c4b5",palette:["#191919","#f3005f","#97e023","#fa8419","#9c64fe","#f3005f","#57d1ea","#c4c4b5","#615e4b","#f3005f","#97e023","#dfd561","#9c64fe","#f3005f","#57d1ea","#f6f6ee"],name:"monokai_soda"},neopolitan:{foreground:"#ffffff",background:"#17130f",cursor:"#ffffff",cursor_text:"#ffffff",palette:["#17130f","#800000","#61ce3c","#fbde2d","#253b76","#ff0080","#8da6ce","#f8f8f8","#17130f","#800000","#61ce3c","#fbde2d","#253b76","#ff0080","#8da6ce","#f8f8f8"],name:"neopolitan"},novel:{foreground:"#3b2322",background:"#dfdbc3",cursor:"#73635a",cursor_text:"#000000",palette:["#000000","#cc0000","#009600","#d06b00","#0000cc","#cc00cc","#0087cc","#cccccc","#7f7f7f","#cc0000","#009600","#d06b00","#0000cc","#cc00cc","#0086cb","#ffffff"],name:"novel"},ocean:{foreground:"#ffffff",background:"#224fbc",cursor:"#7f7f7f",cursor_text:"#ffffff",palette:["#000000","#990000","#00a600","#999900","#0000b2","#b200b2","#00a6b2","#bfbfbf","#666666","#e50000","#00d900","#e5e500","#0000ff","#e500e5","#00e5e5","#e5e5e5"],name:"ocean"},pro:{foreground:"#f2f2f2",background:"#000000",cursor:"#4d4d4d",cursor_text:"#ffffff",palette:["#000000","#990000","#00a600","#999900","#1f08db","#b200b2","#00a6b2","#bfbfbf","#666666","#e50000","#00d900","#e5e500","#0000ff","#e500e5","#00e5e5","#e5e5e5"],name:"pro"},red_sands:{foreground:"#d7c9a7",background:"#79241e",cursor:"#ffffff",cursor_text:"#000000",palette:["#000000","#ff3f00","#00bb00","#e7b000","#0071ff","#bb00bb","#00bbbb","#bbbbbb","#555555","#bb0000","#00bb00","#e7b000","#0071ae","#ff55ff","#55ffff","#ffffff"],name:"red_sands"},seafoam_pastel:{foreground:"#d3e7d3",background:"#243434",cursor:"#576479",cursor_text:"#323232",palette:["#757575","#825d4d","#718c61","#ada16d","#4d7b82","#8a7167","#719393","#e0e0e0","#8a8a8a","#cf9379","#98d9aa","#fae79d","#79c3cf","#d6b2a1","#ade0e0","#e0e0e0"],name:"seafoam_pastel"},solarized_darcula:{foreground:"#d2d8d9",background:"#3d3f41",cursor:"#708183",cursor_text:"#002731",palette:["#25292a","#f24840","#629655","#b68800","#2075c7","#797fd4","#15968d","#d2d8d9","#25292a","#f24840","#629655","#b68800","#2075c7","#797fd4","#15968d","#d2d8d9"],name:"solarized_darcula"},solarized_dark:{foreground:"#708183",background:"#001e26",cursor:"#708183",cursor_text:"#002731",palette:["#002731","#d01b24","#728905","#a57705","#2075c7","#c61b6e","#259185","#e9e2cb","#001e26","#bd3612","#465a61","#52676f","#708183","#5856b9","#81908f","#fcf4dc"],name:"solarized_dark"},solarized_light:{foreground:"#52676f",background:"#fcf4dc",cursor:"#52676f",cursor_text:"#e9e2cb",palette:["#002731","#d01b24","#728905","#a57705","#2075c7","#c61b6e","#259185","#e9e2cb","#001e26","#bd3612","#465a61","#52676f","#708183","#5856b9","#81908f","#fcf4dc"],name:"solarized_light"},symfonic:{foreground:"#ffffff",background:"#000000",cursor:"#dc322f",cursor_text:"#ffffff",palette:["#000000","#dc322f","#56db3a","#ff8400","#0084d4","#b729d9","#ccccff","#ffffff","#1b1d21","#dc322f","#56db3a","#ff8400","#0084d4","#b729d9","#ccccff","#ffffff"],name:"symfonic"},terminal_basic:{foreground:"#000000",background:"#ffffff",cursor:"#7f7f7f",cursor_text:"#000000",palette:["#000000","#990000","#00a600","#999900","#0000b2","#b200b2","#00a6b2","#bfbfbf","#666666","#e50000","#00d900","#e5e500","#0000ff","#e500e5","#00e5e5","#e5e5e5"],name:"terminal_basic"},vaughn:{foreground:"#dcdccc",background:"#25234e",cursor:"#ff5555",cursor_text:"#ffffff",palette:["#24234f","#705050","#60b48a","#dfaf8f","#5555ff","#f08cc3","#8cd0d3","#709080","#709080","#dca3a3","#60b48a","#f0dfaf","#5555ff","#ec93d3","#93e0e3","#ffffff"],name:"vaughn"},zenburn:{foreground:"#dcdccc",background:"#3f3f3f",cursor:"#73635a",cursor_text:"#000000",palette:["#4d4d4d","#705050","#60b48a","#f0dfaf","#506070","#dc8cc3","#8cd0d3","#dcdccc","#709080","#dca3a3","#c3bf9f","#e0cf9f","#94bff3","#ec93d3","#93e0e3","#ffffff"],name:"zenburn"}}}),function(){function n(){this._events=this._events||{}}function l(e){var r=this;if(!(this instanceof l))return new l(arguments[0],arguments[1],arguments[2]);n.call(this),typeof e=="number"&&(e={cols:arguments[0],rows:arguments[1],handler:arguments[2]}),e=e||{},S(x(l.defaults),function(t){e[t]==null&&(e[t]=l.options[t],l[t]!==l.defaults[t]&&(e[t]=l[t])),r[t]=e[t]}),e.colors.length===8?e.colors=e.colors.concat(l._colors.slice(8)):e.colors.length===16?e.colors=e.colors.concat(l._colors.slice(16)):e.colors.length===10?e.colors=e.colors.slice(0,-2).concat(l._colors.slice(8,-2),e.colors.slice(-2)):e.colors.length===18&&(e.colors=e.colors.concat(l._colors.slice(16,-2),e.colors.slice(-2))),this.colors=e.colors,this.options=e,this.parent=e.body||e.parent||(t?t.getElementsByTagName("body")[0]:null),this.cols=e.cols||e.geometry[0],this.rows=e.rows||e.geometry[1],e.handler&&this.on("data",e.handler),this.ybase=0,this.ydisp=0,this.x=0,this.y=0,this.cursorState=0,this.cursorHidden=!1,this.convertEol,this.state=0,this.queue="",this.scrollTop=0,this.scrollBottom=this.rows-1,this.applicationKeypad=!1,this.applicationCursor=!1,this.originMode=!1,this.insertMode=!1,this.wraparoundMode=!1,this.normal=null,this.prefixMode=!1,this.selectMode=!1,this.visualMode=!1,this.searchMode=!1,this.searchDown,this.entry="",this.entryPrefix="",this._real,this._selected,this._textarea,this.charset=null,this.gcharset=null,this.glevel=0,this.charsets=[null],this.decLocator,this.x10Mouse,this.vt200Mouse,this.vt300Mouse,this.normalMouse,this.mouseEvents,this.sendFocus,this.utfMouse,this.sgrMouse,this.urxvtMouse,this.element,this.children,this.refreshStart,this.refreshEnd,this.savedX,this.savedY,this.savedCols,this.readable=!0,this.writable=!0,this.defAttr=131840,this.curAttr=this.defAttr,this.params=[],this.currentParam=0,this.prefix="",this.postfix="",this.lines=[];var i=this.rows;while(i--)this.lines.push(this.blankLine());this.tabs,this.setupStops()}function c(e,t,n,r){e.addEventListener(t,n,r||!1)}function h(e,t,n,r){e.removeEventListener(t,n,r||!1)}function p(e){return e.preventDefault(),e.stopPropagation(),e.cancelBubble=!0,!1}function d(e,t){function n(){this.constructor=e}n.prototype=t.prototype,e.prototype=new n}function v(e){var t=e.getElementsByTagName("body")[0],n=e.createElement("span");n.innerHTML="hello world",t.appendChild(n);var r=n.scrollWidth;n.style.fontWeight="bold";var i=n.scrollWidth;return t.removeChild(n),r!==i}function b(e,t){var n=e.length;while(n--)if(e[n]===t)return n;return-1}function w(e){return e<="＀"?!1:e>="！"&&e<="ﾾ"||e>="ￂ"&&e<="ￇ"||e>="ￊ"&&e<="ￏ"||e>="ￒ"&&e<="ￗ"||e>="ￚ"&&e<="ￜ"||e>="￠"&&e<="￦"||e>="￨"&&e<="￮"}function E(e,t,n){var r=e<<16|t<<8|n;if(E._cache[r]!=null)return E._cache[r];var i=Infinity,s=-1,o=0,u,a,f,c,h;for(;o<l.vcolors.length;o++){u=l.vcolors[o],a=u[0],f=u[1],c=u[2],h=E.distance(e,t,n,a,f,c);if(h===0){s=o;break}h<i&&(i=h,s=o)}return E._cache[r]=s}function S(e,t,n){if(e.forEach)return e.forEach(t,n);for(var r=0;r<e.length;r++)t.call(n,e[r],r,e)}function x(e){if(Object.keys)return Object.keys(e);var t,n=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&n.push(t);return n}var e=this,t=this.document;n.prototype.addListener=function(e,t){this._events[e]=this._events[e]||[],this._events[e].push(t)},n.prototype.on=n.prototype.addListener,n.prototype.removeListener=function(e,t){if(!this._events[e])return;var n=this._events[e],r=n.length;while(r--)if(n[r]===t||n[r].listener===t){n.splice(r,1);return}},n.prototype.off=n.prototype.removeListener,n.prototype.removeAllListeners=function(e){this._events[e]&&delete this._events[e]},n.prototype.once=function(e,t){function n(){var r=Array.prototype.slice.call(arguments);return this.removeListener(e,n),t.apply(this,r)}return n.listener=t,this.on(e,n)},n.prototype.emit=function(e){if(!this._events[e])return;var t=Array.prototype.slice.call(arguments,1),n=this._events[e],r=n.length,i=0;for(;i<r;i++)n[i].apply(this,t)},n.prototype.listeners=function(e){return this._events[e]=this._events[e]||[]};var r=0,i=1,s=2,o=3,u=4,a=5,f=6;d(l,n),l.prototype.eraseAttr=function(){return this.defAttr&-512|this.curAttr&511},l.tangoColors=["#2e3436","#cc0000","#4e9a06","#c4a000","#3465a4","#75507b","#06989a","#d3d7cf","#555753","#ef2929","#8ae234","#fce94f","#729fcf","#ad7fa8","#34e2e2","#eeeeec"],l.xtermColors=["#000000","#cd0000","#00cd00","#cdcd00","#0000ee","#cd00cd","#00cdcd","#e5e5e5","#7f7f7f","#ff0000","#00ff00","#ffff00","#5c5cff","#ff00ff","#00ffff","#ffffff"],l.colors=function(){function r(t,n,r){e.push("#"+i(t)+i(n)+i(r))}function i(e){return e=e.toString(16),e.length<2?"0"+e:e}var e=l.tangoColors.slice(),t=[0,95,135,175,215,255],n;n=0;for(;n<216;n++)r(t[n/36%6|0],t[n/6%6|0],t[n%6]);n=0;for(;n<24;n++)t=8+n*10,r(t,t,t);return e}(),l.colors[256]="#000000",l.colors[257]="#f0f0f0",l._colors=l.colors.slice(),l.vcolors=function(){var e=[],t=l.colors,n=0,r;for(;n<256;n++)r=parseInt(t[n].substring(1),16),e.push([r>>16&255,r>>8&255,r&255]);return e}(),l.defaults={colors:l.colors,convertEol:!1,termName:"xterm",geometry:[80,24],cursorBlink:!0,visualBell:!1,popOnBell:!1,scrollback:1e3,screenKeys:!1,debug:!1,useStyle:!1},l.options={},S(x(l.defaults),function(e){l[e]=l.defaults[e],l.options[e]=l.defaults[e]}),l.focus=null,l.prototype.focus=function(){if(l.focus===this)return;l.focus&&l.focus.blur(),this.sendFocus&&this.send("[I"),this.showCursor(),l.focus=this},l.prototype.blur=function(){if(l.focus!==this)return;this.cursorState=0,this.refresh(this.y,this.y),this.sendFocus&&this.send("[O"),l.focus=null},l.prototype.initGlobal=function(){var e=this.document;l._boundDocs=l._boundDocs||[];if(~b(l._boundDocs,e))return;l._boundDocs.push(e),l.bindPaste(e),l.bindKeys(e),l.bindCopy(e),this.isIpad&&l.fixIpad(e),this.useStyle&&l.insertStyle(e,this.colors[256],this.colors[257])},l.bindPaste=function(e){var t=e.defaultView;c(t,"paste",function(e){var t=l.focus;if(!t)return;return e.clipboardData?t.send(e.clipboardData.getData("text/plain")):t.context.clipboardData&&t.send(t.context.clipboardData.getData("Text")),t.element.contentEditable="inherit",p(e)})},l.bindKeys=function(e){c(e,"keydown",function(e){if(!l.focus)return;var t=e.target||e.srcElement;if(!t)return;if(t===l.focus.element||t===l.focus.context||t===l.focus.document||t===l.focus.body||t===l._textarea||t===l.focus.parent)return l.focus.keyDown(e)},!0),c(e,"keypress",function(e){if(!l.focus)return;var t=e.target||e.srcElement;if(!t)return;if(t===l.focus.element||t===l.focus.context||t===l.focus.document||t===l.focus.body||t===l._textarea||t===l.focus.parent)return l.focus.keyPress(e)},!0),c(e,"mousedown",function(e){if(!l.focus)return;var t=e.target||e.srcElement;if(!t)return;do if(t===l.focus.element)return;while(t=t.parentNode);l.focus.blur()})},l.bindCopy=function(e){var t=e.defaultView;c(t,"copy",function(e){var t=l.focus;if(!t)return;if(!t._selected)return;var n=t.getCopyTextarea(),r=t.grabText(t._selected.x1,t._selected.x2,t._selected.y1,t._selected.y2);t.emit("copy",r),n.focus(),n.textContent=r,n.value=r,n.setSelectionRange(0,r.length),g(function(){t.element.focus(),t.focus()},1)})},l.fixIpad=function(e){var t=e.createElement("textarea");t.style.position="absolute",t.style.left="-32000px",t.style.top="-32000px",t.style.width="0px",t.style.height="0px",t.style.opacity="0",t.style.backgroundColor="transparent",t.style.borderStyle="none",t.style.outlineStyle="none",t.autocapitalize="none",t.autocorrect="off",e.getElementsByTagName("body")[0].appendChild(t),l._textarea=t,g(function(){t.focus()},1e3)},l.insertStyle=function(e,t,n){var r=e.getElementById("term-style");if(r)return;var i=e.getElementsByTagName("head")[0];if(!i)return;var r=e.createElement("style");r.id="term-style",r.innerHTML=".terminal {\n  float: left;\n  border: "+t+" solid 5px;\n"+'  font-family: "DejaVu Sans Mono", "Liberation Mono", monospace;\n'+"  font-size: 13px;\n"+"  color: "+n+";\n"+"  background: "+t+";\n"+"}\n"+"\n"+".terminal-cursor {\n"+"  color: "+t+";\n"+"  background: "+n+";\n"+"}\n",i.insertBefore(r,i.firstChild)},l.prototype.open=function(e){var t=this,n=0,r;this.parent=e||this.parent;if(!this.parent)throw new Error("Terminal requires a parent element.");this.context=this.parent.ownerDocument.defaultView,this.document=this.parent.ownerDocument,this.body=this.document.getElementsByTagName("body")[0],this.context.navigator&&this.context.navigator.userAgent&&(this.isMac=!!~this.context.navigator.userAgent.indexOf("Mac"),this.isIpad=!!~this.context.navigator.userAgent.indexOf("iPad"),this.isMSIE=!!~this.context.navigator.userAgent.indexOf("MSIE")),this.element=this.document.createElement("div"),this.element.className="terminal",this.element.style.outline="none",this.element.setAttribute("tabindex",0),this.element.style.backgroundColor=this.colors[256],this.element.style.color=this.colors[257],this.children=[];for(;n<this.rows;n++)r=this.document.createElement("div"),this.element.appendChild(r),this.children.push(r);this.parent.appendChild(this.element),this.refresh(0,this.rows-1),this.initGlobal(),this.focus(),this.startBlink(),c(this.element,"focus",function(){t.focus(),t.isIpad&&l._textarea.focus()}),c(this.element,"mousedown",function(){t.focus()}),c(this.element,"mousedown",function(e){var n=e.button!=null?+e.button:e.which!=null?e.which-1:null;t.isMSIE&&(n=n===1?0:n===4?1:n);if(n!==2)return;t.element.contentEditable="true",g(function(){t.element.contentEditable="inherit"},1)},!0),this.bindMouse(),l.brokenBold==null&&(l.brokenBold=v(this.document)),g(function(){t.element.focus()},100)},l.prototype.bindMouse=function(){function i(e){var t,i;t=a(e),i=f(e);if(!i)return;u(t,i);switch(e.type){case"mousedown":n=t;break;case"mouseup":n=32;break;case r:}}function s(e){var t=n,r;r=f(e);if(!r)return;t+=32,u(t,r)}function o(e,n){if(!t.utfMouse){if(n===255)return e.push(0);n>127&&(n=127),e.push(n)}else{if(n===2047)return e.push(0);n<127?e.push(n):(n>2047&&(n=2047),e.push(192|n>>6),e.push(128|n&63))}}function u(e,n){if(t.vt300Mouse){e&=3,n.x-=32,n.y-=32;var r="[24";if(e===0)r+="1";else if(e===1)r+="3";else if(e===2)r+="5";else{if(e===3)return;r+="0"}r+="~["+n.x+","+n.y+"]\r",t.send(r);return}if(t.decLocator){e&=3,n.x-=32,n.y-=32,e===0?e=2:e===1?e=4:e===2?e=6:e===3&&(e=3),t.send("["+e+";"+(e===3?4:0)+";"+n.y+";"+n.x+";"+(n.page||0)+"&w");return}if(t.urxvtMouse){n.x-=32,n.y-=32,n.x++,n.y++,t.send("["+e+";"+n.x+";"+n.y+"M");return}if(t.sgrMouse){n.x-=32,n.y-=32,t.send("[<"+((e&3)===3?e&-4:e)+";"+n.x+";"+n.y+((e&3)===3?"m":"M"));return}var r=[];o(r,e),o(r,n.x),o(r,n.y),t.send("[M"+m.fromCharCode.apply(m,r))}function a(e){var n,r,i,s,o;switch(e.type){case"mousedown":n=e.button!=null?+e.button:e.which!=null?e.which-1:null,t.isMSIE&&(n=n===1?0:n===4?1:n);break;case"mouseup":n=3;break;case"DOMMouseScroll":n=e.detail<0?64:65;break;case"mousewheel":n=e.wheelDeltaY>0?64:65}return r=e.shiftKey?4:0,i=e.metaKey?8:0,s=e.ctrlKey?16:0,o=r|i|s,t.vt200Mouse?o&=s:t.normalMouse||(o=0),n=32+(o<<2)+n,n}function f(e){var n,i,s,o,u;if(e.pageX==null)return;n=e.pageX,i=e.pageY,u=t.element;while(u&&u!==t.document.documentElement)n-=u.offsetLeft,i-=u.offsetTop,u="offsetParent"in u?u.offsetParent:u.parentNode;return s=t.element.clientWidth,o=t.element.clientHeight,n=Math.round(n/s*t.cols),i=Math.round(i/o*t.rows),n<0&&(n=0),n>t.cols&&(n=t.cols),i<0&&(i=0),i>t.rows&&(i=t.rows),n+=32,i+=32,{x:n,y:i,type:e.type===r?"mousewheel":e.type}}var e=this.element,t=this,n=32,r="onmousewheel"in this.context?"mousewheel":"DOMMouseScroll";c(e,"mousedown",function(e){if(!t.mouseEvents)return;return i(e),t.focus(),t.vt200Mouse?(i({__proto__:e,type:"mouseup"}),p(e)):(t.normalMouse&&c(t.document,"mousemove",s),t.x10Mouse||c(t.document,"mouseup",function n(e){return i(e),t.normalMouse&&h(t.document,"mousemove",s),h(t.document,"mouseup",n),p(e)}),p(e))}),c(e,r,function(e){if(!t.mouseEvents)return;if(t.x10Mouse||t.vt300Mouse||t.decLocator)return;return i(e),p(e)}),c(e,r,function(e){if(t.mouseEvents)return;if(t.applicationKeypad)return;var n=e.type==="DOMMouseScroll"?e.detail:-e.wheelDeltaY/160;return n<0?n=Math.floor(n):n=Math.ceil(n),t.scrollDisp(n),p(e)})},l.prototype.destroy=function(){this.readable=!1,this.writable=!1,this._events={},this.handler=function(){},this.write=function(){},this.element.parentNode&&this.element.parentNode.removeChild(this.element)},l.prototype.refresh=function(e,t){var n,r,i,s,o,u,a,f,c,h,p,d,v,m;t-e>=this.rows/2&&(m=this.element.parentNode,m&&m.removeChild(this.element)),a=this.cols,r=e,t>=this.lines.length&&(this.log("`end` is too large. Most likely a bad CSR."),t=this.lines.length-1);for(;r<=t;r++){v=r+this.ydisp,s=this.lines[v],o="",r===this.y&&this.cursorState&&(this.ydisp===this.ybase||this.selectMode)&&!this.cursorHidden?n=this.x:n=-1,c=this.defAttr,i=0;for(;i<a;i++){f=s[i][0],u=s[i][1],i===n&&(f=-1),f!==c&&(c!==this.defAttr&&(o+="</span>"),f!==this.defAttr&&(f===-1?o+='<span class="reverse-video terminal-cursor">':(o+='<span style="',h=f&511,p=f>>9&511,d=f>>18,d&1&&(l.brokenBold||(o+="font-weight:bold;"),p<8&&(p+=8)),d&2&&(o+="text-decoration:underline;"),d&4&&(d&2?(o=o.slice(0,-1),o+=" blink;"):o+="text-decoration:blink;"),d&8&&(h=f>>9&511,p=f&511,d&1&&p<8&&(p+=8)),d&16&&(o+="visibility:hidden;"),h!==256&&(o+="background-color:"+this.colors[h]+";"),p!==257&&(o+="color:"+this.colors[p]+";"),o+='">')));switch(u){case"&":o+="&amp;";break;case"<":o+="&lt;";break;case">":o+="&gt;";break;default:u<=" "?o+="&nbsp;":(w(u)&&i++,o+=u)}c=f}c!==this.defAttr&&(o+="</span>"),this.children[r].innerHTML=o}m&&m.appendChild(this.element)},l.prototype._cursorBlink=function(){if(l.focus!==this)return;this.cursorState^=1,this.refresh(this.y,this.y)},l.prototype.showCursor=function(){this.cursorState||(this.cursorState=1,this.refresh(this.y,this.y))},l.prototype.startBlink=function(){if(!this.cursorBlink)return;var e=this;this._blinker=function(){e._cursorBlink()},this._blink=y(this._blinker,500)},l.prototype.refreshBlink=function(){if(!this.cursorBlink)return;clearInterval(this._blink),this._blink=y(this._blinker,500)},l.prototype.scroll=function(){var e;++this.ybase===this.scrollback&&(this.ybase=this.ybase/2|0,this.lines=this.lines.slice(-(this.ybase+this.rows)+1)),this.ydisp=this.ybase,e=this.ybase+this.rows-1,e-=this.rows-1-this.scrollBottom,e===this.lines.length?this.lines.push(this.blankLine()):this.lines.splice(e,0,this.blankLine()),this.scrollTop!==0&&(this.ybase!==0&&(this.ybase--,this.ydisp=this.ybase),this.lines.splice(this.ybase+this.scrollTop,1)),this.updateRange(this.scrollTop),this.updateRange(this.scrollBottom)},l.prototype.scrollDisp=function(e){this.ydisp+=e,this.ydisp>this.ybase?this.ydisp=this.ybase:this.ydisp<0&&(this.ydisp=0),this.refresh(0,this.rows-1)},l.prototype.write=function(e){var t=e.length,n=0,c,h,p;this.refreshStart=this.y,this.refreshEnd=this.y,this.ybase!==this.ydisp&&(this.ydisp=this.ybase,this.maxRange());for(;n<t;n++){p=e[n];switch(this.state){case r:switch(p){case"":this.bell();break;case"\n":case"":case"\f":this.convertEol&&(this.x=0),this.y++,this.y>this.scrollBottom&&(this.y--,this.scroll());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=i;break;default:if(p>=" "){this.charset&&this.charset[p]&&(p=this.charset[p]),this.x>=this.cols&&(this.x=0,this.y++,this.y>this.scrollBottom&&(this.y--,this.scroll())),this.lines[this.y+this.ybase][this.x]=[this.curAttr,p],this.x++,this.updateRange(this.y);if(w(p)){c=this.y+this.ybase;if(this.cols<2||this.x>=this.cols){this.lines[c][this.x-1]=[this.curAttr," "];break}this.lines[c][this.x]=[this.curAttr," "],this.x++}}}break;case i:switch(p){case"[":this.params=[],this.currentParam=0,this.state=s;break;case"]":this.params=[],this.currentParam=0,this.state=o;break;case"P":this.params=[],this.currentParam=0,this.state=a;break;case"_":this.state=f;break;case"^":this.state=f;break;case"c":this.reset();break;case"E":this.x=0;case"D":this.index();break;case"M":this.reverseIndex();break;case"%":this.setgLevel(0),this.setgCharset(0,l.charsets.US),this.state=r,n++;break;case"(":case")":case"*":case"+":case"-":case".":switch(p){case"(":this.gcharset=0;break;case")":this.gcharset=1;break;case"*":this.gcharset=2;break;case"+":this.gcharset=3;break;case"-":this.gcharset=1;break;case".":this.gcharset=2}this.state=u;break;case"/":this.gcharset=3,this.state=u,n--;break;case"N":break;case"O":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=r;break;case"8":this.restoreCursor(),this.state=r;break;case"#":this.state=r,n++;break;case"H":this.tabSet();break;case"=":this.log("Serial port requested application keypad."),this.applicationKeypad=!0,this.state=r;break;case">":this.log("Switching back to normal keypad."),this.applicationKeypad=!1,this.state=r;break;default:this.state=r,this.error("Unknown ESC control: %s.",p)}break;case u:switch(p){case"0":h=l.charsets.SCLD;break;case"A":h=l.charsets.UK;break;case"B":h=l.charsets.US;break;case"4":h=l.charsets.Dutch;break;case"C":case"5":h=l.charsets.Finnish;break;case"R":h=l.charsets.French;break;case"Q":h=l.charsets.FrenchCanadian;break;case"K":h=l.charsets.German;break;case"Y":h=l.charsets.Italian;break;case"E":case"6":h=l.charsets.NorwegianDanish;break;case"Z":h=l.charsets.Spanish;break;case"H":case"7":h=l.charsets.Swedish;break;case"=":h=l.charsets.Swiss;break;case"/":h=l.charsets.ISOLatin,n++;break;default:h=l.charsets.US}this.setgCharset(this.gcharset,h),this.gcharset=null,this.state=r;break;case o:if(p===""||p===""){p===""&&n++,this.params.push(this.currentParam);switch(this.params[0]){case 0:case 1:case 2:this.params[1]&&(this.title=this.params[1],this.handleTitle(this.title));break;case 3:break;case 4:case 5:break;case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:case 19:break;case 46:break;case 50:break;case 51:break;case 52:break;case 104:case 105:case 110:case 111:case 112:case 113:case 114:case 115:case 116:case 117:case 118:}this.params=[],this.currentParam=0,this.state=r}else this.params.length?this.currentParam+=p:p>="0"&&p<="9"?this.currentParam=this.currentParam*10+p.charCodeAt(0)-48:p===";"&&(this.params.push(this.currentParam),this.currentParam="");break;case s:if(p==="?"||p===">"||p==="!"){this.prefix=p;break}if(p>="0"&&p<="9"){this.currentParam=this.currentParam*10+p.charCodeAt(0)-48;break}if(p==="$"||p==='"'||p===" "||p==="'"){this.postfix=p;break}this.params.push(this.currentParam),this.currentParam=0;if(p===";")break;this.state=r;switch(p){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":switch(this.prefix){case"!":this.softReset(this.params)}break;default:this.error("Unknown CSI code: %s.",p)}this.prefix="",this.postfix="";break;case a:if(p===""||p===""){p===""&&n++;switch(this.prefix){case"":break;case"$q":var d=this.currentParam,v=!1;switch(d){case'"q':d='0"q';break;case'"p':d='61"p';break;case"r":d=""+(this.scrollTop+1)+";"+(this.scrollBottom+1)+"r";break;case"m":d="0m";break;default:this.error("Unknown DCS Pt: %s.",d),d=""}this.send("P"+ +v+"$r"+d+"\\");break;case"+p":break;case"+q":var d=this.currentParam,v=!1;this.send("P"+ +v+"+r"+d+"\\");break;default:this.error("Unknown DCS prefix: %s.",this.prefix)}this.currentParam=0,this.prefix="",this.state=r}else this.currentParam?this.currentParam+=p:!this.prefix&&p!=="$"&&p!=="+"?this.currentParam=p:this.prefix.length===2?this.currentParam=p:this.prefix+=p;break;case f:if(p===""||p==="")p===""&&n++,this.state=r}}this.updateRange(this.y),this.refresh(this.refreshStart,this.refreshEnd)},l.prototype.writeln=function(e){this.write(e+"\r\n")},l.prototype.keyDown=function(e){var t=this,n;switch(e.keyCode){case 8:if(e.shiftKey){n="\b";break}if(e.altKey){n="";break}n="";break;case 9:if(e.shiftKey){n="[Z";break}n="	";break;case 13:n="\r";break;case 27:n="";break;case 37:if(this.applicationCursor){n="OD";break}if(e.altKey){n="b";break}n="[D";break;case 39:if(this.applicationCursor){n="OC";break}if(e.altKey){n="f";break}n="[C";break;case 38:if(this.applicationCursor){n="OA";break}if(e.ctrlKey)return this.scrollDisp(-1),p(e);n="[A";break;case 40:if(this.applicationCursor){n="OB";break}if(e.ctrlKey)return this.scrollDisp(1),p(e);n="[B";break;case 46:n="[3~";break;case 45:n="[2~";break;case 36:if(this.applicationKeypad){n="OH";break}n="OH";break;case 35:if(this.applicationKeypad){n="OF";break}n="OF";break;case 33:if(e.shiftKey)return this.scrollDisp(-(this.rows-1)),p(e);n="[5~";break;case 34:if(e.shiftKey)return this.scrollDisp(this.rows-1),p(e);n="[6~";break;case 112:n="OP";break;case 113:n="OQ";break;case 114:n="OR";break;case 115:n="OS";break;case 116:n="[15~";break;case 117:n="[17~";break;case 118:n="[18~";break;case 119:n="[19~";break;case 120:n="[20~";break;case 121:n="[21~";break;case 122:n="[23~";break;case 123:n="[24~";break;default:if(e.ctrlKey)if(e.keyCode>=65&&e.keyCode<=90){if(this.screenKeys&&!this.prefixMode&&!this.selectMode&&e.keyCode===65)return this.enterPrefix(),p(e);if(e.keyCode===86&&this.prefixMode)return this.leavePrefix(),!0;if(e.keyCode===67&&(this.prefixMode||this.selectMode)&&this.visualMode)return g(function(){t.leaveVisual()},1),!0;if(e.keyCode===86&&e.shiftKey)return!0;if(e.keyCode===67&&e.shiftKey)return!0;n=m.fromCharCode(e.keyCode-64)}else e.keyCode===32?n=m.fromCharCode(0):e.keyCode>=51&&e.keyCode<=55?n=m.fromCharCode(e.keyCode-51+27):e.keyCode===56?n=m.fromCharCode(127):e.keyCode===219?n=m.fromCharCode(27):e.keyCode===221&&(n=m.fromCharCode(29));else if(!this.isMac&&e.altKey||this.isMac&&e.metaKey){if(e.keyCode===86||e.keyCode===67)return!0;e.keyCode>=65&&e.keyCode<=90?n=""+m.fromCharCode(e.keyCode+32):e.keyCode===192?n="`":e.keyCode>=48&&e.keyCode<=57&&(n=""+(e.keyCode-48))}else this.isMac&&e.altKey&&e.keyCode==220&&(e.keyIdentifier=="U+004C"?n="|":e.keyIdentifier=="U+002F"&&(n="\\"))}return n?this.prefixMode?(this.leavePrefix(),p(e)):this.selectMode?(this.keySelect(e,n),p(e)):(this.emit("keydown",e),this.emit("key",n,e),this.showCursor(),this.handler(n),p(e)):!0},l.prototype.setgLevel=function(e){this.glevel=e,this.charset=this.charsets[e]},l.prototype.setgCharset=function(e,t){this.charsets[e]=t,this.glevel===e&&(this.charset=t)},l.prototype.keyPress=function(e){var t;p(e);if(e.charCode)t=e.charCode;else if(e.which==null)t=e.keyCode;else{if(e.which===0||e.charCode===0)return!1;t=e.which}return!t||e.ctrlKey||e.altKey||e.metaKey?!1:(t=m.fromCharCode(t),this.prefixMode?(this.leavePrefix(),this.keyPrefix(e,t),!1):this.selectMode?(this.keySelect(e,t),!1):(this.emit("keypress",t,e),this.emit("key",t,e),this.showCursor(),this.handler(t),!1))},l.prototype.send=function(e){var t=this;this.queue||g(function(){t.handler(t.queue),t.queue=""},1),this.queue+=e},l.prototype.bell=function(){if(!this.visualBell)return;var e=this;this.element.style.borderColor="white",g(function(){e.element.style.borderColor=""},10),this.popOnBell&&this.focus()},l.prototype.log=function(){if(!this.debug)return;if(!this.context.console||!this.context.console.log)return;var e=Array.prototype.slice.call(arguments);this.context.console.log.apply(this.context.console,e)},l.prototype.error=function(){if(!this.debug)return;if(!this.context.console||!this.context.console.error)return;var e=Array.prototype.slice.call(arguments);this.context.console.error.apply(this.context.console,e)},l.prototype.resize=function(e,t){var n,r,i,s,o;e<1&&(e=1),t<1&&(t=1),s=this.cols;if(s<e){o=[this.defAttr," "],i=this.lines.length;while(i--)while(this.lines[i].length<e)this.lines[i].push(o)}else if(s>e){i=this.lines.length;while(i--)while(this.lines[i].length>e)this.lines[i].pop()}this.setupStops(s),this.cols=e,s=this.rows;if(s<t){r=this.element;while(s++<t)this.lines.length<t+this.ybase&&this.lines.push(this.blankLine()),this.children.length<t&&(n=this.document.createElement("div"),r.appendChild(n),this.children.push(n))}else if(s>t)while(s-->t){this.lines.length>t+this.ybase&&this.lines.pop();if(this.children.length>t){r=this.children.pop();if(!r)continue;r.parentNode.removeChild(r)}}this.rows=t,this.y>=t&&(this.y=t-1),this.x>=e&&(this.x=e-1),this.scrollTop=0,this.scrollBottom=t-1,this.refresh(0,this.rows-1),this.normal=null},l.prototype.updateRange=function(e){e<this.refreshStart&&(this.refreshStart=e),e>this.refreshEnd&&(this.refreshEnd=e)},l.prototype.maxRange=function(){this.refreshStart=0,this.refreshEnd=this.rows-1},l.prototype.setupStops=function(e){e!=null?this.tabs[e]||(e=this.prevStop(e)):(this.tabs={},e=0);for(;e<this.cols;e+=8)this.tabs[e]=!0},l.prototype.prevStop=function(e){e==null&&(e=this.x);while(!this.tabs[--e]&&e>0);return e>=this.cols?this.cols-1:e<0?0:e},l.prototype.nextStop=function(e){e==null&&(e=this.x);while(!this.tabs[++e]&&e<this.cols);return e>=this.cols?this.cols-1:e<0?0:e},l.prototype.eraseRight=function(e,t){var n=this.lines[this.ybase+t],r=[this.eraseAttr()," "];for(;e<this.cols;e++)n[e]=r;this.updateRange(t)},l.prototype.eraseLeft=function(e,t){var n=this.lines[this.ybase+t],r=[this.eraseAttr()," "];e++;while(e--)n[e]=r;this.updateRange(t)},l.prototype.eraseLine=function(e){this.eraseRight(0,e)},l.prototype.blankLine=function(e){var t=e?this.eraseAttr():this.defAttr,n=[t," "],r=[],i=0;for(;i<this.cols;i++)r[i]=n;return r},l.prototype.ch=function(e){return e?[this.eraseAttr()," "]:[this.defAttr," "]},l.prototype.is=function(e){var t=this.termName;return(t+"").indexOf(e)===0},l.prototype.handler=function(e){this.emit("data",e)},l.prototype.handleTitle=function(e){this.emit("title",e)},l.prototype.index=function(){this.y++,this.y>this.scrollBottom&&(this.y--,this.scroll()),this.state=r},l.prototype.reverseIndex=function(){var e;this.y--,this.y<this.scrollTop&&(this.y++,this.lines.splice(this.y+this.ybase,0,this.blankLine(!0)),e=this.rows-1-this.scrollBottom,this.lines.splice(this.rows-1+this.ybase-e+1,1),this.updateRange(this.scrollTop),this.updateRange(this.scrollBottom)),this.state=r},l.prototype.reset=function(){this.options.rows=this.rows,this.options.cols=this.cols,l.call(this,this.options),this.refresh(0,this.rows-1)},l.prototype.tabSet=function(){this.tabs[this.x]=!0,this.state=r},l.prototype.cursorUp=function(e){var t=e[0];t<1&&(t=1),this.y-=t,this.y<0&&(this.y=0)},l.prototype.cursorDown=function(e){var t=e[0];t<1&&(t=1),this.y+=t,this.y>=this.rows&&(this.y=this.rows-1)},l.prototype.cursorForward=function(e){var t=e[0];t<1&&(t=1),this.x+=t,this.x>=this.cols&&(this.x=this.cols-1)},l.prototype.cursorBackward=function(e){var t=e[0];t<1&&(t=1),this.x-=t,this.x<0&&(this.x=0)},l.prototype.cursorPos=function(e){var t,n;t=e[0]-1,e.length>=2?n=e[1]-1:n=0,t<0?t=0:t>=this.rows&&(t=this.rows-1),n<0?n=0:n>=this.cols&&(n=this.cols-1),this.x=n,this.y=t},l.prototype.eraseInDisplay=function(e){var t;switch(e[0]){case 0:this.eraseRight(this.x,this.y),t=this.y+1;for(;t<this.rows;t++)this.eraseLine(t);break;case 1:this.eraseLeft(this.x,this.y),t=this.y;while(t--)this.eraseLine(t);break;case 2:t=this.rows;while(t--)this.eraseLine(t);break;case 3:}},l.prototype.eraseInLine=function(e){switch(e[0]){case 0:this.eraseRight(this.x,this.y);break;case 1:this.eraseLeft(this.x,this.y);break;case 2:this.eraseLine(this.y)}},l.prototype.charAttributes=function(e){if(e.length===1&&e[0]===0){this.curAttr=this.defAttr;return}var t=e.length,n=0,r=this.curAttr>>18,i=this.curAttr>>9&511,s=this.curAttr&511,o;for(;n<t;n++)o=e[n],o>=30&&o<=37?i=o-30:o>=40&&o<=47?s=o-40:o>=90&&o<=97?(o+=8,i=o-90):o>=100&&o<=107?(o+=8,s=o-100):o===0?(r=this.defAttr>>18,i=this.defAttr>>9&511,s=this.defAttr&511):o===1?r|=1:o===4?r|=2:o===5?r|=4:o===7?r|=8:o===8?r|=16:o===22?r&=-2:o===24?r&=-3:o===25?r&=-5:o===27?r&=-9:o===28?r&=-17:o===39?i=this.defAttr>>9&511:o===49?s=this.defAttr&511:o===38?e[n+1]===2?(n+=2,i=E(e[n]&255,e[n+1]&255,e[n+2]&255),i===-1&&(i=511),n+=2):e[n+1]===5&&(n+=2,o=e[n]&255,i=o):o===48?e[n+1]===2?(n+=2,s=E(e[n]&255,e[n+1]&255,e[n+2]&255),s===-1&&(s=511),n+=2):e[n+1]===5&&(n+=2,o=e[n]&255,s=o):o===100?(i=this.defAttr>>9&511,s=this.defAttr&511):this.error("Unknown SGR attribute: %d.",o);this.curAttr=r<<18|i<<9|s},l.prototype.deviceStatus=function(e){if(!this.prefix)switch(e[0]){case 5:this.send("[0n");break;case 6:this.send("["+(this.y+1)+";"+(this.x+1)+"R")}else if(this.prefix==="?")switch(e[0]){case 6:this.send("[?"+(this.y+1)+";"+(this.x+1)+"R");break;case 15:break;case 25:break;case 26:break;case 53:}},l.prototype.insertChars=function(e){var t,n,r,i;t=e[0],t<1&&(t=1),n=this.y+this.ybase,r=this.x,i=[this.eraseAttr()," "];while(t--&&r<this.cols)this.lines[n].splice(r++,0,i),this.lines[n].pop()},l.prototype.cursorNextLine=function(e){var t=e[0];t<1&&(t=1),this.y+=t,this.y>=this.rows&&(this.y=this.rows-1),this.x=0},l.prototype.cursorPrecedingLine=function(e){var t=e[0];t<1&&(t=1),this.y-=t,this.y<0&&(this.y=0),this.x=0},l.prototype.cursorCharAbsolute=function(e){var t=e[0];t<1&&(t=1),this.x=t-1},l.prototype.insertLines=function(e){var t,n,r;t=e[0],t<1&&(t=1),n=this.y+this.ybase,r=this.rows-1-this.scrollBottom,r=this.rows-1+this.ybase-r+1;while(t--)this.lines.splice(n,0,this.blankLine(!0)),this.lines.splice(r,1);this.updateRange(this.y),this.updateRange(this.scrollBottom)},l.prototype.deleteLines=function(e){var t,n,r;t=e[0],t<1&&(t=1),n=this.y+this.ybase,r=this.rows-1-this.scrollBottom,r=this.rows-1+this.ybase-r;while(t--)this.lines.splice(r+1,0,this.blankLine(!0)),this.lines.splice(n,1);this.updateRange(this.y),this.updateRange(this.scrollBottom)},l.prototype.deleteChars=function(e){var t,n,r;t=e[0],t<1&&(t=1),n=this.y+this.ybase,r=[this.eraseAttr()," "];while(t--)this.lines[n].splice(this.x,1),this.lines[n].push(r)},l.prototype.eraseChars=function(e){var t,n,r,i;t=e[0],t<1&&(t=1),n=this.y+this.ybase,r=this.x,i=[this.eraseAttr()," "];while(t--&&r<this.cols)this.lines[n][r++]=i},l.prototype.charPosAbsolute=function(e){var t=e[0];t<1&&(t=1),this.x=t-1,this.x>=this.cols&&(this.x=this.cols-1)},l.prototype.HPositionRelative=function(e){var t=e[0];t<1&&(t=1),this.x+=t,this.x>=this.cols&&(this.x=this.cols-1)},l.prototype.sendDeviceAttributes=function(e){if(e[0]>0)return;this.prefix?this.prefix===">"&&(this.is("xterm")?this.send("[>0;276;0c"):this.is("rxvt-unicode")?this.send("[>85;95;0c"):this.is("linux")?this.send(e[0]+"c"):this.is("screen")&&this.send("[>83;40003;0c")):this.is("xterm")||this.is("rxvt-unicode")||this.is("screen")?this.send("[?1;2c"):this.is("linux")&&this.send("[?6c")},l.prototype.linePosAbsolute=function(e){var t=e[0];t<1&&(t=1),this.y=t-1,this.y>=this.rows&&(this.y=this.rows-1)},l.prototype.VPositionRelative=function(e){var t=e[0];t<1&&(t=1),this.y+=t,this.y>=this.rows&&(this.y=this.rows-1)},l.prototype.HVPosition=function(e){e[0]<1&&(e[0]=1),e[1]<1&&(e[1]=1),this.y=e[0]-1,this.y>=this.rows&&(this.y=this.rows-1),this.x=e[1]-1,this.x>=this.cols&&(this.x=this.cols-1)},l.prototype.setMode=function(e){if(typeof e=="object"){var t=e.length,n=0;for(;n<t;n++)this.setMode(e[n]);return}if(!this.prefix)switch(e){case 4:this.insertMode=!0;break;case 20:}else if(this.prefix==="?")switch(e){case 1:this.applicationCursor=!0;break;case 2:this.setgCharset(0,l.charsets.US),this.setgCharset(1,l.charsets.US),this.setgCharset(2,l.charsets.US),this.setgCharset(3,l.charsets.US);break;case 3:this.savedCols=this.cols,this.resize(132,this.rows);break;case 6:this.originMode=!0;break;case 7:this.wraparoundMode=!0;break;case 12:break;case 66:this.log("Serial port requested application keypad."),this.applicationKeypad=!0;break;case 9:case 1e3:case 1002:case 1003:this.x10Mouse=e===9,this.vt200Mouse=e===1e3,this.normalMouse=e>1e3,this.mouseEvents=!0,this.element.style.cursor="default",this.log("Binding to mouse events.");break;case 1004:this.sendFocus=!0;break;case 1005:this.utfMouse=!0;break;case 1006:this.sgrMouse=!0;break;case 1015:this.urxvtMouse=!0;break;case 25:this.cursorHidden=!1;break;case 1049:case 47:case 1047:if(!this.normal){var r={lines:this.lines,ybase:this.ybase,ydisp:this.ydisp,x:this.x,y:this.y,scrollTop:this.scrollTop,scrollBottom:this.scrollBottom,tabs:this.tabs};this.reset(),this.normal=r,this.showCursor()}}},l.prototype.resetMode=function(e){if(typeof e=="object"){var t=e.length,n=0;for(;n<t;n++)this.resetMode(e[n]);return}if(!this.prefix)switch(e){case 4:this.insertMode=!1;break;case 20:}else if(this.prefix==="?")switch(e){case 1:this.applicationCursor=!1;break;case 3:this.cols===132&&this.savedCols&&this.resize(this.savedCols,this.rows),delete this.savedCols;break;case 6:this.originMode=!1;break;case 7:this.wraparoundMode=!1;break;case 12:break;case 66:this.log("Switching back to normal keypad."),this.applicationKeypad=!1;break;case 9:case 1e3:case 1002:case 1003:this.x10Mouse=!1,this.vt200Mouse=!1,this.normalMouse=!1,this.mouseEvents=!1,this.element.style.cursor="";break;case 1004:this.sendFocus=!1;break;case 1005:this.utfMouse=!1;break;case 1006:this.sgrMouse=!1;break;case 1015:this.urxvtMouse=!1;break;case 25:this.cursorHidden=!0;break;case 1049:case 47:case 1047:this.normal&&(this.lines=this.normal.lines,this.ybase=this.normal.ybase,this.ydisp=this.normal.ydisp,this.x=this.normal.x,this.y=this.normal.y,this.scrollTop=this.normal.scrollTop,this.scrollBottom=this.normal.scrollBottom,this.tabs=this.normal.tabs,this.normal=null,this.refresh(0,this.rows-1),this.showCursor())}},l.prototype.setScrollRegion=function(e){if(this.prefix)return;this.scrollTop=(e[0]||1)-1,this.scrollBottom=(e[1]||this.rows)-1,this.x=0,this.y=0},l.prototype.saveCursor=function(e){this.savedX=this.x,this.savedY=this.y},l.prototype.restoreCursor=function(e){this.x=this.savedX||0,this.y=this.savedY||0},l.prototype.cursorForwardTab=function(e){var t=e[0]||1;while(t--)this.x=this.nextStop()},l.prototype.scrollUp=function(e){var t=e[0]||1;while(t--)this.lines.splice(this.ybase+this.scrollTop,1),this.lines.splice(this.ybase+this.scrollBottom,0,this.blankLine());this.updateRange(this.scrollTop),this.updateRange(this.scrollBottom)},l.prototype.scrollDown=function(e){var t=e[0]||1;while(t--)this.lines.splice(this.ybase+this.scrollBottom,1),this.lines.splice(this.ybase+this.scrollTop,0,this.blankLine());this.updateRange(this.scrollTop),this.updateRange(this.scrollBottom)},l.prototype.initMouseTracking=function(e){},l.prototype.resetTitleModes=function(e){},l.prototype.cursorBackwardTab=function(e){var t=e[0]||1;while(t--)this.x=this.prevStop()},l.prototype.repeatPrecedingCharacter=function(e){var t=e[0]||1,n=this.lines[this.ybase+this.y],r=n[this.x-1]||[this.defAttr," "];while(t--)n[this.x++]=r},l.prototype.tabClear=function(e){var t=e[0];t<=0?delete this.tabs[this.x]:t===3&&(this.tabs={})},l.prototype.mediaCopy=function(e){},l.prototype.setResources=function(e){},l.prototype.disableModifiers=function(e){},l.prototype.setPointerMode=function(e){},l.prototype.softReset=function(e){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]},l.prototype.requestAnsiMode=function(e){},l.prototype.requestPrivateMode=function(e){},l.prototype.setConformanceLevel=function(e){},l.prototype.loadLEDs=function(e){},l.prototype.setCursorStyle=function(e){},l.prototype.setCharProtectionAttr=function(e){},l.prototype.restorePrivateValues=function(e){},l.prototype.setAttrInRectangle=function(e){var t=e[0],n=e[1],r=e[2],i=e[3],s=e[4],o,u;for(;t<r+1;t++){o=this.lines[this.ybase+t];for(u=n;u<i;u++)o[u]=[s,o[u][1]]}this.updateRange(e[0]),this.updateRange(e[2])},l.prototype.savePrivateValues=function(e){},l.prototype.manipulateWindow=function(e){},l.prototype.reverseAttrInRectangle=function(e){},l.prototype.setTitleModeFeature=function(e){},l.prototype.setWarningBellVolume=function(e){},l.prototype.setMarginBellVolume=function(e){},l.prototype.copyRectangle=function(e){},l.prototype.enableFilterRectangle=function(e){},l.prototype.requestParameters=function(e){},l.prototype.selectChangeExtent=function(e){},l.prototype.fillRectangle=function(e){var t=e[0],n=e[1],r=e[2],i=e[3],s=e[4],o,u;for(;n<i+1;n++){o=this.lines[this.ybase+n];for(u=r;u<s;u++)o[u]=[o[u][0],m.fromCharCode(t)]}this.updateRange(e[1]),this.updateRange(e[3])},l.prototype.enableLocatorReporting=function(e){var t=e[0]>0},l.prototype.eraseRectangle=function(e){var t=e[0],n=e[1],r=e[2],i=e[3],s,o,u;u=[this.eraseAttr()," "];for(;t<r+1;t++){s=this.lines[this.ybase+t];for(o=n;o<i;o++)s[o]=u}this.updateRange(e[0]),this.updateRange(e[2])},l.prototype.setLocatorEvents=function(e){},l.prototype.selectiveEraseRectangle=function(e){},l.prototype.requestLocatorPosition=function(e){},l.prototype.insertColumns=function(){var e=params[0],t=this.ybase+this.rows,n=[this.eraseAttr()," "],r;while(e--)for(r=this.ybase;r<t;r++)this.lines[r].splice(this.x+1,0,n),this.lines[r].pop();this.maxRange()},l.prototype.deleteColumns=function(){var e=params[0],t=this.ybase+this.rows,n=[this.eraseAttr()," "],r;while(e--)for(r=this.ybase;r<t;r++)this.lines[r].splice(this.x,1),this.lines[r].push(n);this.maxRange()},l.prototype.enterPrefix=function(){this.prefixMode=!0},l.prototype.leavePrefix=function(){this.prefixMode=!1},l.prototype.enterSelect=function(){this._real={x:this.x,y:this.y,ydisp:this.ydisp,ybase:this.ybase,cursorHidden:this.cursorHidden,lines:this.copyBuffer(this.lines),write:this.write},this.write=function(){},this.selectMode=!0,this.visualMode=!1,this.cursorHidden=!1,this.refresh(this.y,this.y)},l.prototype.leaveSelect=function(){this.x=this._real.x,this.y=this._real.y,this.ydisp=this._real.ydisp,this.ybase=this._real.ybase,this.cursorHidden=this._real.cursorHidden,this.lines=this._real.lines,this.write=this._real.write,delete this._real,this.selectMode=!1,this.visualMode=!1,this.refresh(0,this.rows-1)},l.prototype.enterVisual=function(){this._real.preVisual=this.copyBuffer(this.lines),this.selectText(this.x,this.x,this.ydisp+this.y,this.ydisp+this.y),this.visualMode=!0},l.prototype.leaveVisual=function(){this.lines=this._real.preVisual,delete this._real.preVisual,delete this._selected,this.visualMode=!1,this.refresh(0,this.rows-1)},l.prototype.enterSearch=function(e){this.entry="",this.searchMode=!0,this.searchDown=e,this._real.preSearch=this.copyBuffer(this.lines),this._real.preSearchX=this.x,this._real.preSearchY=this.y,this.entryPrefix="Search: ";var t=this.ydisp+this.rows-1;for(var n=0;n<this.entryPrefix.length;n++)this.lines[t][n]=[this.defAttr&-512|4,this.entryPrefix[n]];this.y=this.rows-1,this.x=this.entryPrefix.length,this.refresh(this.rows-1,this.rows-1)},l.prototype.leaveSearch=function(){this.searchMode=!1,this._real.preSearch&&(this.lines=this._real.preSearch,this.x=this._real.preSearchX,this.y=this._real.preSearchY,delete this._real.preSearch,delete this._real.preSearchX,delete this._real.preSearchY),this.refresh(this.rows-1,this.rows-1)},l.prototype.copyBuffer=function(e){var e=e||this.lines,t=[];for(var n=0;n<e.length;n++){t[n]=[];for(var r=0;r<e[n].length;r++)t[n][r]=[e[n][r][0],e[n][r][1]]}return t},l.prototype.getCopyTextarea=function(e){var t=this._copyTextarea,n=this.document;return t||(t=n.createElement("textarea"),t.style.position="absolute",t.style.left="-32000px",t.style.top="-32000px",t.style.width="0px",t.style.height="0px",t.style.opacity="0",t.style.backgroundColor="transparent",t.style.borderStyle="none",t.style.outlineStyle="none",n.getElementsByTagName("body")[0].appendChild(t),this._copyTextarea=t),t},l.prototype.copyText=function(e){var t=this,n=this.getCopyTextarea();this.emit("copy",e),n.focus(),n.textContent=e,n.value=e,n.setSelectionRange(0,e.length),g(function(){t.element.focus(),t.focus()},1)},l.prototype.selectText=function(e,t,n,r){var i,s,o,u,a,f,l,c,h;if(this._selected){i=this._selected.x1,s=this._selected.x2,o=this._selected.y1,u=this._selected.y2,u<o&&(a=s,s=i,i=a,a=u,u=o,o=a),s<i&&o===u&&(a=s,s=i,i=a);for(l=o;l<=u;l++){f=0,c=this.cols-1,l===o&&(f=i),l===u&&(c=s);for(;f<=c;f++)this.lines[l][f].old!=null&&(h=this.lines[l][f].old,delete this.lines[l][f].old,this.lines[l][f]=[h,this.lines[l][f][1]])}n=this._selected.y1,e=this._selected.x1}n=Math.max(n,0),n=Math.min(n,this.ydisp+this.rows-1),r=Math.max(r,0),r=Math.min(r,this.ydisp+this.rows-1),this._selected={x1:e,x2:t,y1:n,y2:r},r<n&&(a=t,t=e,e=a,a=r,r=n,n=a),t<e&&n===r&&(a=t,t=e,e=a);for(l=n;l<=r;l++){f=0,c=this.cols-1,l===n&&(f=e),l===r&&(c=t);for(;f<=c;f++)h=this.lines[l][f][0],this.lines[l][f]=[h&-512|261636,this.lines[l][f][1]],this.lines[l][f].old=h}n-=this.ydisp,r-=this.ydisp,n=Math.max(n,0),n=Math.min(n,this.rows-1),r=Math.max(r,0),r=Math.min(r,this.rows-1),this.refresh(0,this.rows-1)},l.prototype.grabText=function(e,t,n,r){var i="",s="",o,u,a,f,l;r<n&&(l=t,t=e,e=l,l=r,r=n,n=l),t<e&&n===r&&(l=t,t=e,e=l);for(a=n;a<=r;a++){u=0,f=this.cols-1,a===n&&(u=e),a===r&&(f=t);for(;u<=f;u++){o=this.lines[a][u][1];if(o===" "){s+=o;continue}s&&(i+=s,s=""),i+=o,w(o)&&u++}s="",i+="\n"}for(u=t,a=r;u<this.cols;u++)if(this.lines[a][u][1]!==" "){i=i.slice(0,-1);break}return i},l.prototype.keyPrefix=function(e,t){t==="k"||t==="&"?this.destroy():t==="p"||t==="]"?this.emit("request paste"):t==="c"?this.emit("request create"):t>="0"&&t<="9"?(t=+t-1,~t||(t=9),this.emit("request term",t)):t==="n"?this.emit("request term next"):t==="P"?this.emit("request term previous"):t===":"?this.emit("request command mode"):t==="["&&this.enterSelect()},l.prototype.keySelect=function(e,t){this.showCursor();if(this.searchMode||t==="n"||t==="N")return this.keySearch(e,t);if(t===""){var n=this.ydisp+this.y;this.ydisp===this.ybase?(this.y=Math.min(this.y+(this.rows-1)/2|0,this.rows-1),this.refresh(0,this.rows-1)):this.scrollDisp((this.rows-1)/2|0),this.visualMode&&this.selectText(this.x,this.x,n,this.ydisp+this.y);return}if(t===""){var n=this.ydisp+this.y;this.ydisp===0?(this.y=Math.max(this.y-(this.rows-1)/2|0,0),this.refresh(0,this.rows-1)):this.scrollDisp(-(this.rows-1)/2|0),this.visualMode&&this.selectText(this.x,this.x,n,this.ydisp+this.y);return}if(t===""){var n=this.ydisp+this.y;this.scrollDisp(this.rows-1),this.visualMode&&this.selectText(this.x,this.x,n,this.ydisp+this.y);return}if(t===""){var n=this.ydisp+this.y;this.scrollDisp(-(this.rows-1)),this.visualMode&&this.selectText(this.x,this.x,n,this.ydisp+this.y);return}if(t==="k"||t==="[A"){var n=this.ydisp+this.y;this.y--,this.y<0&&(this.y=0,this.scrollDisp(-1)),this.visualMode?this.selectText(this.x,this.x,n,this.ydisp+this.y):this.refresh(this.y,this.y+1);return}if(t==="j"||t==="[B"){var n=this.ydisp+this.y;this.y++,this.y>=this.rows&&(this.y=this.rows-1,this.scrollDisp(1)),this.visualMode?this.selectText(this.x,this.x,n,this.ydisp+this.y):this.refresh(this.y-1,this.y);return}if(t==="h"||t==="[D"){var r=this.x;this.x--,this.x<0&&(this.x=0),this.visualMode?this.selectText(this.x,r,this.ydisp+this.y,this.ydisp+this.y):this.refresh(this.y,this.y);return}if(t==="l"||t==="[C"){var r=this.x;this.x++,this.x>=this.cols&&(this.x=this.cols-1),this.visualMode?this.selectText(r,this.x,this.ydisp+this.y,this.ydisp+this.y):this.refresh(this.y,this.y);return}if(t==="v"||t===" "){this.visualMode?this.leaveVisual():this.enterVisual();return}if(t==="y"){if(this.visualMode){var i=this.grabText(this._selected.x1,this._selected.x2,this._selected.y1,this._selected.y2);this.copyText(i),this.leaveVisual()}return}if(t==="q"){this.visualMode?this.leaveVisual():this.leaveSelect();return}if(t==="w"||t==="W"){var s=this.x,o=this.y,u=this.ydisp,r=this.x,n=this.y,a=this.ydisp,f=!1;for(;;){var l=this.lines[a+n];while(r<this.cols){if(l[r][1]<=" ")f=!0;else if(f)break;r++}r>=this.cols&&(r=this.cols-1);if(r===this.cols-1&&l[r][1]<=" "){r=0;if(++n>=this.rows){n--;if(++a>this.ybase){a=this.ybase,r=this.x;break}}continue}break}this.x=r,this.y=n,this.scrollDisp(-this.ydisp+a),this.visualMode&&this.selectText(s,this.x,o+u,this.ydisp+this.y);return}if(t==="b"||t==="B"){var s=this.x,o=this.y,u=this.ydisp,r=this.x,n=this.y,a=this.ydisp;for(;;){var l=this.lines[a+n],f=r>0&&l[r][1]>" "&&l[r-1][1]>" ";while(r>=0){if(l[r][1]<=" "){if(f&&r+1<this.cols&&l[r+1][1]>" "){r++;break}f=!0}r--}r<0&&(r=0);if(r===0&&(l[r][1]<=" "||!f)){r=this.cols-1;if(--n<0){n++;if(--a<0){a++,r=0;break}}continue}break}this.x=r,this.y=n,this.scrollDisp(-this.ydisp+a),this.visualMode&&this.selectText(this.x,s,this.ydisp+this.y,o+u);return}if(t==="e"||t==="E"){var r=this.x+1,n=this.y,a=this.ydisp;r>=this.cols&&r--;for(;;){var l=this.lines[a+n];while(r<this.cols){if(!(l[r][1]<=" "))break;r++}while(r<this.cols){if(l[r][1]<=" "&&r-1>=0&&l[r-1][1]>" "){r--;break}r++}r>=this.cols&&(r=this.cols-1);if(r===this.cols-1&&l[r][1]<=" "){r=0;if(++n>=this.rows){n--;if(++a>this.ybase){a=this.ybase;break}}continue}break}this.x=r,this.y=n,this.scrollDisp(-this.ydisp+a),this.visualMode&&this.selectText(s,this.x,o+u,this.ydisp+this.y);return}if(t==="^"||t==="0"){var s=this.x;if(t==="0")this.x=0;else if(t==="^"){var l=this.lines[this.ydisp+this.y],r=0;while(r<this.cols){if(l[r][1]>" ")break;r++}r>=this.cols&&(r=this.cols-1),this.x=r}this.visualMode?this.selectText(this.x,s,this.ydisp+this.y,this.ydisp+this.y):this.refresh(this.y,this.y);return}if(t==="$"){var s=this.x,l=this.lines[this.ydisp+this.y],r=this.cols-1;while(r>=0){if(l[r][1]>" "){this.visualMode&&r<this.cols-1&&r++;break}r--}r<0&&(r=0),this.x=r,this.visualMode?this.selectText(s,this.x,this.ydisp+this.y,this.ydisp+this.y):this.refresh(this.y,this.y);return}if(t==="g"||t==="G"){var s=this.x,o=this.y,u=this.ydisp;t==="g"?(this.x=0,this.y=0,this.scrollDisp(-this.ydisp)):t==="G"&&(this.x=0,this.y=this.rows-1,this.scrollDisp(this.ybase)),this.visualMode&&this.selectText(s,this.x,o+u,this.ydisp+this.y);return}if(t==="H"||t==="M"||t==="L"){var s=this.x,o=this.y;t==="H"?(this.x=0,this.y=0):t==="M"?(this.x=0,this.y=this.rows/2|0):t==="L"&&(this.x=0,this.y=this.rows-1),this.visualMode?this.selectText(s,this.x,this.ydisp+o,this.ydisp+this.y):(this.refresh(o,o),this.refresh(this.y,this.y));return}if(t==="{"||t==="}"){var s=this.x,o=this.y,u=this.ydisp,l,c=!1,h=!1,p=-1,n=this.y+(t==="{"?-1:1),a=this.ydisp,d;t==="{"?n<0&&(n++,a>0&&a--):t==="}"&&n>=this.rows&&(n--,a<this.ybase&&a++);for(;;){l=this.lines[a+n];for(d=0;d<this.cols;d++){if(l[d][1]>" "){p===-1&&(p=0),c=!0;break}if(d===this.cols-1){p===-1?p=1:p===0?h=!0:p===1&&c&&(h=!0);break}}if(h)break;if(t==="{"){n--;if(n<0){n++;if(!(a>0))break;a--}}else if(t==="}"){n++;if(n>=this.rows){n--;if(!(a<this.ybase))break;a++}}}h||(t==="{"?(n=0,a=0):t==="}"&&(n=this.rows-1,a=this.ybase)),this.x=0,this.y=n,this.scrollDisp(-this.ydisp+a),this.visualMode&&this.selectText(s,this.x,o+u,this.ydisp+this.y);return}if(t==="/"||t==="?"){this.visualMode||this.enterSearch(t==="/");return}return!1},l.prototype.keySearch=function(e,t){if(t===""){this.leaveSearch();return}if(t==="\r"||!this.searchMode&&(t==="n"||t==="N")){this.leaveSearch();var n=this.entry;if(!n){this.refresh(0,this.rows-1);return}var r=this.x,i=this.y,s=this.ydisp,o,u=!1,a=!1,f=this.x+1,l=this.ydisp+this.y,c,h,p=t==="N"?this.searchDown:!this.searchDown;for(;;){o=this.lines[l];while(f<this.cols){for(h=0;h<n.length;h++){if(f+h>=this.cols)break;if(o[f+h][1]!==n[h])break;if(o[f+h][1]===n[h]&&h===n.length-1){u=!0;break}}if(u)break;f+=h+1}if(u)break;f=0;if(!p){l++;if(l>this.ybase+this.rows-1){if(a)break;a=!0,l=0}}else{l--;if(l<0){if(a)break;a=!0,l=this.ybase+this.rows-1}}}if(u){l-this.ybase<0?(c=l,l=0,c>this.ybase&&(l=c-this.ybase,c=this.ybase)):(c=this.ybase,l-=this.ybase),this.x=f,this.y=l,this.scrollDisp(-this.ydisp+c),this.visualMode&&this.selectText(r,this.x,i+s,this.ydisp+this.y);return}this.refresh(0,this.rows-1);return}if(t==="\b"||t===""){if(this.entry.length===0)return;var d=this.ydisp+this.rows-1;this.entry=this.entry.slice(0,-1);var h=this.entryPrefix.length+this.entry.length;this.lines[d][h]=[this.lines[d][h][0]," "],this.x--,this.refresh(this.rows-1,this.rows-1),this.refresh(this.y,this.y);return}if(t.length===1&&t>=" "&&t<="~"){var d=this.ydisp+this.rows-1;this.entry+=t;var h=this.entryPrefix.length+this.entry.length-1;this.lines[d][h]=[this.defAttr&-512|4,t],this.x++,this.refresh(this.rows-1,this.rows-1),this.refresh(this.y,this.y);return}return!1},l.charsets={},l.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:"≥","{":"π","|":"≠","}":"£","~":"·"},l.charsets.UK=null,l.charsets.US=null,l.charsets.Dutch=null,l.charsets.Finnish=null,l.charsets.French=null,l.charsets.FrenchCanadian=null,l.charsets.German=null,l.charsets.Italian=null,l.charsets.NorwegianDanish=null,l.charsets.Spanish=null,l.charsets.Swedish=null,l.charsets.Swiss=null,l.charsets.ISOLatin=null;var m=this.String,g=this.setTimeout,y=this.setInterval;E._cache={},E.distance=function(e,t,n,r,i,s){return Math.pow(30*(e-r),2)+Math.pow(59*(t-i),2)+Math.pow(11*(n-s),2)},l.EventEmitter=n,l.inherits=d,l.on=c,l.off=h,l.cancel=p,typeof module!="undefined"?module.exports=l:this.Terminal=l}.call(function(){return this||(typeof window!="undefined"?window:global)}()),define("vendors/term",function(){}),define("require-tools/less/normalize",[],function(){function r(e,r,i){if(e.indexOf("data:")===0)return e;e=t(e);var u=i.match(n),a=r.match(n);return a&&(!u||u[1]!=a[1]||u[2]!=a[2])?s(e,r):o(s(e,r),i)}function s(e,t){e.substr(0,2)=="./"&&(e=e.substr(2));if(e.match(/^\//)||e.match(n))return e;var r=t.split("/"),i=e.split("/");r.pop();while(curPart=i.shift())curPart==".."?r.pop():r.push(curPart);return r.join("/")}function o(e,t){var n=t.split("/");n.pop(),t=n.join("/")+"/",i=0;while(t.substr(i,1)==e.substr(i,1))i++;while(t.substr(i,1)!="/")i--;t=t.substr(i+1),e=e.substr(i+1),n=t.split("/");var r=e.split("/");out="";while(n.shift())out+="../";while(curPart=r.shift())out+=curPart+"/";return out.substr(0,out.length-1)}var e=/([^:])\/+/g,t=function(t){return t.replace(e,"$1/")},n=/[^\:\/]*:\/\/([^\/])*/,u=function(e,n,i){n=t(n),i=t(i);var s=/@import\s*("([^"]*)"|'([^']*)')|url\s*\(\s*(\s*"([^"]*)"|'([^']*)'|[^\)]*\s*)\s*\)/ig,o,u,e;while(o=s.exec(e)){u=o[3]||o[2]||o[5]||o[6]||o[4];var a;a=r(u,n,i);var f=o[5]||o[6]?1:0;e=e.substr(0,s.lastIndex-u.length-f-1)+a+e.substr(s.lastIndex-f-1),s.lastIndex=s.lastIndex+(a.length-u.length)}return e};return u.convertURIBase=r,u.absoluteURI=s,u.relativeURI=o,u}),define("require-tools/less/less",["require"],function(e){var t={};t.pluginBuilder="./less-builder";if(typeof window=="undefined")return t.load=function(e,t,n){n()},less;t.normalize=function(e,t){return e.substr(e.length-5,5)==".less"&&(e=e.substr(0,e.length-5)),e=t(e),e};var n=document.getElementsByTagName("head")[0],r=window.location.href.split("/");r[r.length-1]="",r=r.join("/");var i;window.less=window.less||{env:"development"};var s=0,o;t.inject=function(e){s<31&&(o=document.createElement("style"),o.type="text/css",n.appendChild(o),s++),o.styleSheet?o.styleSheet.cssText+=e:o.appendChild(document.createTextNode(e))};var u;return t.load=function(n,s,o,a){e(["./lessc","./normalize"],function(a,f){if(!i){var l=e.toUrl("base_url").split("/");l[l.length-1]="",i=f.absoluteURI(l.join("/"),r)+"/"}var c=s.toUrl(n+".less");c=f.absoluteURI(c,i),u=u||new a.Parser(window.less),u.parse('@import "'+c+'";',function(e,n){if(e)return o.error(e);t.inject(f(n.toCSS(),c,r)),setTimeout(o,7)})})},t}),define("require-tools/less/less!stylesheets/tab",[],function(){}),define("views/tab",["themes","vendors/term","less!stylesheets/tab.less"],function(e){function a(e){var t=e.palette;return e.background&&(t[256]=e.background),e.foreground&&(t[257]=e.foreground),t}var t=codebox.require("underscore"),n=codebox.require("jQuery"),r=codebox.require("hr/hr"),i=codebox.require("views/tabs/base"),s=codebox.require("core/box"),o=codebox.require("core/user"),u=o.settings("terminal"),f=i.extend({className:i.prototype.className+" addon-terminal-tab",defaults:{shellId:null,resize:!0},menuTitle:"Terminal",initialize:function(r){var i=this;return f.__super__.initialize.apply(this,arguments),this.connected=!1,this.menu.menuSection([{type:"checkbox",title:"Exit",action:function(e){i.closeTab()}}]),this.term_w=80,this.term_h=24,this.term_el=n("<div>",{"class":"tab-panel-inner terminal-body"}).appendTo(n("<div>",{"class":"tab-panel-body"}).appendTo(this.$el)).get(0),this.theme=e[u.get("theme","solarized_dark")],this.term=new Terminal({cols:this.term_w,rows:this.term_h,screenKeys:!0,useStyle:!1,scrollback:1e3,parent:this.term_el,colors:a(this.theme)}),this.term.open(this.term_el),this.interval=setInterval(t.bind(this.resize,this),2e3),this.clear(),this.sessionId=this.options.shellId||t.uniqueId("term"),this.shell=s.openShell({shellId:this.options.shellId?this.sessionId:this.sessionId+"-"+(new Date).getSeconds()}),this.on("tab:close",function(){clearInterval(this.interval),this.shell.disconnect(),this.term.destroy()},this),this.on("tab:state",function(e){e&&this.term.focus()},this),this.setTabTitle("Terminal - "+this.sessionId),this.shell.on("connect",function(){i.connected=!0,i.shell.stream.once("data",function(){i.shell.socket.emit("shell.resize",{shellId:i.shell.shellId,rows:i.term_h,columns:i.term_w})}),i.shell.stream.on("error",function(){i.writeln("Error connecting to remote host")}),i.shell.stream.on("end",function(){i.writeln("Connection closed by remote host"),i.closeTab()}),i.shell.stream.on("data",function(e){i.write(e.toString())}),i.trigger("terminal:ready")},this),this.term.on("data",function(e){i.shell.stream.write(e)}),this.on("resize",function(e,t){if(!i.connected)return;e=e||i.term_w,t=t||i.term_h,i.shell.socket.emit("shell.resize",{shellId:i.shell.shellId,rows:t,columns:e})}),this.shell.connect(),this},render:function(){return this.$el.css({"font-family":u.get("font","monospace"),"font-size":u.get("size",13)+"px","line-height":u.get("line-height",1.3)}),n(this.term_el).css({background:this.theme.background,"border-color":this.theme.background}),setTimeout(this.resize.bind(this),0),this.ready()},resize:function(e,n){if(!this.options.resize)return!1;var r=Math.floor(u.get("line-height",1.3)*u.get("size",13));return e=e||t.min([400,t.max([Math.floor((this.$el.outerWidth()-10)/8)-1,10])]),n=n||t.min([400,t.max([Math.floor(this.$el.outerHeight()/r)-1,10])]),e==this.term_w&&n==this.term_h?this:(this.term_w=e,this.term_h=n,this.term.resize(this.term_w,this.term_h),this.trigger("resize",this.term_w,this.term_h),this)},write:function(e){return this.term.write(e),this},writeln:function(e){return this.write(e+"\r\n")},clear:function(){return this.write("[H[2J")}});return f}),define("client",["themes","views/tab"],function(e,t){var n=codebox.require("models/command"),r=codebox.require("core/commands/toolbar"),i=codebox.require("core/box"),s=codebox.require("core/tabs"),o=codebox.require("core/settings"),u=codebox.require("core/commands/menu"),a={};_.each(e,function(e,t){a[t]=t}),o.add({namespace:"terminal",title:"Terminal",defaults:{font:"monospace",size:13,"line-height":1.3,theme:"monokai_soda"},fields:{font:{label:"Font",type:"select",options:{monospace:"Monospace",arial:"Arial","Courier New":"Courier New","'MS Sans Serif', Geneva, sans-serif;":"MS Sans Serif","'Lucida Sans Unicode', 'Lucida Grande', sans-serif":"Lucida Sans Unicode",monaco:"Monaco (Mac OS)",menlo:"Menlo (Mac OS)","Ubuntu Mono":"Ubuntu Mono (Ubuntu)",Consolas:"Consolas (Windows)","Lucida Console":"Lucida Console (Windows)"}},size:{label:"Font size",type:"number",min:8,max:20,step:1},"line-height":{label:"Line height",type:"number",min:1,max:1.9,step:.1},theme:{label:"Theme",type:"select",options:a}}});var f=r.register("terminal.open",{title:"New Terminal",icon:"terminal",offline:!1,shortcuts:["alt+t"]},function(e){var n=s.add(t,{shellId:e},{section:"terminals"});return n}),l=n.register("terminal.list",{title:"Open Terminals",offline:!1,type:"menu"}),c=function(){return i.listShells().then(function(e){l.menu.reset(_.map(e,function(e){return{title:e,action:function(){f.run(e)}}}))})};i.on("box:shell:open box:shell:destroy",c),u.getById("file").menuSection([f,l])}),function(e){var t=document,n="appendChild",r="styleSheet",i=t.createElement("style");i.type="text/css",t.getElementsByTagName("head")[0][n](i),i[r]?i[r].cssText=e:i[n](t.createTextNode(e))}(".addon-terminal-tab{position:absolute;width:100%;height:100%;background:0 0}.addon-terminal-tab .tab-panel-body .tab-panel-inner.terminal-body{background:#000;border-color:#000;overflow:auto;cursor:text;font-weight:700;padding:3px}.addon-terminal-tab .tab-panel-body .tab-panel-inner.terminal-body *{white-space:nowrap}.addon-terminal-tab .tab-panel-body .tab-panel-inner.terminal-body .terminal-cursor{background:#fff;color:#000}")