terminal.js
Version:
terminal emulation library for javascript.
2 lines • 123 kB
JavaScript
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Terminal=a()}}(function(){return function(){function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){return e(b[g][1][a]||a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}return a}()({1:[function(a,b,c){b.exports=a("./lib/terminal.js"),b.exports.TermState=a("./lib/term_state.js"),b.exports.TermDiff=a("./lib/term_diff.js"),b.exports.output={PlainOutput:a("./lib/output/plain.js"),AnsiOutput:a("./lib/output/ansi.js"),TtyOutput:a("./lib/output/tty.js"),HtmlOutput:a("./lib/output/html.js"),DomOutput:a("./lib/output/dom.js")},b.exports.source={EmitterSource:a("./lib/source/emitter.js")},b.exports.input={DomInput:a("./lib/input/dom.js"),TtyInput:a("./lib/input/tty.js")}},{"./lib/input/dom.js":10,"./lib/input/tty.js":11,"./lib/output/ansi.js":12,"./lib/output/dom.js":14,"./lib/output/html.js":15,"./lib/output/plain.js":17,"./lib/output/tty.js":18,"./lib/source/emitter.js":20,"./lib/term_diff.js":21,"./lib/term_state.js":22,"./lib/terminal.js":23}],2:[function(a,b,c){"use strict";var d={"":function(a,b){this.emit("bell")},"\b":function(a,b){this.state.mvCursor(-1,0)},"\t":function(a,b){this.state.mvTab(1)},"":function(a,b){this.state.removeChar(1)},"":function(a,b){this.state.setTab()},"":function(){this.state.mapCharset("G1")},"":function(){this.state.mapCharset("G0")},"":function(a,b){return void 0!==b[1]?this.callHandler("esc",b[1],b):0},"\r":function(a,b){this.state.setCursor(0,null)}};b.exports=d},{}],3:[function(a,b,c){"use strict";var d={"@":function(a,b,c,d,e){this.state.insertBlank(b||1)},A:function(a,b,c,d,e){this.state.mvCursor(0,-(b||1))},B:function(a,b,c,d,e){this.state.mvCursor(0,b||1)},C:function(a,b,c,d,e){this.state.mvCursor(b||1,0)},D:function(a,b,c,d,e){this.state.mvCursor(-(b||1),0)},E:function(a,b,c,d,e){this.state.mvCursor(0,b||1).setCursor(0,null)},F:function(a,b,c,d,e){this.state.mvCursor(0,-b||-1).setCursor(0,null)},G:function(a,b,c,d,e){this.state.setCursor((b||1)-1)},H:function(a,b,c,d,e){this.state.setCursor((c||1)-1,(b||1)-1)},I:function(a,b,c,d,e){this.state.mvTab(b||1)},J:function(a,b,c,d,e){this.state.eraseInDisplay(b||0)},K:function(a,b,c,d,e){this.state.eraseInLine(b||0)},L:function(a,b,c,d,e){this.state.insertLine(b||1),this.state.setCursor(0,null)},M:function(a,b,c,d,e){this.state.removeLine(b||1)},P:function(a,b,c,d,e){this.state.removeChar(b||1)},R:function(a,b,c,d,e){},S:function(a,b,c,d,e){this.state.scroll(b||1)},T:function(a,b,c,d,e){d.length<=1&&this.state.scroll(-b||-1)},X:function(a,b,c,d,e){this.state.eraseCharacters(b||1)},Z:function(a,b,c,d,e){this.state.mvTab(-(b||1))},a:function(a,b,c,d,e){this.state.mvCursor(b||1,0)},b:function(a,b,c,d,e){},c:function(a,b,c,d,e){this.emit("request",">0;95;c")},d:function(a,b,c,d,e){this.state.setCursor(null,(b||1)-1)},e:function(a,b,c,d,e){this.state.mvCursor(0,b||1)},f:function(a,b,c,d,e){this.state.setCursor((c||1)-1,(b||1)-1)},g:function(a,b,c,d,e){this.state.tabClear(b||0)},h:function(a,b,c,d,e){var f;for(f=0;f<d.length;f++)this.callHandler("mode",e+d[f],!0)},i:function(a,b,c,d,e){},l:function(a,b,c,d,e){var f;for(f=0;f<d.length;f++)this.callHandler("mode",e+d[f],!1)},m:function(a,b,c,d,e){var f;if(5===d[1]&&38===d[0])this.state.setAttribute("fg",d[2]);else if(5===d[1]&&48===d[0])this.state.setAttribute("bg",d[2]);else{for(f=0;f<d.length;f++)this.callHandler("sgr",d[f]);0===f&&this.callHandler("sgr",0)}},n:function(a,b,c,d,e){},p:function(a,b,c,d,e){},q:function(a,b,c,d,e){0===b?this.state.resetLeds():this.state.ledOn(b-1)},r:function(a,b,c,d,e){this.state.setScrollRegion((b||1)-1,(c||this.state.rows)-1)},s:function(a,b,c,d,e){this.state.saveCursor()},t:function(a,b,c,d,e){},u:function(a,b,c,d,e){this.state.restoreCursor()},v:function(a,b,c,d,e){},w:function(a,b,c,d,e){},x:function(a,b,c,d,e){},y:function(a,b,c,d,e){},z:function(a,b,c,d,e){},"`":function(a,b,c,d,e){this.state.setCursor((b||1)-1)},"{":function(a,b,c,d,e){},"|":function(a,b,c,d,e){},"}":function(a,b,c,d,e){},"~":function(a,b,c,d,e){}};b.exports=d},{}],4:[function(a,b,c){"use strict";b.exports={}},{}],5:[function(a,b,c){"use strict";var d={c:function(a,b){return this.state.reset(),2},D:function(a,b){return this.state.nextLine(),2},E:function(a,b){return this.state.nextLine().setCursor(0),2},H:function(a,b){return this.state.setTab(),2},M:function(a,b){return this.state.prevLine(),2},N:function(a,b){return this.state.mapCharset("G2",!0),2},O:function(a,b){return this.state.mapCharset("G3",!0),2},P:function(a,b){var c=this.parseDcs(b);if(null===c||""===c.cmd)return 0;if(c.length!==b.length&&""===c.cmd)return 1;this.callHandler("dcs",c.cmd,+c.args[0],+c.args[1],c.args,c.mod);return c.length},Q:function(a,b){return 2},R:function(a,b){return 2},S:function(a,b){return 2},T:function(a,b){return 2},U:function(a,b){return 2},V:function(a,b){return 2},W:function(a,b){return 2},X:function(a,b){return 2},Y:function(a,b){return 2},Z:function(a,b){return 2},n:function(a,b){return this.state.mapCharset("G2"),2},o:function(a,b){return this.state.mapCharset("G3"),2},7:function(a,b){return this.state.saveCursor(),2},8:function(a,b){return this.state.restoreCursor(),2},"|":function(a,b){return 2},"[":function(a,b){var c=this.parseCsi(b);if(null===c||""===c.cmd)return 0;if(c.length!==b.length&&""===c.cmd)return 1;this.callHandler("csi",c.cmd,+c.args[0],+c.args[1],c.args,c.mod);return c.length},"\\":function(a,b){return 2},"]":function(a,b){var c=this.parseOsc(b);if(null===c||!1===c.terminated)return 0;if(c.length!==b.length&&!1===c.terminated)return 1;this.callHandler("osc",c.cmd,c.args);return c.length},"^":function(a,b){return 2},_:function(a,b){return 2},"%":function(a,b){return void 0===b[2]?0:(this.state.selectCharset("unicode"),3)},"}":function(a,b){return 2},"~":function(a,b){return 2},"(":"/",")":"/","*":"/","+":"/","-":"/",".":"/","/":function(a,b){var c={"(":"G0",")":"G1","*":"G2","+":"G3","-":"G1",".":"G2","/":"G3"};if(void 0===b[2])return 0;if("%"===b[2]&&void 0===b[3])return 0;var d="0"===b[2]?"graphics":"unicode";return this.state.selectCharset(d,c[b[1]]),"%"===b[2]?4:3},"#":function(a,b){if(void 0===b[2])return 0;var c=this.state.getLine();switch(b[2]){case"3":c.attr.doubleheight="top";break;case"4":c.attr.doubleheight="bottom";break;case"5":delete c.attr.doubleheight,delete c.attr.doublewidth;break;case"6":c.attr.doublewidth=!0}return this.state.setLine(c),3},g:function(a,b){return this.emit("bell",!0),2},"<":function(a,b){return 2},">":function(a,b){return this.state.setMode("appKeypad",!1),2},"=":function(a,b){return this.state.setMode("appKeypad",!0),2}};b.exports=d},{}],6:[function(a,b,c){"use strict";var d={1:function(a,b){this.state.setMode("appKeypad",b)},4:function(a,b){this.state.setMode("insert",b)},"?5":function(a,b){this.state.setMode("reverse",b)},7:function(a,b){this.state.setMode("wrap",b)},"?12":function(a,b){this.state.setMode("cursorBlink",b)},20:function(a,b){this.state.setMode("crlf",b)},"?25":function(a,b){this.state.setMode("cursor",b)},"?47":function(a,b){this.state.switchBuffer(b)},"?1000":function(a,b){this.state.setMode("mousebtn",b)},"?1002":function(a,b){this.state.setMode("mousemtn",b)},"?1006":function(a,b){this.state.setMode("mousesgr",b)},"?1047":function(a,b){this.state.switchBuffer(b)},"?1048":function(a,b){b?this.state.saveCursor():this.state.restoreCursor()},"?1049":function(a,b){this.callHandler("mode","1048",b),this.callHandler("mode","1047",b),b&&this.state.setCursor(0,0)}};b.exports=d},{}],7:[function(a,b,c){"use strict";function d(a){var b=arguments;return function(c,d){var e=Array.prototype.slice(b,1);e.unshift(d),this.emit.apply(a,e)}}function e(a){return function(b,c){this.state.setMeta(a,c)}}var f={0:"bold",1:"underline",2:"blink",3:"reverse"},g={"":"0",0:function(a,b){this.state.setMeta("title",b[0]),this.state.setMeta("icon",b[0])},1:e("icon"),2:e("title"),3:function(){},4:function(a,b){b=b.split(";"),this.emit("colorchange",b[0],b[1])},5:function(a,b){b=b.split(";"),this.emit("colorchange",f[b[0]],b[1])},10:d("colorchange","fg"),11:d("colorchange","bg"),12:d("colorchange","cursor"),13:d("colorchange","mousefg"),14:d("colorchange","mousebg"),15:d("colorchange","tektronixfg"),16:d("colorchange","tektronixbg"),17:d("colorchange","highlightbg"),18:d("colorchange","tektronixhighlight"),19:d("colorchange","highlightfg"),46:d("logfilechange"),50:d("fontchange"),51:d("emacs"),52:function(){},104:function(a,b){this.emit("colorreset",b)},105:function(a,b){this.emit("colorreset",f[b])},110:d("colorreset","fg"),111:d("colorreset","bg"),112:d("colorreset","cursor"),113:d("colorreset","mousefg"),114:d("colorreset","mousebg"),115:d("colorreset","tektronixfg"),116:d("colorreset","tektronixbg"),117:d("colorreset","highlightbg"),118:d("colorreset","tektronixhighlight"),119:d("colorreset","highlightfg")};b.exports=g},{}],8:[function(a,b,c){"use strict";function d(a,b){return function(){this.state.setAttribute(a,b)}}var e={0:function(a){this.state.resetAttribute()},1:d("bold",!0),2:function(a){},3:d("italic",!0),4:d("underline",!0),5:"6",6:d("blink",!0),7:d("inverse",!0),8:function(a){},9:function(a){},20:function(a){},21:function(a){},22:d("bold",!1),23:d("italic",!1),24:d("underline",!1),25:d("blink",!1),27:d("inverse",!1),30:"37",31:"37",32:"37",33:"37",34:"37",35:"37",36:"37",37:function(a){this.state.setAttribute("fg",+a-30)},38:function(a){},39:function(a){this.state.resetAttribute("fg")},40:"47",41:"47",42:"47",43:"47",44:"47",45:"47",46:"47",47:function(a){this.state.setAttribute("bg",+a-40)},48:function(a){},49:function(a){this.state.resetAttribute("bg")},51:function(a){},52:function(a){},53:function(a){},90:"97",91:"97",92:"97",93:"97",94:"97",95:"97",96:"97",97:function(a){this.state.setAttribute("fg",+a-90+8)},100:"107",101:"107",102:"107",103:"107",104:"107",105:"107",106:"107",107:function(a){this.state.setAttribute("bg",+a-100+8)}};b.exports=e},{}],9:[function(a,b,c){"use strict";function d(a,b){d.super_.apply(this,arguments);var c=arguments[Math.max(1,arguments.length-1)];this.target=a,this.buffer=b,this._appKeypad=!1;this._opts=g.extend({},this._defOpts,c)}var e=a("stream"),f=a("util"),g=a("../util.js");f.inherits(d,e.Readable),d.prototype.getKey=function(a){var b=this.buffer.getMode("appKeypad")?"O":"[";switch(a){case"up":b+="A";break;case"down":b+="B";break;case"right":b+="C";break;case"left":b+="D"}return b},d.prototype._read=function(){},b.exports=d},{"../util.js":24,stream:54,util:59}],10:[function(a,b,c){"use strict";function d(a,b,c){d.super_.apply(this,arguments),a.tabIndex=0,this._addListener(this.target,"keypress",this._keypress),this._addListener(this.target,"keydown",this._keydown),this._addListener(this.target,"paste",this._paste),this._addListener(this.target,"contextmenu",this._contextmenu),this._addListener(this.target,"click",this._click),this._addListener(this.target,"mousemove",this._mousemove)}a("../util");(0,a("util").inherits)(d,a("./base")),b.exports=d,d.prototype._addListener=function(a,b,c){var d=this,e=function(a){return a=a||window.event,c.call(d,a)};a.addEventListener?a.addEventListener(b,e):a["on"+b]=e},d.prototype.getKeyCode=function(a){return a?a.charCode?a.charCode:a.which?a.which:a.keyCode:void 0},d.prototype._mousemove=function(a){},d.prototype._click=function(a){this.target.contentEditable=!1},d.prototype._cancelEvent=function(a){return a.stopPropagation&&a.stopPropagation(),a.preventDefault&&a.preventDefault(),this.target.contentEditable=!1,!1},d.prototype._contextmenu=function(a){this.target.contentEditable=!0},d.prototype._paste=function(a){return this.push(a.clipboardData.getData("text/plain")),this._cancelEvent(a)},d.prototype._keypress=function(a){var b=this.getKeyCode(a);if(b&&!a.ctrlKey&&!a.altKey&&!a.metaKey)return this.push(String.fromCharCode(b)),this.target.contentEditable=!1,this._cancelEvent(a)},d.prototype._keydown=function(a){var b,c=this.getKeyCode(a);if(!(a.ctrlKey&&a.shiftKey||a.metaKey)){switch(c){case 8:if(a.shiftKey){b="\b";break}b="";break;case 9:if(a.shiftKey){b="[Z";break}b="\t";break;case 13:b="\r";break;case 27:b="";break;case 37:b=this.getKey("left");break;case 39:b=this.getKey("right");break;case 38:b=this.getKey("up");break;case 40:b=this.getKey("down");break;case 46:b="[3~";break;case 45:b="[2~";break;case 36:b="OH";break;case 35:b="OF";break;case 33:b="[5~";break;case 34:b="[6~";break;case 112:b="OP";break;case 113:b="OQ";break;case 114:b="OR";break;case 115:b="OS";break;case 116:b="[15~";break;case 117:b="[17~";break;case 118:b="[18~";break;case 119:b="[19~";break;case 120:b="[20~";break;case 121:b="[21~";break;case 122:b="[23~";break;case 123:b="[24~";break;default:a.ctrlKey?c>=65&&c<=90?b=String.fromCharCode(c-64):32===c?b=String.fromCharCode(0):c>=51&&c<=55?b=String.fromCharCode(c-51+27):56===c?b=String.fromCharCode(127):219===c?b=String.fromCharCode(27):221===c&&(b=String.fromCharCode(29)):a.altKey&&(c>=65&&c<=90?b=""+String.fromCharCode(c+32):192===c?b="`":c>=48&&c<=57&&(b=""+(c-48)))}return void 0!==b?(this.target.contentEditable=!1,this.push(b),this._cancelEvent(a)):void 0}},d.canHandle=a("../output/dom.js").canHandle},{"../output/dom.js":14,"../util":24,"./base":9,util:59}],11:[function(a,b,c){"use strict";function d(a,b,c){d.super_.apply(this,arguments);var e=this;this.target.stdout&&(this.target=this.target.stdout),this.target.on("readable",function(){e.doread()})}a("../util");(0,a("util").inherits)(d,a("./base")),b.exports=d;d.prototype.doread=function(){var a=this.target.read().toString();this.appKeypad&&(a=a.replace(/\x1b\[([0-9;]*[ABCD])/g,"O$1")),this.push(a)},d.canHandle=function(a){return a.stdin&&(a=a.stdin),"object"==typeof a&&"read"in a&&"on"in a&&a.isTTY}},{"../util":24,"./base":9,util:59}],12:[function(a,b,c){"use strict";function d(a,b){d.super_.apply(this,arguments)}var e=a("../util");(0,a("util").inherits)(d,a("./base.js")),b.exports=d,d.prototype._mkSgr=function(a,b){var c="",d=b&&b.$cursor;c+=!0===a.bold?";1":";22",c+=!0===a.italic?";3":";23",c+=!0===a.underline?";4":";24",c+=!0===a.blink?";5":";25",c+=!0===a.inverse||d&&!0!==a.inverse?";7":";27";var e=a.fg,f=a.bg;return e&&(c+=e<8?";"+(+e+30):e<16?";"+(+e+90-8):";38;5;"+e),f&&(c+=f<7?";"+(+f+30):f<16?";"+(+f+100-8):";48;5;"+f),"["+c.substr(1)+"m"},d.prototype._renderLine=function(a,b){var c,d,f,g="",h=a.str;for(null!==a.attr[h.length].bg?h+=e.repeat(" ",this.state.colums-h.length):void 0!==b&&(h+=e.repeat(" ",b+1-h.length)),c=0;c<h.length;){if(d=c++,d in a.attr&&(f=a.attr[d]),b!==d)for(;c<h.length&&!(c in a.attr)&&b!==c;)c++;g+=this._mkSgr(f,{$cursor:b===d})+h.substring(d,c)}return g},d.prototype.toString=function(){for(var a="",b=this.state.cursor,c=0;c<this.state.rows;c++){var d=this.state.getLine(c);a+="\n"+this._renderLine(d,b.y===c?b.x:null)}return a.substr(1)+"[0m"},d.canHandle=function(a){return"ansi"===a}},{"../util":24,"./base.js":13,util:59}],13:[function(a,b,c){"use strict";function d(a){var b=arguments[Math.max(1,arguments.length-1)];this.state=a,this._opts=e.extend({},this._defOpts,b)}var e=a("../util.js");b.exports=d,d.prototype.toString=function(){throw new Error("toString is not implemented!")}},{"../util.js":24}],14:[function(a,b,c){"use strict";function d(a,b,c,e){this.html=new g(a,e),c.innerHTML="<div style='visibility:hidden;'></div>",this.spacer=c.firstChild,this.cursorView=null,d.super_.apply(this,arguments),this._opts.adhesiveCursor=!0}var e=a("../util"),f=a("util").inherits,g=a("./html.js");f(d,a("./live_base.js")),b.exports=d,d.prototype.createView=function(){var a=this.target.ownerDocument.createElement("div");return a.style.overflow="hidden",a},d.prototype.removeLine=function(a,b){return this.target.removeChild(b)},d.prototype.changeLine=function(a,b,c,d){b.innerHTML=this.html._renderLine(c,d)},d.prototype.insertLine=function(a,b,c,d){return b.innerHTML=this.html._renderLine(c,d),this.target.insertBefore(b,this.target.childNodes[a]),b},d.prototype.changeLed=function(a,b,c,d){},d.prototype.setCursor=function(a,b){},d.prototype.resize=function(a){this.target.lastChild.innerHTML=this.html._genColumnsString()},d.prototype.commit=function(){var a=this.state.rows-this.state.getBufferRowCount(),b=e.repeat("<br />",a)+"<div style='line-height:0'>"+e.repeat(" ",this.state.columns)+"</div>";this.spacer.innerHTML=b,this.spacer.lineHeight=0===a?"0":"inherit"},d.canHandle=function(a){return null!==a&&"object"==typeof a&&"ownerDocument"in a}},{"../util":24,"./html.js":15,"./live_base.js":16,util:59}],15:[function(a,b,c){"use strict";function d(a,b){d.super_.apply(this,arguments)}var e=a("../util");(0,a("util").inherits)(d,a("./base")),b.exports=d,d.prototype._defOpts={cssClass:!1,cursorBg:"#00ff00",cursorFg:"#ffffff"},d.prototype.colors=["#2e3436","#cc0000","#4e9a06","#c4a000","#3465a4","#75507b","#06989a","#d3d7cf","#555753","#ef2929","#8ae234","#fce94f","#729fcf","#ad7fa8","#34e2e2","#eeeeec"],d.prototype.colors=function(){function a(a){return a=a.toString(16),a.length<2?"0"+a:a}function b(b,c,d){e.push("#"+a(b)+a(c)+a(d))}var c,e=d.prototype.colors,f=[0,95,135,175,215,255];for(c=0;c<216;c++)b(f[c/36%6|0],f[c/6%6|0],f[c%6]);for(c=0;c<24;c++)f=8+10*c,b(f,f,f);return e}(),d.prototype._cssPrefix=function(a){return a+"-webkit-"+a+"-moz-"+a+"-ms-"+a},d.prototype._mkCssProperties=function(a){var b="";return a?(a.fg&&(b+=(a.inverse?"background":"color")+":"+this.colors[a.fg]+";"),a.bg&&(b+=(a.inverse?"color":"background")+":"+this.colors[a.bg]+";"),a.bold&&(b+="font-weight:bold;"),a.italic&&(b+="font-style:italic;"),(a.underline||a.blink)&&(b+="text-decoration:"+(a.underline?"underline ":"")+(a.blink?"blink;":";")),(a.doublewidth||a.doubleheight)&&(b+=this._cssPrefix("transform:"+(a.doublewidth?"scaleX(2) ":"")+(a.doubleheight?"scaleY(2);":";")),b+=this._cssPrefix("transform-origin:left "+(a.doubleheight||"")+";")),b):""};d.prototype.escapeHtml=function(a){return a.replace(/</g,"<").replace(/>/g,">").replace(/ /g," ")},d.prototype._mkAttr=function(a,b,c){if(this._opts.cssClass){for(var d=b||"",e=Object.keys(a),f=0;f<e.length;f++)!0===a[e[f]]?d+=" "+e[f]:!1!==a[e[f]]&&null!==a[e[f]]&&(d+=" "+e[f]+"_"+a[e[f]]);return"class='"+d+"'"}var g=this._mkCssProperties(a);switch(b){case"cursor":g+="background:"+this._opts.cursorBg+";",g+="color:"+this._opts.cursorFg+";";break;case"line":g+="overflow:hidden;white-space:nowrap;"}return""===g?"":(c&&c.setAttribute("style",g),"style='"+g+"'")},d.prototype._renderLine=function(a,b){var c,d,f,g,h,i="",j=a.str;if(null!==a.attr[j.length].bg?j+=e.repeat(" ",this.state.columns-j.length):void 0!==b&&b<this.state.columns&&(j+=e.repeat(" ",b+1-j.length)),0===j.length)return"<br />";for(c=0;c<j.length;){if("",d=c++,d in a.attr&&(f=a.attr[d]),b!==d)for(;c<j.length&&!(c in a.attr)&&b!==c;)c++;g=this._mkAttr(f,this.state.getMode("cursor")&&b===d?"cursor":void 0),h=this.escapeHtml(j.substring(d,c)),i+=""!==g?"<span "+g+">"+h+"</span>":h}return"<div "+this._mkAttr(a.attr,"line")+">"+i+"</div>"},d.prototype.toString=function(){var a,b="";for(a=0;a<this.state.rows;a++){var c=this.state.getLine(a);b+="<div style='overflow:hidden'>"+this._renderLine(c)+"</div>"}return b+"<div style='line-height:0;visibility:hidden;'>"+this._genColumnsString()+"</div>"},d.prototype._genColumnsString=function(){return e.repeat(" ",this.state.columns)},d.canHandle=function(a){return"html"===a}},{"../util":24,"./base":13,util:59}],16:[function(a,b,c){"use strict";function d(a,b,c,e){d.super_.apply(this,arguments);this.target=c,this.writer=b,this._views=[],this._oldViews=[],this._cursorView=null,this._cursorDrawnAt=null,this._timeout=null,this._queue=[];var f=this;a.on("lineremove",function(){f._removeLine.apply(f,arguments)}),a.on("linechange",function(){f._changeLine.apply(f,arguments)}),a.on("lineinsert",function(){f._insertLine.apply(f,arguments)}),a.on("ledchange",function(){f._changeLed.apply(f,arguments)}),a.on("cursormove",function(){f._setCursor.apply(f,arguments)}),a.on("resize",function(){f._resize.apply(f,arguments)}),a.on("bell",function(){f._bell.apply(f,arguments)}),b.on("ready",function(){f._checkCommit()})}var e=a("util").inherits,f=function(){};e(d,a("./base")),b.exports=d,d.prototype._schedule=function(a,b){var c;for(c=0;c<this._queue.length;c++)if(this._queue[c].view===a)return void(this._queue[c].cb=b);this._queue.unshift({view:a,cb:b})},d.prototype._flush=function(a){var b;for(b=0;b<this._queue.length;b++)this._queue[b].cb.call(this,this._queue[b].view);this._queue=[]},d.prototype._updateCursor=function(a,b){if(this._opts.adhesiveCursor&&null!==this._cursorDrawnAt)switch(a){case"insert":b<=this._cursorDrawnAt&&(this._cursorDrawnAt=Math.min(this._cursorDrawnAt+1,this.state.rows-1));break;case"remove":b<this._cursorDrawnAt?this._cursorDrawnAt--:b===this._cursorDrawnAt&&(this._cursorDrawnAt=null)}},d.prototype._removeLine=function(a){var b=this._views.splice(a,1)[0],c=this.removeLine(a,b.view);c&&(b.view=c,this._oldViews.push(b)),this._updateCursor("remove",a)},d.prototype._changeLine=function(a,b,c){this.state.getMode("cursor")||(c=void 0),this._schedule(this._views[a],function(d){var e=this.changeLine(a,d.view,b,c);void 0!==e&&(d.view=e),void 0!==c&&(this._cursorDrawnAt=a)})},d.prototype._insertLine=function(a,b,c){var d=this._oldViews.shift()||{view:this.createView()},e=this.insertLine(a,d.view,b,c);void 0!==e&&(d.view=e),this._views.splice(a,0,d),this._updateCursor("insert",a)},d.prototype._changeLed=function(){this.changeLed.apply(this,arguments)},d.prototype._setCursor=function(a,b){this._cursorView=this.setCursor(a,b)},d.prototype._resize=function(a){this._flush(),this.resize(a)},d.prototype._checkCommit=function(){var a=this,b=arguments;if(!this._opts.renderInterval)return this._commit.apply(this,b);null===this._timeout&&(this._timeout=setTimeout(function(){a._commit.apply(a,b),a._timeout=null},this._opts._renderInterval))},d.prototype._commit=function(){var a=this.state.cursor;a.y!==this._cursorDrawnAt&&null!==this._cursorDrawnAt&&this._changeLine(this._cursorDrawnAt,this.state.getLine(this._cursorDrawnAt)),a.y<this._views.length&&this._changeLine(a.y,this.state.getLine(a.y),a.x),this._flush(),this.commit.apply(this,arguments)},d.prototype._bell=function(){this.bell.apply(this,arguments)},d.prototype.createView=d.prototype.removeLine=d.prototype.changeLine=d.prototype.insertLine=d.prototype.changeLed=d.prototype.setCursor=d.prototype.resize=d.prototype.bell=d.prototype.commit=f},{"./base":13,util:59}],17:[function(a,b,c){"use strict";function d(a,b){d.super_.apply(this,arguments)}var e=a("util").inherits,f=a("../util");e(d,a("./base.js")),b.exports=d,d.prototype.toString=function(){var a="",b=this._opts.locateCursor;b&&(a+=f.repeat(" ",this.state.cursor.x+1)+"v\n");for(var c=0;c<this.state.rows;c++){var d=this.state.getLine(c);b&&(a+=c===this.state.cursor.y?">":" "),a+=d.str+"\n"}return b&&(a+=f.repeat(" ",this.state.cursor.x+1)+"^\n"),a},d.canHandle=function(a){return"plain"===a}},{"../util":24,"./base.js":13,util:59}],18:[function(a,b,c){"use strict";function d(a,b,c,e){this.ansi=new f(a,e),c.stdout&&(c=c.stdout),c.write("[3J[H[?25l"),d.super_.call(this,a,b,c,e),this._opts.adhesiveCursor=!0}var e=(a("../util"),a("util").inherits),f=a("./ansi.js");e(d,a("./live_base.js")),b.exports=d,d.prototype.removeLine=function(a,b){return this.target.write("["+(a+1)+";1H[M"),null},d.prototype.changeLine=function(a,b,c,d){return this.target.write("["+(a+1)+";1H"+this.ansi._renderLine(c,d)),null},d.prototype.insertLine=function(a,b,c,d){return this.target.write("["+(a+1)+";1H[L"),this.changeLine.apply(this,arguments),null},d.prototype.changeLed=function(a,b,c,d){},d.prototype.setCursor=function(a,b){},d.prototype.resize=function(a){},d.prototype.commit=function(){},d.canHandle=function(a){return a.stdout&&(a=a.stdout),"object"==typeof a&&"read"in a&&"on"in a&&a.isTTY}},{"../util":24,"./ansi.js":12,"./live_base.js":16,util:59}],19:[function(a,b,c){"use strict";function d(a,b){var c=arguments[Math.max(1,arguments.length-1)];this.writer=a,this.source=b,this._opts=e.extend({},this._defOpts,c)}var e=a("../util.js");b.exports=d},{"../util.js":24}],20:[function(a,b,c){"use strict";function d(a){return function(){return"function"==typeof this.source[a]?this.source[a].apply(this.source,arguments):(Array.prototype.unshift.call(arguments,a),this.source.emit.apply(this.source,arguments))}}function e(a,b,c){e.super_.apply(this,arguments),this._register()}a("../util");(0,a("util").inherits)(e,a("./base")),b.exports=e,e.prototype._register=function(){var a=this.writer;this.source.on("data",function(b){a.write(b)}).on("exit",function(){a.end()})},e.prototype.write=d("write"),e.prototype.end=d("end"),e.prototype._resize=d("resize"),e.prototype.kill=d("kill"),e.prototype.resize=function(a){return this._resize(a)},e.canHandle=function(a){return a&&"function"==typeof a.addListener&&"function"==typeof a.on}},{"../util":24,"./base":19,util:59}],21:[function(a,b,c){"use strict";function d(a,b){var c,d={};if(b instanceof Array)for(c=0;c<b.length||c<a.length;c++)b[c]!==a[c]&&(d[c]=b[c]);else for(c in b)b[c]!==a[c]&&(d[c]=b[c]);return d}function e(a,b){var c,d,e,f;for(c=Object.keys(a),e=0;e<c.length;e++){if(!b[c[e]])return!1;for(d=Object.keys(a[c[e]]),f=0;f<d.length;f++)if(a[c[e]][d[f]]!==b[c[e]][d[f]])return!1}return!0}function f(a,b){if(this._changes=[],this._cursor=null,this._scrollRegion=null,this._savedCursor=null,this._modes=null,this._leds=null,this._size=null,this._tabs=null,this._columns=null,this._rows=null,"object"==typeof a&&a.getLine)this.oldState=a,this.newState=b,this._mkDiff(a,b),this._mkCursor(a,b),this._mkScrollRegion(a,b),this._mkModes(a,b),this._mkLeds(a,b),this._mkSize(a,b),this._mkTabs(a,b);else if("string"==typeof a){var c=JSON.parse(a);this._loadJson(c)}else this._loadJson(a)}var g=a("./util.js");b.exports=f,f.prototype._mkCursor=function(a,b){a.cursor.x===b.cursor.x&&a.cursor.y===b.cursor.y||(this._cursor=g.extend({},b.cursor)),a._savedCursor.x===b._savedCursor.x&&a._savedCursor.y===b._savedCursor.y||(this._savedCursor=g.extend({},b._savedCursor))},f.prototype._mkScrollRegion=function(a,b){this._scrollRegion=b._scrollRegion.slice()},f.prototype._mkModes=function(a,b){this._modes=d(a._modes,b._modes)},f.prototype._mkLeds=function(a,b){this._leds=d(a._leds,b._leds)},f.prototype._mkSize=function(a,b){a.columns===b.columns&&a.rows===b.rows||(this._rows=b.rows,this._columns=b.columns)},f.prototype._mkTabs=function(a,b){this._tabs=b._tabs.slice()},f.prototype._getChange=function(a){for(var b={l:a},c=this._changes.length-1;c>=0;c--){if(this._changes[c].l===a)return this._changes[c];if(this._changes[c].l<a)return this._changes.splice(c+1,0,b),b}return this._changes.unshift(b),b},f.prototype._cmpLines=function(a,b){return a===b||void 0!==a&&void 0!==b&&(a.str===b.str&&(e(a.attr,b.attr)&&e(b.attr,a.attr)))},f.prototype._mkDiff=function(a,b){var c,d,e,f,g,h,i=Math.max(1,a.getBufferRowCount()),j=Math.max(1,b.getBufferRowCount()),k=-i,l=-1+k,m=new Array(i*j),n=m.slice(0);for(c=0;c<m.length;c++){d=c%i,e=~~(c/i);this._cmpLines(a.getLine(d),b.getLine(e))?n[c]=l:m[c+-1]<=m[c+k]?n[c]=k:n[c]=-1,m[c]=~~(l===n[c])+~~(0===d?0:m[c+n[c]])}for(e=j-1,d=i-1,c=m.length-1;c>=0;d--,e--,c+=n[c]){for(;!isNaN(c)&&n[c]!==l;c+=n[c]);for(g=c%i,h=~~(c/i),isNaN(c)&&(g=h=-1);e>h;d=Math.max(d-1,g),e--)this._getChange(e)[d>g?".":"+"]=b.getLine(e);for(;d>g;d--)f=this._getChange(h+1),f["-"]=(f["-"]||0)+1;0!==d||n[c]!==l&&-1!==n[c]||(n[c]=k)}},f.prototype.toJSON=function(){return{changes:this._changes,cursor:this._cursor,savedCursor:this._savedCursor,leds:this._leds,modes:this._modes,size:this._size,tabs:this._tabs,scrollRegion:this._scrollRegion}},f.prototype.toString=function(){var a,b,c=[],d=0,e=this._changes[0]?this._changes[0].l:0;for(a=0;a<this._changes.length;a++,d++,e++){for(;d<this._changes[a].l;d++,e++)c.push(" "+this.newState.getLine(d).str);for(b=0;b<this._changes[a]["-"];b++)c.push("-"+this.oldState.getLine(e).str);this._changes[a]["+"]&&(c.push("+"+this._changes[a]["+"].str),e--),this._changes[a]["."]&&c.push("."+this._changes[a]["."].str)}return c.join("\n")},f.prototype._loadJson=function(a){this._cursor=a.cursor,this._savedCursor=a.savedCursor,this._scrollRegion=a.scrollRegion,this._modes=a.modes,this._leds=a.leds,this._rows=a.rows,this._columns=a.columns,this._changes=a.changes,this._tabs=a.tabs},f.prototype.apply=function(a){(this._columns||this._rows)&&this._applySize(a),this._cursor&&this._applyCursor(a),this._scrollRegion&&this._applyScrollRegion(a),this._leds&&this._applyLeds(a),this._tabs&&this._applyTabs(a),this._savedCursor&&this._applySavedCursor(a),this._modes&&this._applyModes(a),this._changes&&this._applyChanges(a)},f.prototype._applySize=function(a){a.resize({columns:this._columns,rows:this._rows})},f.prototype._applyCursor=function(a){a.setCursor(this._cursor.x,this._cursor.y)},f.prototype._applyScrollRegion=function(a){a.setScrollRegion(this._scrollRegion[0],this._scrollRegion[1])},f.prototype._applyLeds=function(a){for(var b in this._leds)a.setLed(b,this._leds[b])},f.prototype._applySavedCursor=function(a){a._savedCursor.x=this._savedCursor.x,a._savedCursor.y=this._savedCursor.y},f.prototype._applyTabs=function(a){a.tabs=this._tabs.slice()},f.prototype._applyModes=function(a){for(var b in this._modes)a.setMode(b,this._modes[b])},f.prototype._applyChanges=function(a){for(var b=0;b<this._changes.length;b++){var c=this._changes[b];c["-"]&&a._removeLine(c.l,c["-"]),c["+"]?a._insertLine(c.l,c["+"]):c["."]&&a.setLine(c.l,c["."])}}},{"./util.js":24}],22:[function(a,b,c){"use strict";function d(a){return function(b,c){!0===this["_"+a+"sUsed"]&&(this["_"+a+"s"]=f.extend({},this["_"+a+"s"]),this["_"+a+"sUsed"]=!1);var d=this["_"+a+"s"];if(!(b in d))throw new Error("Unknown "+a+" `"+b+"`");this.emit(a+"change",b,c,d[b]),d[b]=c}}function e(a){e.super_.call(this,{decodeStrings:!1}),a=f.extend({attributes:{}},a),this._defaultAttr=f.extend({fg:null,bg:null,bold:!1,underline:!1,italic:!1,blink:!1,inverse:!1},a.attributes),this._attributesUsed=!0,this.rows=~~a.rows||24,this.columns=~~a.columns||80,this.on("newListener",this._newListener).on("removeListener",this._removeListener).on("pipe",this._pipe),this.reset()}var f=a("./util.js"),g=a("util").inherits,h=f.getWidth,i=f.indexOfWidth,j=f.substrWidth,k={"`":"◆",a:"▒",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:"≥","{":"π","|":"≠","}":"£","~":"·"};g(e,a("stream").Writable),b.exports=e,e.prototype._pipe=function(a){var b=a.emit.bind(a,"resize");this.on("resize",b).on("unpipe",function(a){a.removeListener("resize",b)})},e.prototype._newListener=function(a,b){var c;switch(a){case"lineinsert":for(c=0;c<this.getBufferRowCount();c++)b.call(this,c,this.getLine(c));break;case"resize":b.call(this,{columns:this.columns,rows:this.rows});break;case"cursormove":b.call(this,this.cursor.x,this.cursor.y)}},e.prototype._removeListener=function(a,b){var c;if("lineremove"===a)for(c=0;c<this.getBufferRowCount();c++)b.call(this,0,this.getLine(c))},e.prototype.reset=function(){this._buffer&&this._removeLine(0,this.getBufferRowCount()),this._buffer=this._defBuffer={str:[],attr:[]},this._altBuffer={str:[],attr:[]},this._scrollback={str:[],attr:[]},this._modes={cursor:!0,cursorBlink:!1,appKeypad:!1,wrap:!0,insert:!1,crlf:!1,mousebtn:!1,mousemtn:!1,mousesgr:!1,reverse:!1,graphic:!1,stringWidth:"length"},this._charsets={G0:"unicode",G1:"unicode",G2:"unicode",G3:"unicode"},this._mappedCharset="G0",
this._mappedCharsetNext="G0",this._metas={title:"",icon:""},this.resetAttribute(),this.cursor={x:0,y:0},this._savedCursor={x:0,y:0},this._scrollRegion=[0,this.rows-1],this.resetLeds(),this._tabs=[]},e.prototype._createLine=function(a){if(void 0===a||"object"!=typeof a)a=a?a.toString():"",a={str:a,attr:{0:this._defaultAttr}};else if(!a||"string"!=typeof a.str||"object"!=typeof a.attr)throw new Error("line objects must contain attr and str"+a);for(var b in a.attr)isNaN(b)||(b>a.str.length||void 0===a.attr[b])&&delete a.attr[b];return a},e.prototype._write=function(a,b,c){var d,e,f,g=a.split("\n"),k=this._modes.stringWidth,l=!1,m=this.cursor;for(d=0;d<g.length;d++)l=!1,h(k,g[d])>this.columns-m.x&&(this._modes.wrap?(e=i(k,g[d],this.columns-m.x),g.splice(d,1,j(k,g[d],0,this.columns-m.x),g[d].substr(e)),l=!0):(f=g[d].substr(-1),m.x>=this.columns&&(m.x=this.columns-h(k,f)),g[d]=j(k,g[d],0,this.columns-m.x-h(k,f))+f)),this._lineInject(g[d],l),d+1!==g.length&&(m.y++,(this._modes.crlf||l)&&(m.x=0),m.y>this._scrollRegion[1]&&(m.y--,this._removeLine(this._scrollRegion[0]),this._insertLine(this._scrollRegion[1])));return this.setCursor(),c()},e.prototype.mapCharset=function(a,b){this._mappedCharset=a,b||(this._mappedCharsetNext=a),this._modes.graphic="graphics"===this._charsets[this._mappedCharset]},e.prototype.selectCharset=function(a,b){b||(b=this._mappedCharset),this._charsets[b]=a,this._modes.graphic="graphics"===this._charsets[this._mappedCharset]},e.prototype._graphConvert=function(a){if(this._mappedCharset===this._mappedCharsetNext&&!this._modes.graphic)return a;var b,c="";for(b=0;b<a.length;b++)c+=this._modes.graphic&&a[b]in k?k[a[b]]:a[b],this._mappedCharset=this._mappedCharsetNext,this._modes.graphic="graphics"===this._charsets[this._mappedCharset];return c},e.prototype._lineInject=function(a,b){var c,d=this.cursor,e=this.getLine(),g=this._modes.stringWidth;this._modes.insert?(c=new Array(a.length),c.unshift(e.attr,e.str.length+1,d.x,0),f.objSplice.apply(0,c),e.str=j(g,e.str,0,d.x)+f.repeat(" ",d.x-h(g,e.str))+this._graphConvert(a)+j(g,e.str,d.x),e.str=j(g,e.str,0,this.columns)):e.str=j(g,e.str,0,d.x)+f.repeat(" ",d.x-h(g,e.str))+this._graphConvert(a)+j(g,e.str,d.x+h(g,a)),this._applyAttributes(e,d.x,a.length),b&&(e.attr.wrapped=!0),this.setLine(d.y,e),d.x+=h(g,a)},e.prototype.removeChar=function(a){var b=this.cursor,c=this.getLine(b.y),d=c.attr[c.str.length];f.objSplice(c.attr,c.str.length+1,b.x,a),c.str=c.str.substr(0,b.x)+c.str.substr(b.x+a),c.attr[c.str.length]=d,this.setLine(b.y,c)},e.prototype.insertBlank=function(a){var b=this.cursor,c=this.getLine(b.y),d=c.attr[c.str.length];f.objSplice(c.attr,c.str.length+1,b.x,0,new Array(a)),f.objSplice(c.attr,c.str.length+1,this.columns),c.str=c.str.substr(0,b.x)+f.repeat(" ",a)+c.str.substr(b.x),c.str=c.str.substr(0,this.columns),c.attr[c.str.length]=d,this.setLine(b.y,c)},e.prototype.removeLine=function(a){this._removeLine(this.cursor.y,+a),this._scrollRegion[1]!==this.rows-1&&this.cursor.y<=this._scrollRegion[1]&&this._insertLine(this._scrollRegion[1]+1-a,+a)},e.prototype._removeLine=function(a,b){var c,d,e;for(void 0===b&&(b=1),d=this._buffer.str.splice(a,b),this._scrollback.str.push.call(this._scrollback,d),e=this._buffer.attr.splice(a,b),this._scrollback.attr.push.call(this._scrollback,e),c=0;c<d.length;c++)this.emit("lineremove",a,{str:d[c],attr:e[c]});return b},e.prototype.setLine=function(a,b){"object"==typeof a&&void 0===b&&(b=a,a=this.cursor.y),b=this._createLine(b),this._buffer.str.length<=a?this._insertLine(a,b):(b.str.length>this.columns&&(b.attr[this.columns]=b.attr[b.str.length]),this._buffer.str[a]=b.str.substr(0,this.columns),this._buffer.attr[a]=b.attr,this.emit("linechange",a,b))},e.prototype.insertLine=function(a){this._insertLine(this.cursor.y,+a)},e.prototype._insertLine=function(a,b){var c,d=this.getBufferRowCount(),e=Math.min(d,a),f=a+1;for("number"==typeof b&&(f=a+b,b=void 0),c=e;c<f;c++)this.rows===this.getBufferRowCount()&&this._removeLine(this._scrollRegion[1],1),b=this._createLine(b),this._buffer.str.splice(e,0,b.str),this._buffer.attr.splice(e,0,b.attr),this.emit("lineinsert",e,b),b=void 0},e.prototype._applyAttributes=function(a,b,c){var d,e,f,g,h;for(d=b+c;d>0&&void 0===a.attr[d];d--);for(e=a.attr[d],g=b-1;g>0&&void 0===a.attr[g];g--);for(f=a.attr[g],h=b;h<b+c;h++)delete a.attr[h];return f===this._attributes&&b!==a.str.length||(a.attr[b]=this._attributes),b+c<=this.columns&&(a.attr[b+c]=e),this._attributesUsed=!0,this},e.prototype.setCursor=function(a,b){var c=this.cursor;return"number"!=typeof a&&(a=c.x),"number"!=typeof b&&(b=c.y),a<0?a=0:a>this.columns&&(a=this.columns),b<0?b=0:b>=this.rows&&(b=this.rows-1),c.x===a&&c.y===b&&0!==arguments.length||(c.x=a,c.y=b,this.emit("cursormove",a,b)),this},e.prototype.resize=function(a){var b=this.cursor,c=Math.max(0,this.rows-a.rows),d=this.rows-b.y-1,e=Math.min(c,d),f=c-e;return this._removeLine(this.rows-e,e),this._removeLine(0,f),this.rows=~~a.rows,this.columns=~~a.columns,this.redraw(),this.setScrollRegion(0,this.rows-1),this.emit("resize",{rows:this.rows,columns:this.columns}),this.setCursor(),this},e.prototype.redraw=function(){for(var a=0;a<this._buffer.str.length;a++)this.setLine(a,this.getLine(a))},e.prototype.mvCursor=function(a,b){return(a||b)&&this.setCursor(this.cursor.x+a,this.cursor.y+b),this},e.prototype.scroll=function(a){var b,c=Math.min(Math.abs(a),this._scrollRegion[1]-this._scrollRegion[0]);if(a>0)for(this._removeLine(this._scrollRegion[0],c),b=0;b<c;b++)this._insertLine(this._scrollRegion[1]+1-c);else for(this._removeLine(this._scrollRegion[1]+1-c,c),b=0;b<c;b++)this._insertLine(this._scrollRegion[0])},e.prototype.toString=function(){return this._buffer.str.join("\n")},e.prototype.prevLine=function(){return this.cursor.y===this._scrollRegion[0]?this.scroll(-1):this.mvCursor(0,-1),this},e.prototype.nextLine=function(){return this.cursor.y===this._scrollRegion[1]?this.scroll(1):this.mvCursor(0,1),this},e.prototype.resetAttribute=function(a){return a?this.setAttribute(a,this._defaultAttr[a]):(this._attributesUsed=!0,this._attributes=this._defaultAttr),this},e.prototype.saveCursor=function(){return this._savedCursor.x=this.cursor.x,this._savedCursor.y=this.cursor.y,this},e.prototype.restoreCursor=function(){return this.setCursor(this._savedCursor.x,this._savedCursor.y)},e.prototype.eraseCharacters=function(a){var b=this.cursor,c=this.getLine(b.y);c.str=c.str.substr(0,b.x)+f.repeat(" ",a)+c.str.substr(b.x+a),c.str=c.str.substr(0,this.columns),this._applyAttributes(c,b.x,a),this.setLine(b.y,c)},e.prototype.eraseInDisplay=function(a){var b,c,d=this.cursor,e=this,f=function(){c=e._createLine(),e._applyAttributes(c,0,e.columns),e.setLine(b,c)};switch(a||0){case"below":case"after":case 0:for(a=0,b=d.y+1;b<this.rows;b++)f();break;case"above":case"before":case 1:for(a=1,b=0;b<d.y-1;b++)f();break;case"all":case 2:for(b=0;b<this.rows;b++)f();return this}return this.eraseInLine(a)},e.prototype.eraseInLine=function(a){var b=this.cursor,c=this.getLine();switch(a||0){case"after":case 0:c.str=c.str.substr(0,b.x),this._applyAttributes(c,b.x,this.columns);break;case"before":case 1:c.str=f.repeat(" ",b.x)+c.str.substr(b.x),this._applyAttributes(c,0,b.x);break;case"all":case 2:c=this._createLine()}return this.setLine(b.y,c),this},e.prototype.setScrollRegion=function(a,b){return this._scrollRegion[0]=+a,this._scrollRegion[1]=+b,this},e.prototype.switchBuffer=function(a){var b,c,d;if(a?(c=this._altBuffer,d=this._defBuffer):(c=this._defBuffer,d=this._altBuffer),c!==this._buffer){for(b=c.str.length;b<d.str.length;b++)this.emit("lineremove",c.str.length,this.getLine(b));for(this._buffer=c,b=0;b<c.str.length&&b<d.str.length;b++)this.emit("linechange",c.str.length,this.getLine(b));for(;b<c.str.length;b++)this.emit("lineinsert",b,this.getLine(b));return this}},e.prototype.ledOn=function(a){return this.setLed(a,!0),this},e.prototype.setLed=function(a,b){return a<this._leds.length&&(this._leds[a]=!!b,this.emit("ledchange",Array.apply(null,this._leds))),this},e.prototype.resetLeds=function(){return this._leds=[!1,!1,!1,!1],this.emit("ledchange",Array.apply(null,this._leds)),this},e.prototype.getBufferRowCount=function(){return this._buffer.str.length},e.prototype.getLed=function(a){return this._leds[a]},e.prototype.getLine=function(a){return void 0===a&&(a=this.cursor.y),void 0!==this._buffer.str[a]?{str:this._buffer.str[a],attr:this._buffer.attr[a]}:this._createLine()},e.prototype.getMode=function(a){return this._modes[a]},e.prototype.mvTab=function(a){var b=this.cursor.x,c=this._tabs[this._tabs.length-1]||0,d=a>0;for(a=Math.abs(a);0!==a&&b>=0&&b<this.columns-1;)b+=d?1:-1,(~f.indexOf(this._tabs,b)||b>c&&b%8==0)&&a--;this.setCursor(b)},e.prototype.setTab=function(a){void 0===a&&(a=this.cursor.x),~f.indexOf(this._tabs,a)||(this._tabs.push(a),this._tabs.sort())},e.prototype.removeTab=function(a){var b,c=this._tabs;for(b=0;b<c.length&&c[b]!==a;b++);c.splice(b,1)},e.prototype.tabClear=function(a){switch(a||"current"){case"current":case 0:for(var b=this._tabs.length-1;b>=0;b--)if(this._tabs[b]<this.cursor.x){this._tabs.splice(b,1);break}break;case"all":case 3:this._tabs=[]}},e.prototype.setAttribute=d("attribute"),e.prototype.setMode=d("mode"),e.prototype.setMeta=d("meta")},{"./util.js":24,stream:54,util:59}],23:[function(a,b,c){"use strict";function d(a){d.super_.call(this,{decodeStrings:!1}),this.options=f.extend({columns:80,rows:24,attributes:{}},a||{}),this.rows=~~this.rows,this.columns=~~this.columns,this.state=new g(this.options),this.oldChunk=null,this.on("pipe",this._pipe)}var e=a("util").inherits,f=a("./util"),g=a("./term_state.js"),h=a("./output/dom.js"),i=a("./input/dom.js"),j={plain:a("./output/plain.js"),html:a("./output/html.js"),ansi:a("./output/ansi.js")},k=/^\x1b\[([?!>]?)([0-9;]*)([@A-Za-z`]?)/,l=/^\x1bP([0-9;@A-Za-z`]*)\x1b\\/,m=/^\x1b\]([0-9]*);([^\x07]*)(\x07?)/;e(d,a("stream").Writable),b.exports=d,d.prototype.handlers={chr:a("./handler/chr.js"),esc:a("./handler/esc.js"),csi:a("./handler/csi.js"),sgr:a("./handler/sgr.js"),dcs:a("./handler/dcs.js"),mode:a("./handler/mode.js"),osc:a("./handler/osc.js")},d.prototype._pipe=function(a){var b=function(b){"function"==typeof a.resize&&a.resize(b.columns,b.rows),a.emit("resize",b)};this.on("resize",b).on("unpipe",function(a){a.removeListener("resize",b)})},d.prototype._write=function(a,b,c){var d=1;for("string"!=typeof a&&(a=a.toString()),null!==this.oldChunk&&(a=this.oldChunk+a,this.oldChunk=null);a.length>0&&d>0;){if(null===(d=this.callHandler("chr",a[0],a))){for(d=1;d<a.length&&!(a[d]in this.handlers.chr);d++);this.state.write(a.substr(0,d))}d>0&&(a=a.slice(d))}0!==a.length&&(this.oldChunk=a),this.emit("ready"),c()},d.prototype.callHandler=function(a,b){var c,d=Array.prototype.slice.call(arguments,1);return a in this.handlers&&b in this.handlers[a]?("string"==typeof this.handlers[a][b]&&(b=this.handlers[a][b]),c=this.handlers[a][b].apply(this,d),void 0===c?1:c):null},d.prototype.parseCsi=function(a){var b,c=k.exec(a);if(null===c)return null;var d=""===c[2]?[]:c[2].split(";");for(b=0;b<d.length;b++)d[b]=+d[b];return{args:d,mod:c[1],cmd:c[3],length:c[0].length}},d.prototype.parseOsc=function(a){var b=m.exec(a);return null===b?null:{args:b[2].split(";"),cmd:b[1],terminated:""===b[3],length:b[0].length}},d.prototype.parseDcs=function(a){var b=l.exec(a);return null===b?null:{args:[null,null],mod:b[1],cmd:b[1],length:b[0].length}},d.prototype.dom=function(a,b){var c=new i(a,this.state,b);new h(this.state,this,a,b);return c},d.prototype.toString=function(a){return"string"!=typeof a?this.state.toString.apply(this.state,arguments):new j[a](this.state).toString()}},{"./handler/chr.js":2,"./handler/csi.js":3,"./handler/dcs.js":4,"./handler/esc.js":5,"./handler/mode.js":6,"./handler/osc.js":7,"./handler/sgr.js":8,"./input/dom.js":10,"./output/ansi.js":12,"./output/dom.js":14,"./output/html.js":15,"./output/plain.js":17,"./term_state.js":22,"./util":24,stream:54,util:59}],24:[function(a,b,c){"use strict";function d(a,b){var c,d="";for(c=0;c<b;c++)d+=a;return d}function e(a){return a.split("").reduce(function(a,b){return a+(b.charCodeAt(0)>255?2:1)},0)}function f(a,b){if(!a||!a.toLowerCase)return b.length;switch(a.toLowerCase()){case"wcwidth":return i(b);case"dbcs":return e(b);case"length":default:return b.length}}function g(a,b,c){if(!1===a)return c;for(var d=0;d<=b.length;d++)if(f(a,b.substr(0,d))>c)return d-1;return b.length}function h(a,b,c,e){var h,i=e,j=c,k=0;return!1!==a&&(j=g(a,b,c),f(a,b.substr(0,j))<c&&(j++,k=f(a,b.substr(0,j))-c),i=g(a,b.substr(j),e-k),h=Math.min(e,f(a,b.substr(j)))-(k+f(a,b.substr(j,i)))),d(" ",k)+b.substr(j,i)+d(" ",h)}var i=a("wcwidth"),j=Array.prototype;c.extend=function(a){for(var b=1;b<arguments.length;b++)for(var c in arguments[b])a[c]=arguments[b][c];return a},c.repeat=d,c.objSplice=function(a,b,c,d,e){var f=j.splice,g=[c,d];j.push.apply(g,e),a.length=b,f.apply(a,g),delete a.length},c.indexOf=j.indexOf?function(){var a=j.slice.call(arguments);return j.indexOf.apply(a.shift(),a)}:function(a,b){for(var c=0;c<this.length;c++)if(this[c]===b)return c;return-1},c.getWidth=f,c.indexOfWidth=g,c.substrWidth=h},{wcwidth:61}],25:[function(a,b,c){"use strict";function d(a){var b=a.length;if(b%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var c=a.indexOf("=");return-1===c&&(c=b),[c,c===b?0:4-c%4]}function e(a){var b=d(a),c=b[0],e=b[1];return 3*(c+e)/4-e}function f(a,b,c){return 3*(b+c)/4-c}function g(a){var b,c,e=d(a),g=e[0],h=e[1],i=new m(f(a,g,h)),j=0,k=h>0?g-4:g;for(c=0;c<k;c+=4)b=l[a.charCodeAt(c)]<<18|l[a.charCodeAt(c+1)]<<12|l[a.charCodeAt(c+2)]<<6|l[a.charCodeAt(c+3)],i[j++]=b>>16&255,i[j++]=b>>8&255,i[j++]=255&b;return 2===h&&(b=l[a.charCodeAt(c)]<<2|l[a.charCodeAt(c+1)]>>4,i[j++]=255&b),1===h&&(b=l[a.charCodeAt(c)]<<10|l[a.charCodeAt(c+1)]<<4|l[a.charCodeAt(c+2)]>>2,i[j++]=b>>8&255,i[j++]=255&b),i}function h(a){return k[a>>18&63]+k[a>>12&63]+k[a>>6&63]+k[63&a]}function i(a,b,c){for(var d,e=[],f=b;f<c;f+=3)d=(a[f]<<16&16711680)+(a[f+1]<<8&65280)+(255&a[f+2]),e.push(h(d));return e.join("")}function j(a){for(var b,c=a.length,d=c%3,e=[],f=0,g=c-d;f<g;f+=16383)e.push(i(a,f,f+16383>g?g:f+16383));return 1===d?(b=a[c-1],e.push(k[b>>2]+k[b<<4&63]+"==")):2===d&&(b=(a[c-2]<<8)+a[c-1],e.push(k[b>>10]+k[b>>4&63]+k[b<<2&63]+"=")),e.join("")}c.byteLength=e,c.toByteArray=g,c.fromByteArray=j;for(var k=[],l=[],m="undefined"!=typeof Uint8Array?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,p=n.length;o<p;++o)k[o]=n[o],l[n.charCodeAt(o)]=o;l["-".charCodeAt(0)]=62,l["_".charCodeAt(0)]=63},{}],26:[function(a,b,c){},{}],27:[function(a,b,c){(function(b){(function(){"use strict";function b(a){if(a>W)throw new RangeError('The value "'+a+'" is invalid for option "size"');var b=new Uint8Array(a);return b.__proto__=d.prototype,b}function d(a,b,c){if("number"==typeof a){if("string"==typeof b)throw new TypeError('The "string" argument must be of type string. Received type number');return h(a)}return e(a,b,c)}function e(a,b,c){if("string"==typeof a)return i(a,b);if(ArrayBuffer.isView(a))return j(a);if(null==a)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof a);if(S(a,ArrayBuffer)||a&&S(a.buffer,ArrayBuffer))return k(a,b,c);if("number"==typeof a)throw new TypeError('The "value" argument must not be of type number. Received type number');var e=a.valueOf&&a.valueOf();if(null!=e&&e!==a)return d.from(e,b,c);var f=l(a);if(f)return f;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof a[Symbol.toPrimitive])return d.from(a[Symbol.toPrimitive]("string"),b,c);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof a)}function f(a){if("number"!=typeof a)throw new TypeError('"size" argument must be of type number');if(a<0)throw new RangeError('The value "'+a+'" is invalid for option "size"')}function g(a,c,d){return f(a),a<=0?b(a):void 0!==c?"string"==typeof d?b(a).fill(c,d):b(a).fill(c):b(a)}function h(a){return f(a),b(a<0?0:0|m(a))}function i(a,c){if("string"==typeof c&&""!==c||(c="utf8"),!d.isEncoding(c))throw new TypeError("Unknown encoding: "+c);var e=0|o(a,c),f=b(e),g=f.write(a,c);return g!==e&&(f=f.slice(0,g)),f}function j(a){for(var c=a.length<0?0:0|m(a.length),d=b(c),e=0;e<c;e+=1)d[e]=255&a[e];return d}function k(a,b,c){if(b<0||a.byteLength<b)throw new RangeError('"offset" is outside of buffer bounds');if(a.byteLength<b+(c||0))throw new RangeError('"length" is outside of buffer bounds');var e;return e=void 0===b&&void 0===c?new Uint8Array(a):void 0===c?new Uint8Array(a,b):new Uint8Array(a,b,c),e.__proto__=d.prototype,e}function l(a){if(d.isBuffer(a)){var c=0|m(a.length),e=b(c);return 0===e.length?e:(a.copy(e,0,0,c),e)}return void 0!==a.length?"number"!=typeof a.length||T(a.length)?b(0):j(a):"Buffer"===a.type&&Array.isArray(a.data)?j(a.data):void 0}function m(a){if(a>=W)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+W.toString(16)+" bytes");return 0|a}function n(a){return+a!=a&&(a=0),d.alloc(+a)}function o(a,b){if(d.isBuffer(a))return a.length;if(ArrayBuffer.isView(a)||S(a,ArrayBuffer))return a.byteLength;if("string"!=typeof a)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof a);var c=a.length,e=arguments.length>2&&!0===arguments[2];if(!e&&0===c)return 0;for(var f=!1;;)switch(b){case"ascii":case"latin1":case"binary":return c;case"utf8":case"utf-8":return N(a).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*c;case"hex":return c>>>1;case"base64":return Q(a).length;default:if(f)return e?-1:N(a).length;b=(""+b).toLowerCase(),f=!0}}function p(a,b,c){var d=!1;if((void 0===b||b<0)&&(b=0),b>this.length)return"";if((void 0===c||c>this.length)&&(c=this.length),c<=0)return"";if(c>>>=0,b>>>=0,c<=b)return"";for(a||(a="utf8");;)switch(a){case"hex":return E(this,b,c)