UNPKG

neo-neo-bblessed

Version:

A fork of neo-blessed (which is a fork of blessed) with bug fixes and maintenance.

8 lines (7 loc) 46.2 kB
var _=require("events").EventEmitter,x=require("string_decoder").StringDecoder,M=require("child_process"),l=require("util"),v=require("fs"),C=require("./tput"),w=require("./colors"),p=Array.prototype.slice,b=global.setImmediate||process.nextTick.bind(process);function r(t){var e=this;if(!(this instanceof r))return new r(t);r.bind(this),_.call(this),(!t||t.__proto__!==Object.prototype)&&(t={input:arguments[0],output:arguments[1]}),this.options=t,this.input=t.input||process.stdin,this.output=t.output||process.stdout,t.log=t.log||t.dump,t.log&&(this._logger=v.createWriteStream(t.log),t.dump&&this.setupDump()),this.zero=t.zero!==!1,this.useBuffer=t.buffer,this.x=0,this.y=0,this.savedX=0,this.savedY=0,this.cols=this.output.columns||1,this.rows=this.output.rows||1,this.scrollTop=0,this.scrollBottom=this.rows-1,this._terminal=t.terminal||t.term||process.env.TERM||(process.platform==="win32"?"windows-ansi":"xterm"),this._terminal=this._terminal.toLowerCase(),this.isOSXTerm=process.env.TERM_PROGRAM==="Apple_Terminal",this.isiTerm2=process.env.TERM_PROGRAM==="iTerm.app"||!!process.env.ITERM_SESSION_ID,this.isXFCE=/xfce/i.test(process.env.COLORTERM),this.isTerminator=!!process.env.TERMINATOR_UUID,this.isLXDE=!1,this.isVTE=!!process.env.VTE_VERSION||this.isXFCE||this.isTerminator||this.isLXDE,this.isRxvt=/rxvt/i.test(process.env.COLORTERM),this.isXterm=!1,this.tmux=!!process.env.TMUX,this.tmuxVersion=function(){if(!e.tmux)return 2;try{var i=M.execFileSync("tmux",["-V"],{encoding:"utf8"});return+/^tmux ([\d.]+)/i.exec(i.trim().split(` `)[0])[1]}catch(s){return 2}}(),this._buf="",this._flush=this.flush.bind(this),t.tput!==!1&&this.setupTput(),this.listen()}r.global=null,r.total=0,r.instances=[],r.bind=function(t){r.global||(r.global=t),~r.instances.indexOf(t)||(r.instances.push(t),t.index=r.total,r.total++),!r._bound&&(r._bound=!0,k(process,"exit",r._exitHandler=function(){r.instances.forEach(function(e){e.flush(),e._exiting=!0})}))},r.prototype.__proto__=_.prototype,r.prototype.type="program",r.prototype.log=function(...t){return this._log("LOG",l.format.apply(l,arguments))},r.prototype.debug=function(...t){if(this.options.debug)return this._log("DEBUG",l.format.apply(l,arguments))},r.prototype._log=function(t,e){if(this._logger)return this._logger.write(t+": "+e+` - `)},r.prototype.setupDump=function(){var t=this,e=this.output.write,i=new x("utf8");function s(n){return o(n.replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")).replace(/[^ -~]/g,function(u){return u.charCodeAt(0)>255?u:(u=u.charCodeAt(0).toString(16),u.length>2?(u.length<4&&(u="0"+u),"\\u"+u):(u.length<2&&(u="0"+u),"\\x"+u))})}function o(n){return n.replace(/[\0\x80\x1b-\x1f\x7f\x01-\x1a]/g,function(u){switch(u){case"\0":case"\x80":u="@";break;case"\x1B":u="[";break;case"":u="\\";break;case"":u="]";break;case"":u="^";break;case"":u="_";break;case"\x7F":u="?";break;default:if(u=u.charCodeAt(0),u>=1&&u<=26)u=String.fromCharCode(u+64);else return String.fromCharCode(u);break}return"^"+u})}this.input.on("data",function(n){t._log("IN",s(i.write(n)))}),this.output.write=function(n){return t._log("OUT",s(n)),e.apply(this,arguments)}},r.prototype.setupTput=function(){if(!this._tputSetup){this._tputSetup=!0;var t=this,e=this.options,i=this._write.bind(this),s=this.tput=new C({terminal:this.terminal,padding:e.padding,extended:e.extended,printf:e.printf,termcap:e.termcap,forceUnicode:e.forceUnicode});s.error&&b(function(){t.emit("warning",s.error.message)}),s.padding&&b(function(){t.emit("warning","Terminfo padding has been enabled.")}),this.put=function(){var o=p.call(arguments),n=o.shift();if(s[n])return this._write(s[n].apply(s,o))},Object.keys(s).forEach(function(o){if(t[o]==null&&(t[o]=s[o]),typeof s[o]!="function"){t.put[o]=s[o];return}s.padding?t.put[o]=function(){return s._print(s[o].apply(s,arguments),i)}:t.put[o]=function(){return t._write(s[o].apply(s,arguments))}})}},r.prototype.__defineGetter__("terminal",function(){return this._terminal}),r.prototype.__defineSetter__("terminal",function(t){return this.setTerminal(t),this.terminal}),r.prototype.setTerminal=function(t){this._terminal=t.toLowerCase(),delete this._tputSetup,this.setupTput()},r.prototype.has=function(t){return this.tput?this.tput.has(t):!1},r.prototype.term=function(t){return this.terminal.indexOf(t)===0},r.prototype.listen=function(){var t=this;this.input._blessedInput?this.input._blessedInput++:(this.input._blessedInput=1,this._listenInput()),this.on("newListener",this._newHandler=function e(i){(i==="keypress"||i==="mouse")&&(t.removeListener("newListener",e),t.input.setRawMode&&!t.input.isRaw&&(t.input.setRawMode(!0),t.input.resume()))}),this.on("newListener",function e(i){i==="mouse"&&(t.removeListener("newListener",e),t.bindMouse())}),this.output._blessedOutput?this.output._blessedOutput++:(this.output._blessedOutput=1,this._listenOutput())},r.prototype._listenInput=function(){var t=require("./keys"),e=this;this.input.on("keypress",this.input._keypressHandler=function(i,s){if(s=s||{ch:i},!(s.name==="undefined"&&(s.code==="[M"||s.code==="[I"||s.code==="[O"))&&s.name!=="undefined"){s.name==="enter"&&s.sequence===` `&&(s.name="linefeed"),s.name==="return"&&s.sequence==="\r"&&e.input.emit("keypress",i,E({},s,{name:"enter"}));var o=(s.ctrl?"C-":"")+(s.meta?"M-":"")+(s.shift&&s.name?"S-":"")+(s.name||i);s.full=o,r.instances.forEach(function(n){n.input===e.input&&(n.emit("keypress",i,s),n.emit("key "+o,i,s))})}}),this.input.on("data",this.input._dataHandler=function(i){r.instances.forEach(function(s){s.input===e.input&&s.emit("data",i)})}),t.emitKeypressEvents(this.input)},r.prototype._listenOutput=function(){var t=this;this.output.isTTY||b(function(){t.emit("warning","Output is not a TTY")});function e(){r.instances.forEach(function(i){i.output===t.output&&(i.cols=i.output.columns,i.rows=i.output.rows,i.emit("resize"))})}this.output.on("resize",this.output._resizeHandler=function(){r.instances.forEach(function(i){if(i.output===t.output){if(!i.options.resizeTimeout)return e();i._resizeTimer&&(clearTimeout(i._resizeTimer),delete i._resizeTimer);var s=typeof i.options.resizeTimeout=="number"?i.options.resizeTimeout:300;i._resizeTimer=setTimeout(e,s)}})})},r.prototype.destroy=function(){var t=r.instances.indexOf(this);~t&&(r.instances.splice(t,1),r.total--,this.flush(),this._exiting=!0,r.global=r.instances[0],r.total===0&&(r.global=null,process.removeListener("exit",r._exitHandler),delete r._exitHandler,delete r._bound),this.input._blessedInput--,this.output._blessedOutput--,this.input._blessedInput===0&&(this.input.removeListener("keypress",this.input._keypressHandler),this.input.removeListener("data",this.input._dataHandler),delete this.input._keypressHandler,delete this.input._dataHandler,this.input.setRawMode&&(this.input.isRaw&&this.input.setRawMode(!1),this.input.destroyed||this.input.pause())),this.output._blessedOutput===0&&(this.output.removeListener("resize",this.output._resizeHandler),delete this.output._resizeHandler),this.removeListener("newListener",this._newHandler),delete this._newHandler,this.destroyed=!0,this.emit("destroy"))},r.prototype.key=function(t,e){typeof t=="string"&&(t=t.split(/\s*,\s*/)),t.forEach(function(i){return this.on("key "+i,e)},this)},r.prototype.onceKey=function(t,e){typeof t=="string"&&(t=t.split(/\s*,\s*/)),t.forEach(function(i){return this.once("key "+i,e)},this)},r.prototype.unkey=r.prototype.removeKey=function(t,e){typeof t=="string"&&(t=t.split(/\s*,\s*/)),t.forEach(function(i){return this.removeListener("key "+i,e)},this)},r.prototype.bindMouse=function(){if(!this._boundMouse){this._boundMouse=!0;var t=new x("utf8"),e=this;this.on("data",function(i){var s=t.write(i);s&&e._bindMouse(s,i)})}},r.prototype._bindMouse=function(t,e){var i=this,s,o,n,u,h,a,c,y,g,f;s={name:void 0,ctrl:!1,meta:!1,shift:!1},Buffer.isBuffer(t)&&(t[0]>127&&t[1]===void 0?(t[0]-=128,t="\x1B"+t.toString("utf-8")):t=t.toString("utf-8"));var d=t.charCodeAt(4),m=t.charCodeAt(5);if(e[0]===27&&e[1]===91&&e[2]===77&&(this.isVTE||d>=65533||m>=65533||d>0&&d<32||m>0&&m<32||e[4]>223&&e[4]<248&&e.length===6||e[5]>223&&e[5]<248&&e.length===6)&&(n=e[3],u=e[4],h=e[5],u<32&&(u+=255),h<32&&(h+=255),t="\x1B[M"+String.fromCharCode(n)+String.fromCharCode(u)+String.fromCharCode(h)),o=/^\x1b\[M([\x00\u0020-\uffff]{3})/.exec(t)){n=o[1].charCodeAt(0),u=o[1].charCodeAt(1),h=o[1].charCodeAt(2),s.name="mouse",s.type="X10",s.raw=[n,u,h,o[0]],s.buf=e,s.x=u-32,s.y=h-32,this.zero&&(s.x--,s.y--),u===0&&(s.x=255),h===0&&(s.y=255),a=n>>2,s.shift=!!(a&1),s.meta=!!(a>>1&1),s.ctrl=!!(a>>2&1),n-=32,n>>6&1?(s.action=n&1?"wheeldown":"wheelup",s.button="middle"):n===3?(s.action="mouseup",s.button=this._lastButton||"unknown",delete this._lastButton):(s.action="mousedown",f=n&3,s.button=f===0?"left":f===1?"middle":f===2?"right":"unknown",this._lastButton=s.button),(n===35||n===39||n===51||n===43||this.isVTE&&(n===32||n===36||n===48||n===40))&&(delete s.button,s.action="mousemove"),i.emit("mouse",s);return}if(o=/^\x1b\[(\d+;\d+;\d+)M/.exec(t)){c=o[1].split(";"),n=+c[0],u=+c[1],h=+c[2],s.name="mouse",s.type="urxvt",s.raw=[n,u,h,o[0]],s.buf=e,s.x=u,s.y=h,this.zero&&(s.x--,s.y--),a=n>>2,s.shift=!!(a&1),s.meta=!!(a>>1&1),s.ctrl=!!(a>>2&1),(n===128||n===129)&&(n=67),n-=32,n>>6&1?(s.action=n&1?"wheeldown":"wheelup",s.button="middle"):n===3?(s.action="mouseup",s.button=this._lastButton||"unknown",delete this._lastButton):(s.action="mousedown",f=n&3,s.button=f===0?"left":f===1?"middle":f===2?"right":"unknown",this._lastButton=s.button),(n===35||n===39||n===51||n===43||this.isVTE&&(n===32||n===36||n===48||n===40))&&(delete s.button,s.action="mousemove"),i.emit("mouse",s);return}if(o=/^\x1b\[<(\d+;\d+;\d+)([mM])/.exec(t)){y=o[2]==="M",c=o[1].split(";"),n=+c[0],u=+c[1],h=+c[2],s.name="mouse",s.type="sgr",s.raw=[n,u,h,o[0]],s.buf=e,s.x=u,s.y=h,this.zero&&(s.x--,s.y--),a=n>>2,s.shift=!!(a&1),s.meta=!!(a>>1&1),s.ctrl=!!(a>>2&1),n>>6&1?(s.action=n&1?"wheeldown":"wheelup",s.button="middle"):(s.action=y?"mousedown":"mouseup",f=n&3,s.button=f===0?"left":f===1?"middle":f===2?"right":"unknown"),(n===35||n===39||n===51||n===43||this.isVTE&&(n===32||n===36||n===48||n===40))&&(delete s.button,s.action="mousemove"),i.emit("mouse",s);return}if(o=/^\x1b\[<(\d+;\d+;\d+;\d+)&w/.exec(t)){c=o[1].split(";"),n=+c[0],u=+c[1],h=+c[2],g=+c[3],s.name="mouse",s.type="dec",s.raw=[n,u,h,o[0]],s.buf=e,s.x=u,s.y=h,s.page=g,this.zero&&(s.x--,s.y--),s.action=n===3?"mouseup":"mousedown",s.button=n===2?"left":n===4?"middle":n===6?"right":"unknown",i.emit("mouse",s);return}if(o=/^\x1b\[24([0135])~\[(\d+),(\d+)\]\r/.exec(t)){n=+o[1],u=+o[2],h=+o[3],s.name="mouse",s.type="vt300",s.raw=[n,u,h,o[0]],s.buf=e,s.x=u,s.y=h,this.zero&&(s.x--,s.y--),s.action="mousedown",s.button=n===1?"left":n===2?"middle":n===5?"right":"unknown",i.emit("mouse",s);return}if(o=/^\x1b\[(O|I)/.exec(t)){s.action=o[1]==="I"?"focus":"blur",i.emit("mouse",s),i.emit(s.action);return}},r.prototype.enableGpm=function(){var t=this,e=require("./gpmclient");this.gpm||(this.gpm=e(),this.gpm.on("btndown",function(i,s,o,n){o--,n--;var u={name:"mouse",type:"GPM",action:"mousedown",button:t.gpm.ButtonName(i),raw:[i,s,o,n],x:o,y:n,shift:t.gpm.hasShiftKey(s),meta:t.gpm.hasMetaKey(s),ctrl:t.gpm.hasCtrlKey(s)};t.emit("mouse",u)}),this.gpm.on("btnup",function(i,s,o,n){o--,n--;var u={name:"mouse",type:"GPM",action:"mouseup",button:t.gpm.ButtonName(i),raw:[i,s,o,n],x:o,y:n,shift:t.gpm.hasShiftKey(s),meta:t.gpm.hasMetaKey(s),ctrl:t.gpm.hasCtrlKey(s)};t.emit("mouse",u)}),this.gpm.on("move",function(i,s,o,n){o--,n--;var u={name:"mouse",type:"GPM",action:"mousemove",button:t.gpm.ButtonName(i),raw:[i,s,o,n],x:o,y:n,shift:t.gpm.hasShiftKey(s),meta:t.gpm.hasMetaKey(s),ctrl:t.gpm.hasCtrlKey(s)};t.emit("mouse",u)}),this.gpm.on("drag",function(i,s,o,n){o--,n--;var u={name:"mouse",type:"GPM",action:"mousemove",button:t.gpm.ButtonName(i),raw:[i,s,o,n],x:o,y:n,shift:t.gpm.hasShiftKey(s),meta:t.gpm.hasMetaKey(s),ctrl:t.gpm.hasCtrlKey(s)};t.emit("mouse",u)}),this.gpm.on("mousewheel",function(i,s,o,n,u,h){var a={name:"mouse",type:"GPM",action:h>0?"wheelup":"wheeldown",button:t.gpm.ButtonName(i),raw:[i,s,o,n,u,h],x:o,y:n,shift:t.gpm.hasShiftKey(s),meta:t.gpm.hasMetaKey(s),ctrl:t.gpm.hasCtrlKey(s)};t.emit("mouse",a)}))},r.prototype.disableGpm=function(){this.gpm&&(this.gpm.stop(),delete this.gpm)},r.prototype.bindResponse=function(){if(!this._boundResponse){this._boundResponse=!0;var t=new x("utf8"),e=this;this.on("data",function(i){i=t.write(i),i&&e._bindResponse(i)})}},r.prototype._bindResponse=function(t){var e={},i;if(Buffer.isBuffer(t)&&(t[0]>127&&t[1]===void 0?(t[0]-=128,t="\x1B"+t.toString("utf-8")):t=t.toString("utf-8")),i=/^\x1b\[(\?|>)(\d*(?:;\d*)*)c/.exec(t)){if(i=i[2].split(";").map(function(s){return+s||0}),e.event="device-attributes",e.code="DA",i[1]==="?")e.type="primary-attribute",i[0]===1&&i[2]===2?(e.term="vt100",e.advancedVideo=!0):i[0]===1&&i[2]===0?e.term="vt101":i[0]===6?e.term="vt102":i[0]===60&&i[1]===1&&i[2]===2&&i[3]===6&&i[4]===8&&i[5]===9&&i[6]===15?e.term="vt220":i.forEach(function(s){switch(s){case 1:e.cols132=!0;break;case 2:e.printer=!0;break;case 6:e.selectiveErase=!0;break;case 8:e.userDefinedKeys=!0;break;case 9:e.nationalReplacementCharsets=!0;break;case 15:e.technicalCharacters=!0;break;case 18:e.userWindows=!0;break;case 21:e.horizontalScrolling=!0;break;case 22:e.ansiColor=!0;break;case 29:e.ansiTextLocator=!0;break}});else{switch(e.type="secondary-attribute",i[0]){case 0:e.term="vt100";break;case 1:e.term="vt220";break;case 2:e.term="vt240";break;case 18:e.term="vt330";break;case 19:e.term="vt340";break;case 24:e.term="vt320";break;case 41:e.term="vt420";break;case 61:e.term="vt510";break;case 64:e.term="vt520";break;case 65:e.term="vt525";break}e.firmwareVersion=i[1],e.romCartridgeRegistrationNumber=i[2]}e.deviceAttributes=e,this.emit("response",e),this.emit("response "+e.event,e);return}if(i=/^\x1b\[(\?)?(\d+)(?:;(\d+);(\d+);(\d+))?n/.exec(t)){if(e.event="device-status",e.code="DSR",!i[1]&&i[2]==="0"&&!i[3]){e.type="device-status",e.status="OK",e.deviceStatus=e.status,this.emit("response",e),this.emit("response "+e.event,e);return}if(i[1]&&(i[2]==="10"||i[2]==="11")&&!i[3]){e.type="printer-status",e.status=i[2]==="10"?"ready":"not ready",e.printerStatus=e.status,this.emit("response",e),this.emit("response "+e.event,e);return}if(i[1]&&(i[2]==="20"||i[2]==="21")&&!i[3]){e.type="udk-status",e.status=i[2]==="20"?"unlocked":"locked",e.UDKStatus=e.status,this.emit("response",e),this.emit("response "+e.event,e);return}if(i[1]&&i[2]==="27"&&i[3]==="1"&&i[4]==="0"&&i[5]==="0"){e.type="keyboard-status",e.status="OK",e.keyboardStatus=e.status,this.emit("response",e),this.emit("response "+e.event,e);return}if(i[1]&&(i[2]==="53"||i[2]==="50")&&!i[3]){e.type="locator-status",e.status=i[2]==="53"?"available":"unavailable",e.locator=e.status,this.emit("response",e),this.emit("response "+e.event,e);return}e.type="error",e.text="Unhandled: "+JSON.stringify(i),e.error=e.text,this.emit("response",e),this.emit("response "+e.event,e);return}if(i=/^\x1b\[(\?)?(\d+);(\d+)R/.exec(t)){e.event="device-status",e.code="DSR",e.type="cursor-status",e.status={x:+i[3],y:+i[2],page:i[1]?0:void 0},e.x=e.status.x,e.y=e.status.y,e.page=e.status.page,e.cursor=e.status,this.emit("response",e),this.emit("response "+e.event,e);return}if(i=/^\x1b\[(\d+)(?:;(\d+);(\d+))?t/.exec(t)){if(e.event="window-manipulation",e.code="",(i[1]==="1"||i[1]==="2")&&!i[2]){e.type="window-state",e.state=i[1]==="1"?"non-iconified":"iconified",e.windowState=e.state,this.emit("response",e),this.emit("response "+e.event,e);return}if(i[1]==="3"&&i[2]){e.type="window-position",e.position={x:+i[2],y:+i[3]},e.x=e.position.x,e.y=e.position.y,e.windowPosition=e.position,this.emit("response",e),this.emit("response "+e.event,e);return}if(i[1]==="4"&&i[2]){e.type="window-size-pixels",e.size={height:+i[2],width:+i[3]},e.height=e.size.height,e.width=e.size.width,e.windowSizePixels=e.size,this.emit("response",e),this.emit("response "+e.event,e);return}if(i[1]==="8"&&i[2]){e.type="textarea-size",e.size={height:+i[2],width:+i[3]},e.height=e.size.height,e.width=e.size.width,e.textAreaSizeCharacters=e.size,this.emit("response",e),this.emit("response "+e.event,e);return}if(i[1]==="9"&&i[2]){e.type="screen-size",e.size={height:+i[2],width:+i[3]},e.height=e.size.height,e.width=e.size.width,e.screenSizeCharacters=e.size,this.emit("response",e),this.emit("response "+e.event,e);return}e.type="error",e.text="Unhandled: "+JSON.stringify(i),e.error=e.text,this.emit("response",e),this.emit("response "+e.event,e);return}if((i=/^\x1b\](l|L)([^\x07\x1b]*)$/.exec(t))&&(i[2]="rxvt",t="\x1B]"+i[1]+i[2]+"\x1B\\"),i=/^\x1b\](l|L)([^\x07\x1b]*)(?:\x07|\x1b\\)/.exec(t)){if(e.event="window-manipulation",e.code="",i[1]==="L"){e.type="window-icon-label",e.text=i[2],e.windowIconLabel=e.text,this.emit("response",e),this.emit("response "+e.event,e);return}if(i[1]==="l"){e.type="window-title",e.text=i[2],e.windowTitle=e.text,this.emit("response",e),this.emit("response "+e.event,e);return}e.type="error",e.text="Unhandled: "+JSON.stringify(i),e.error=e.text,this.emit("response",e),this.emit("response "+e.event,e);return}if(i=/^\x1b\[(\d+(?:;\d+){4})&w/.exec(t)){switch(i=i[1].split(";").map(function(s){return+s}),e.event="locator-position",e.code="DECRQLP",i[0]){case 0:e.status="locator-unavailable";break;case 1:e.status="request";break;case 2:e.status="left-button-down";break;case 3:e.status="left-button-up";break;case 4:e.status="middle-button-down";break;case 5:e.status="middle-button-up";break;case 6:e.status="right-button-down";break;case 7:e.status="right-button-up";break;case 8:e.status="m4-button-down";break;case 9:e.status="m4-button-up";break;case 10:e.status="locator-outside";break}e.mask=i[1],e.row=i[2],e.col=i[3],e.page=i[4],e.locatorPosition=e,this.emit("response",e),this.emit("response "+e.event,e);return}(i=/^\x1b\](\d+);([^\x07\x1b]+)(?:\x07|\x1b\\)/.exec(t))&&(e.event="text-params",e.code="Set Text Parameters",e.ps=+t[1],e.pt=t[2],this.emit("response",e),this.emit("response "+e.event,e))},r.prototype.response=function(t,e,i,s){var o=this;arguments.length===2&&(i=e,e=t,t=null),i||(i=function(){}),this.bindResponse(),t=t?"response "+t:"response";var n;this.once(t,n=function(h){return u&&clearTimeout(u),h.type==="error"?i(new Error(h.event+": "+h.text)):i(null,h)});var u=setTimeout(function(){return o.removeListener(t,n),i(new Error("Timeout."))},2e3);return s?this._write(e):this._twrite(e)},r.prototype._owrite=r.prototype.write=function(t){if(this.output.writable)return this.output.write(t)},r.prototype._buffer=function(t){if(this._exiting){this.flush(),this._owrite(t);return}if(this._buf){this._buf+=t;return}return this._buf=t,b(this._flush),!0},r.prototype.flush=function(){this._buf&&(this._owrite(this._buf),this._buf="")},r.prototype._write=function(t){return this.ret?t:this.useBuffer?this._buffer(t):this._owrite(t)},r.prototype._twrite=function(t){var e=this,i=0,s;return this.tmux?(t=t.replace(/\x1b\\/g,"\x07"),t="\x1BPtmux;\x1B"+t+"\x1B\\",this.output.bytesWritten===0?(s=setInterval(function(){(e.output.bytesWritten>0||++i===50)&&(clearInterval(s),e.flush(),e._owrite(t))},100),!0):(this.flush(),this._owrite(t))):this._write(t)},r.prototype.echo=r.prototype.print=function(t,e){return e?this._write(this.text(t,e)):this._write(t)},r.prototype._ncoords=function(){this.x<0?this.x=0:this.x>=this.cols&&(this.x=this.cols-1),this.y<0?this.y=0:this.y>=this.rows&&(this.y=this.rows-1)},r.prototype.setx=function(t){return this.cursorCharAbsolute(t)},r.prototype.sety=function(t){return this.linePosAbsolute(t)},r.prototype.move=function(t,e){return this.cursorPos(e,t)},r.prototype.omove=function(t,e){this.zero?(t=t||0,e=e||0):(t=(t||1)-1,e=(e||1)-1),!(e===this.y&&t===this.x)&&(e===this.y?t>this.x?this.cuf(t-this.x):t<this.x&&this.cub(this.x-t):t===this.x?e>this.y?this.cud(e-this.y):e<this.y&&this.cuu(this.y-e):(this.zero||(t++,e++),this.cup(e,t)))},r.prototype.rsetx=function(t){if(t)return t>0?this.forward(t):this.back(-t)},r.prototype.rsety=function(t){if(t)return t>0?this.up(t):this.down(-t)},r.prototype.rmove=function(t,e){this.rsetx(t),this.rsety(e)},r.prototype.simpleInsert=function(t,e,i){return this._write(this.repeat(t,e),i)},r.prototype.repeat=function(t,e){return(!e||e<0)&&(e=0),Array(e+1).join(t)},r.prototype.__defineGetter__("title",function(){return this._title}),r.prototype.__defineSetter__("title",function(t){return this.setTitle(t),this._title}),r.prototype.copyToClipboard=function(t){return this.isiTerm2?(this._twrite("\x1B]50;CopyToCliboard="+t+"\x07"),!0):!1},r.prototype.cursorShape=function(t,e){if(this.isiTerm2){switch(t){case"block":e?this._twrite("\x1B]50;CursorShape=0;BlinkingCursorEnabled=1\x07"):this._twrite("\x1B]50;CursorShape=0;BlinkingCursorEnabled=0\x07");break;case"underline":break;case"line":e?this._twrite("\x1B]50;CursorShape=1;BlinkingCursorEnabled=1\x07"):this._twrite("\x1B]50;CursorShape=1;BlinkingCursorEnabled=0\x07");break}return!0}else if(this.term("xterm")||this.term("screen")){switch(t){case"block":e?this._twrite("\x1B[1 q"):this._twrite("\x1B[0 q");break;case"underline":e?this._twrite("\x1B[3 q"):this._twrite("\x1B[2 q");break;case"line":e?this._twrite("\x1B[5 q"):this._twrite("\x1B[4 q");break}return!0}return!1},r.prototype.cursorColor=function(t){return this.term("xterm")||this.term("rxvt")||this.term("screen")?(this._twrite("\x1B]12;"+t+"\x07"),!0):!1},r.prototype.cursorReset=r.prototype.resetCursor=function(){return this.term("xterm")||this.term("rxvt")||this.term("screen")?(this._twrite("\x1B[0 q"),this._twrite("\x1B]112\x07"),this._twrite("\x1B]12;white\x07"),!0):!1},r.prototype.getTextParams=function(t,e){return this.response("text-params","\x1B]"+t+";?\x07",function(i,s){return i?e(i):e(null,s.pt)})},r.prototype.getCursorColor=function(t){return this.getTextParams(12,t)},r.prototype.nul=function(){return this._write("\x80")},r.prototype.bel=r.prototype.bell=function(){return this.has("bel")?this.put.bel():this._write("\x07")},r.prototype.vtab=function(){return this.y++,this._ncoords(),this._write("\v")},r.prototype.ff=r.prototype.form=function(){return this.has("ff")?this.put.ff():this._write("\f")},r.prototype.kbs=r.prototype.backspace=function(){return this.x--,this._ncoords(),this.has("kbs")?this.put.kbs():this._write("\b")},r.prototype.ht=r.prototype.tab=function(){return this.x+=8,this._ncoords(),this.has("ht")?this.put.ht():this._write(" ")},r.prototype.shiftOut=function(){return this._write("")},r.prototype.shiftIn=function(){return this._write("")},r.prototype.cr=r.prototype.return=function(){return this.x=0,this.has("cr")?this.put.cr():this._write("\r")},r.prototype.nel=r.prototype.newline=r.prototype.feed=function(){if(!(this.tput&&this.tput.bools.eat_newline_glitch&&this.x>=this.cols))return this.x=0,this.y++,this._ncoords(),this.has("nel")?this.put.nel():this._write(` `)},r.prototype.ind=r.prototype.index=function(){return this.y++,this._ncoords(),this.tput?this.put.ind():this._write("\x1BD")},r.prototype.ri=r.prototype.reverse=r.prototype.reverseIndex=function(){return this.y--,this._ncoords(),this.tput?this.put.ri():this._write("\x1BM")},r.prototype.nextLine=function(){return this.y++,this.x=0,this._ncoords(),this.has("nel")?this.put.nel():this._write("\x1BE")},r.prototype.reset=function(){return this.x=this.y=0,this.has("rs1")||this.has("ris")?this.has("rs1")?this.put.rs1():this.put.ris():this._write("\x1Bc")},r.prototype.tabSet=function(){return this.tput?this.put.hts():this._write("\x1BH")},r.prototype.sc=r.prototype.saveCursor=function(t){return t?this.lsaveCursor(t):(this.savedX=this.x||0,this.savedY=this.y||0,this.tput?this.put.sc():this._write("\x1B7"))},r.prototype.rc=r.prototype.restoreCursor=function(t,e){return t?this.lrestoreCursor(t,e):(this.x=this.savedX||0,this.y=this.savedY||0,this.tput?this.put.rc():this._write("\x1B8"))},r.prototype.lsaveCursor=function(t){t=t||"local",this._saved=this._saved||{},this._saved[t]=this._saved[t]||{},this._saved[t].x=this.x,this._saved[t].y=this.y,this._saved[t].hidden=this.cursorHidden},r.prototype.lrestoreCursor=function(t,e){var i;t=t||"local",!(!this._saved||!this._saved[t])&&(i=this._saved[t],this.cup(i.y,i.x),e&&i.hidden!==this.cursorHidden&&(i.hidden?this.hideCursor():this.showCursor()))},r.prototype.lineHeight=function(){return this._write("\x1B#")},r.prototype.charset=function(t,e){switch(e=e||0,e){case 0:e="(";break;case 1:e=")";break;case 2:e="*";break;case 3:e="+";break}var i=typeof t=="string"?t.toLowerCase():t;switch(i){case"acs":case"scld":if(this.tput)return this.put.smacs();t="0";break;case"uk":t="A";break;case"us":case"usascii":case"ascii":if(this.tput)return this.put.rmacs();t="B";break;case"dutch":t="4";break;case"finnish":t="C",t="5";break;case"french":t="R";break;case"frenchcanadian":t="Q";break;case"german":t="K";break;case"italian":t="Y";break;case"norwegiandanish":t="E",t="6";break;case"spanish":t="Z";break;case"swedish":t="H",t="7";break;case"swiss":t="=";break;case"isolatin":t="/A";break;default:if(this.tput)return this.put.rmacs();t="B";break}return this._write("\x1B("+t)},r.prototype.enter_alt_charset_mode=r.prototype.as=r.prototype.smacs=function(){return this.charset("acs")},r.prototype.exit_alt_charset_mode=r.prototype.ae=r.prototype.rmacs=function(){return this.charset("ascii")},r.prototype.setG=function(t){switch(t){case 1:t="~";break;case 2:t="n",t="}",t="N";break;case 3:t="o",t="|",t="O";break}return this._write("\x1B"+t)},r.prototype.setTitle=function(t){return this._title=t,this._twrite("\x1B]0;"+t+"\x07")},r.prototype.resetColors=function(t){return this.has("Cr")?this.put.Cr(t):this._twrite("\x1B]112\x07")},r.prototype.dynamicColors=function(t){return this.has("Cs")?this.put.Cs(t):this._twrite("\x1B]12;"+t+"\x07")},r.prototype.selData=function(t,e){return this.has("Ms")?this.put.Ms(t,e):this._twrite("\x1B]52;"+t+";"+e+"\x07")},r.prototype.cuu=r.prototype.up=r.prototype.cursorUp=function(t){return this.y-=t||1,this._ncoords(),this.tput?this.tput.strings.parm_up_cursor?this.put.cuu(t):this._write(this.repeat(this.tput.cuu1(),t)):this._write("\x1B["+(t||"")+"A")},r.prototype.cud=r.prototype.down=r.prototype.cursorDown=function(t){return this.y+=t||1,this._ncoords(),this.tput?this.tput.strings.parm_down_cursor?this.put.cud(t):this._write(this.repeat(this.tput.cud1(),t)):this._write("\x1B["+(t||"")+"B")},r.prototype.cuf=r.prototype.right=r.prototype.forward=r.prototype.cursorForward=function(t){return this.x+=t||1,this._ncoords(),this.tput?this.tput.strings.parm_right_cursor?this.put.cuf(t):this._write(this.repeat(this.tput.cuf1(),t)):this._write("\x1B["+(t||"")+"C")},r.prototype.cub=r.prototype.left=r.prototype.back=r.prototype.cursorBackward=function(t){return this.x-=t||1,this._ncoords(),this.tput?this.tput.strings.parm_left_cursor?this.put.cub(t):this._write(this.repeat(this.tput.cub1(),t)):this._write("\x1B["+(t||"")+"D")},r.prototype.cup=r.prototype.pos=r.prototype.cursorPos=function(t,e){return this.zero?(t=t||0,e=e||0):(t=(t||1)-1,e=(e||1)-1),this.x=e,this.y=t,this._ncoords(),this.tput?this.put.cup(t,e):this._write("\x1B["+(t+1)+";"+(e+1)+"H")},r.prototype.ed=r.prototype.eraseInDisplay=function(t){if(this.tput){switch(t){case"above":t=1;break;case"all":t=2;break;case"saved":t=3;break;case"below":default:t=0;break}return this.put.ed(t)}switch(t){case"above":return this._write("X1b[1J");case"all":return this._write("\x1B[2J");case"saved":return this._write("\x1B[3J");case"below":default:return this._write("\x1B[J")}},r.prototype.clear=function(){return this.x=0,this.y=0,this.tput?this.put.clear():this._write("\x1B[H\x1B[J")},r.prototype.el=r.prototype.eraseInLine=function(t){if(this.tput){switch(t){case"left":t=1;break;case"all":t=2;break;case"right":default:t=0;break}return this.put.el(t)}switch(t){case"left":return this._write("\x1B[1K");case"all":return this._write("\x1B[2K");case"right":default:return this._write("\x1B[K")}},r.prototype.sgr=r.prototype.attr=r.prototype.charAttributes=function(t,e){return this._write(this._attr(t,e))},r.prototype.text=function(t,e){return this._attr(e,!0)+t+this._attr(e,!1)},r.prototype._attr=function(t,e){var i=this,s,o,n;if(Array.isArray(t)?(s=t,t=s[0]||"normal"):(t=t||"normal",s=t.split(/\s*[,;]\s*/)),s.length>1){var u={},h=[];return s.forEach(function(a){var c=i._attr(a,e);c!=null&&(a=c.slice(2,-1),a!==""&&(u[a]||(u[a]=!0,h.push(a))))}),"\x1B["+h.join(";")+"m"}switch(t.indexOf("no ")===0?(t=t.substring(3),e=!1):t.indexOf("!")===0&&(t=t.substring(1),e=!1),t){case"normal":case"default":return e===!1?"":"\x1B[m";case"bold":return e===!1?"\x1B[22m":"\x1B[1m";case"ul":case"underline":case"underlined":return e===!1?"\x1B[24m":"\x1B[4m";case"blink":return e===!1?"\x1B[25m":"\x1B[5m";case"inverse":return e===!1?"\x1B[27m":"\x1B[7m";case"invisible":return e===!1?"\x1B[28m":"\x1B[8m";case"black fg":return e===!1?"\x1B[39m":"\x1B[30m";case"red fg":return e===!1?"\x1B[39m":"\x1B[31m";case"green fg":return e===!1?"\x1B[39m":"\x1B[32m";case"yellow fg":return e===!1?"\x1B[39m":"\x1B[33m";case"blue fg":return e===!1?"\x1B[39m":"\x1B[34m";case"magenta fg":return e===!1?"\x1B[39m":"\x1B[35m";case"cyan fg":return e===!1?"\x1B[39m":"\x1B[36m";case"white fg":case"light grey fg":case"light gray fg":case"bright grey fg":case"bright gray fg":return e===!1?"\x1B[39m":"\x1B[37m";case"default fg":return e===!1?"":"\x1B[39m";case"black bg":return e===!1?"\x1B[49m":"\x1B[40m";case"red bg":return e===!1?"\x1B[49m":"\x1B[41m";case"green bg":return e===!1?"\x1B[49m":"\x1B[42m";case"yellow bg":return e===!1?"\x1B[49m":"\x1B[43m";case"blue bg":return e===!1?"\x1B[49m":"\x1B[44m";case"magenta bg":return e===!1?"\x1B[49m":"\x1B[45m";case"cyan bg":return e===!1?"\x1B[49m":"\x1B[46m";case"white bg":case"light grey bg":case"light gray bg":case"bright grey bg":case"bright gray bg":return e===!1?"\x1B[49m":"\x1B[47m";case"default bg":return e===!1?"":"\x1B[49m";case"light black fg":case"bright black fg":case"grey fg":case"gray fg":return e===!1?"\x1B[39m":"\x1B[90m";case"light red fg":case"bright red fg":return e===!1?"\x1B[39m":"\x1B[91m";case"light green fg":case"bright green fg":return e===!1?"\x1B[39m":"\x1B[92m";case"light yellow fg":case"bright yellow fg":return e===!1?"\x1B[39m":"\x1B[93m";case"light blue fg":case"bright blue fg":return e===!1?"\x1B[39m":"\x1B[94m";case"light magenta fg":case"bright magenta fg":return e===!1?"\x1B[39m":"\x1B[95m";case"light cyan fg":case"bright cyan fg":return e===!1?"\x1B[39m":"\x1B[96m";case"light white fg":case"bright white fg":return e===!1?"\x1B[39m":"\x1B[97m";case"light black bg":case"bright black bg":case"grey bg":case"gray bg":return e===!1?"\x1B[49m":"\x1B[100m";case"light red bg":case"bright red bg":return e===!1?"\x1B[49m":"\x1B[101m";case"light green bg":case"bright green bg":return e===!1?"\x1B[49m":"\x1B[102m";case"light yellow bg":case"bright yellow bg":return e===!1?"\x1B[49m":"\x1B[103m";case"light blue bg":case"bright blue bg":return e===!1?"\x1B[49m":"\x1B[104m";case"light magenta bg":case"bright magenta bg":return e===!1?"\x1B[49m":"\x1B[105m";case"light cyan bg":case"bright cyan bg":return e===!1?"\x1B[49m":"\x1B[106m";case"light white bg":case"bright white bg":return e===!1?"\x1B[49m":"\x1B[107m";case"default fg bg":return e===!1?"":this.term("rxvt")?"\x1B[100m":"\x1B[39;49m";default:if(t[0]==="#"&&(t=t.replace(/#(?:[0-9a-f]{3}){1,2}/i,w.match)),n=/^(-?\d+) (fg|bg)$/.exec(t),n){if(o=+n[1],e===!1||o===-1)return this._attr("default "+n[2]);if(o=w.reduce(o,this.tput.colors),o<16||this.tput&&this.tput.colors<=16)return n[2]==="fg"?o<8?o+=30:o<16&&(o-=8,o+=90):n[2]==="bg"&&(o<8?o+=40:o<16&&(o-=8,o+=100)),"\x1B["+o+"m";if(n[2]==="fg")return"\x1B[38;5;"+o+"m";if(n[2]==="bg")return"\x1B[48;5;"+o+"m"}return/^[\d;]*$/.test(t)?"\x1B["+t+"m":null}},r.prototype.fg=r.prototype.setForeground=function(t,e){return t=t.split(/\s*[,;]\s*/).join(" fg, ")+" fg",this.attr(t,e)},r.prototype.bg=r.prototype.setBackground=function(t,e){return t=t.split(/\s*[,;]\s*/).join(" bg, ")+" bg",this.attr(t,e)},r.prototype.dsr=r.prototype.deviceStatus=function(t,e,i,s){return i?this.response("device-status","\x1B[?"+(t||"0")+"n",e,s):this.response("device-status","\x1B["+(t||"0")+"n",e,s)},r.prototype.getCursor=function(t){return this.deviceStatus(6,t,!1,!0)},r.prototype.saveReportedCursor=function(t){var e=this;if(this.tput.strings.user7==="\x1B[6n"||this.term("screen"))return this.getCursor(function(i,s){if(s&&(e._rx=s.status.x,e._ry=s.status.y),!!t)return t(i)});if(t)return t()},r.prototype.restoreReportedCursor=function(){if(this._rx!=null)return this.cup(this._ry,this._rx)},r.prototype.ich=r.prototype.insertChars=function(t){return this.x+=t||1,this._ncoords(),this.tput?this.put.ich(t):this._write("\x1B["+(t||1)+"@")},r.prototype.cnl=r.prototype.cursorNextLine=function(t){return this.y+=t||1,this._ncoords(),this._write("\x1B["+(t||"")+"E")},r.prototype.cpl=r.prototype.cursorPrecedingLine=function(t){return this.y-=t||1,this._ncoords(),this._write("\x1B["+(t||"")+"F")},r.prototype.cha=r.prototype.cursorCharAbsolute=function(t){return this.zero?t=t||0:t=(t||1)-1,this.x=t,this.y=0,this._ncoords(),this.tput?this.put.hpa(t):this._write("\x1B["+(t+1)+"G")},r.prototype.il=r.prototype.insertLines=function(t){return this.tput?this.put.il(t):this._write("\x1B["+(t||"")+"L")},r.prototype.dl=r.prototype.deleteLines=function(t){return this.tput?this.put.dl(t):this._write("\x1B["+(t||"")+"M")},r.prototype.dch=r.prototype.deleteChars=function(t){return this.tput?this.put.dch(t):this._write("\x1B["+(t||"")+"P")},r.prototype.ech=r.prototype.eraseChars=function(t){return this.tput?this.put.ech(t):this._write("\x1B["+(t||"")+"X")},r.prototype.hpa=r.prototype.charPosAbsolute=function(t){return this.x=t||0,this._ncoords(),this.tput?this.put.hpa.apply(this.put,arguments):(t=p.call(arguments).join(";"),this._write("\x1B["+(t||"")+"`"))},r.prototype.hpr=r.prototype.HPositionRelative=function(t){return this.tput?this.cuf(t):(this.x+=t||1,this._ncoords(),this._write("\x1B["+(t||"")+"a"))},r.prototype.da=r.prototype.sendDeviceAttributes=function(t,e){return this.response("device-attributes","\x1B["+(t||"")+"c",e)},r.prototype.vpa=r.prototype.linePosAbsolute=function(t){return this.y=t||1,this._ncoords(),this.tput?this.put.vpa.apply(this.put,arguments):(t=p.call(arguments).join(";"),this._write("\x1B["+(t||"")+"d"))},r.prototype.vpr=r.prototype.VPositionRelative=function(t){return this.tput?this.cud(t):(this.y+=t||1,this._ncoords(),this._write("\x1B["+(t||"")+"e"))},r.prototype.hvp=r.prototype.HVPosition=function(t,e){return this.zero?(t=t||0,e=e||0):(t=(t||1)-1,e=(e||1)-1),this.y=t,this.x=e,this._ncoords(),this.tput?this.put.cup(t,e):this._write("\x1B["+(t+1)+";"+(e+1)+"f")},r.prototype.sm=r.prototype.setMode=function(){var t=p.call(arguments).join(";");return this._write("\x1B["+(t||"")+"h")},r.prototype.decset=function(){var t=p.call(arguments).join(";");return this.setMode("?"+t)},r.prototype.dectcem=r.prototype.cnorm=r.prototype.cvvis=r.prototype.showCursor=function(){return this.cursorHidden=!1,this.tput?this.put.cnorm():this.setMode("?25")},r.prototype.alternate=r.prototype.smcup=r.prototype.alternateBuffer=function(){if(this.isAlt=!0,this.tput)return this.put.smcup();if(!(this.term("vt")||this.term("linux")))return this.setMode("?47"),this.setMode("?1049")},r.prototype.rm=r.prototype.resetMode=function(){var t=p.call(arguments).join(";");return this._write("\x1B["+(t||"")+"l")},r.prototype.decrst=function(){var t=p.call(arguments).join(";");return this.resetMode("?"+t)},r.prototype.dectcemh=r.prototype.cursor_invisible=r.prototype.vi=r.prototype.civis=r.prototype.hideCursor=function(){return this.cursorHidden=!0,this.tput?this.put.civis():this.resetMode("?25")},r.prototype.rmcup=r.prototype.normalBuffer=function(){return this.isAlt=!1,this.tput?this.put.rmcup():(this.resetMode("?47"),this.resetMode("?1049"))},r.prototype.enableMouse=function(){if(process.env.BLESSED_FORCE_MODES){for(var t=process.env.BLESSED_FORCE_MODES.split(","),e={},i=0;i<t.length;++i){var s=t[i].split("="),o=s[1]!=="0";switch(s[0].toUpperCase()){case"SGRMOUSE":e.sgrMouse=o;break;case"UTFMOUSE":e.utfMouse=o;break;case"VT200MOUSE":e.vt200Mouse=o;break;case"URXVTMOUSE":e.urxvtMouse=o;break;case"X10MOUSE":e.x10Mouse=o;break;case"DECMOUSE":e.decMouse=o;break;case"PTERMMOUSE":e.ptermMouse=o;break;case"JSBTERMMOUSE":e.jsbtermMouse=o;break;case"VT200HILITE":e.vt200Hilite=o;break;case"GPMMOUSE":e.gpmMouse=o;break;case"CELLMOTION":e.cellMotion=o;break;case"ALLMOTION":e.allMotion=o;break;case"SENDFOCUS":e.sendFocus=o;break}}return this.setMouse(e,!0)}if(this.term("rxvt-unicode"))return this.setMouse({urxvtMouse:!0,cellMotion:!0,allMotion:!0},!0);if(this.term("rxvt"))return this.setMouse({vt200Mouse:!0,x10Mouse:!0,cellMotion:!0,allMotion:!0},!0);if(this.isVTE)return this.setMouse({sgrMouse:!0,cellMotion:!0,allMotion:!0},!0);if(this.term("linux"))return this.setMouse({vt200Mouse:!0,gpmMouse:!0},!0);if(this.term("xterm")||this.term("screen")||this.tput&&this.tput.strings.key_mouse)return this.setMouse({vt200Mouse:!0,utfMouse:!0,cellMotion:!0,allMotion:!0},!0)},r.prototype.disableMouse=function(){if(this._currentMouse){var t={};return Object.keys(this._currentMouse).forEach(function(e){t[e]=!1}),this.setMouse(t,!1)}},r.prototype.setMouse=function(t,e){if(t.normalMouse!==null&&(t.vt200Mouse=t.normalMouse,t.allMotion=t.normalMouse),t.hiliteTracking!==null&&(t.vt200Hilite=t.hiliteTracking),e===!0){if(this._currentMouse){this.setMouse(t),Object.keys(t).forEach(function(i){this._currentMouse[i]=t[i]},this);return}this._currentMouse=t,this.mouseEnabled=!0}else e===!1&&(delete this._currentMouse,this.mouseEnabled=!1);t.x10Mouse!==null&&(t.x10Mouse?this.setMode("?9"):this.resetMode("?9")),t.vt200Mouse!==null&&(t.vt200Mouse?this.setMode("?1000"):this.resetMode("?1000")),t.vt200Hilite!==null&&(t.vt200Hilite?this.setMode("?1001"):this.resetMode("?1001")),t.cellMotion!==null&&(t.cellMotion?this.setMode("?1002"):this.resetMode("?1002")),t.allMotion!==null&&(this.tmux&&this.tmuxVersion>=2?t.allMotion?this._twrite("\x1B[?1003h"):this._twrite("\x1B[?1003l"):t.allMotion?this.setMode("?1003"):this.resetMode("?1003")),t.sendFocus!==null&&(t.sendFocus?this.setMode("?1004"):this.resetMode("?1004")),t.utfMouse!==null&&(t.utfMouse?this.setMode("?1005"):this.resetMode("?1005")),t.sgrMouse!==null&&(t.sgrMouse?this.setMode("?1006"):this.resetMode("?1006")),t.urxvtMouse!==null&&(t.urxvtMouse?this.setMode("?1015"):this.resetMode("?1015")),t.decMouse!==null&&(t.decMouse?this._write("\x1B[1;2'z\x1B[1;3'{"):this._write("\x1B['z")),t.ptermMouse!==null&&(t.ptermMouse?this._write("\x1B[>1h\x1B[>6h\x1B[>7h\x1B[>1h\x1B[>9l"):this._write("\x1B[>1l\x1B[>6l\x1B[>7l\x1B[>1l\x1B[>9h")),t.jsbtermMouse!==null&&(t.jsbtermMouse?this._write("\x1B[0~ZwLMRK+1Q\x1B\\"):this._write("\x1B[0~ZwQ\x1B\\")),t.gpmMouse!==null&&(t.gpmMouse?this.enableGpm():this.disableGpm())},r.prototype.decstbm=r.prototype.csr=r.prototype.setScrollRegion=function(t,e){return this.zero?(t=t||0,e=e||this.rows-1):(t=(t||1)-1,e=(e||this.rows)-1),this.scrollTop=t,this.scrollBottom=e,this.x=0,this.y=0,this._ncoords(),this.tput?this.put.csr(t,e):this._write("\x1B["+(t+1)+";"+(e+1)+"r")},r.prototype.scA=r.prototype.saveCursorA=function(){return this.savedX=this.x,this.savedY=this.y,this.tput?this.put.sc():this._write("\x1B[s")},r.prototype.rcA=r.prototype.restoreCursorA=function(){return this.x=this.savedX||0,this.y=this.savedY||0,this.tput?this.put.rc():this._write("\x1B[u")},r.prototype.cht=r.prototype.cursorForwardTab=function(t){return this.x+=8,this._ncoords(),this.tput?this.put.tab(t):this._write("\x1B["+(t||1)+"I")},r.prototype.su=r.prototype.scrollUp=function(t){return this.y-=t||1,this._ncoords(),this.tput?this.put.parm_index(t):this._write("\x1B["+(t||1)+"S")},r.prototype.sd=r.prototype.scrollDown=function(t){return this.y+=t||1,this._ncoords(),this.tput?this.put.parm_rindex(t):this._write("\x1B["+(t||1)+"T")},r.prototype.initMouseTracking=function(){return this._write("\x1B["+p.call(arguments).join(";")+"T")},r.prototype.resetTitleModes=function(){return this._write("\x1B[>"+p.call(arguments).join(";")+"T")},r.prototype.cbt=r.prototype.cursorBackwardTab=function(t){return this.x-=8,this._ncoords(),this.tput?this.put.cbt(t):this._write("\x1B["+(t||1)+"Z")},r.prototype.rep=r.prototype.repeatPrecedingCharacter=function(t){return this.x+=t||1,this._ncoords(),this.tput?this.put.rep(t):this._write("\x1B["+(t||1)+"b")},r.prototype.tbc=r.prototype.tabClear=function(t){return this.tput?this.put.tbc(t):this._write("\x1B["+(t||0)+"g")},r.prototype.mc=r.prototype.mediaCopy=function(){return this._write("\x1B["+p.call(arguments).join(";")+"i")},r.prototype.print_screen=r.prototype.ps=r.prototype.mc0=function(){return this.tput?this.put.mc0():this.mc("0")},r.prototype.prtr_on=r.prototype.po=r.prototype.mc5=function(){return this.tput?this.put.mc5():this.mc("5")},r.prototype.prtr_off=r.prototype.pf=r.prototype.mc4=function(){return this.tput?this.put.mc4():this.mc("4")},r.prototype.prtr_non=r.prototype.pO=r.prototype.mc5p=function(){return this.tput?this.put.mc5p():this.mc("?5")},r.prototype.setResources=function(){return this._write("\x1B[>"+p.call(arguments).join(";")+"m")},r.prototype.disableModifiers=function(t){return this._write("\x1B[>"+(t||"")+"n")},r.prototype.setPointerMode=function(t){return this._write("\x1B[>"+(t||"")+"p")},r.prototype.decstr=r.prototype.rs2=r.prototype.softReset=function(){return this.tput?this.put.rs2():this._write("\x1B[!p\x1B[?3;4l\x1B[4l\x1B>")},r.prototype.decrqm=r.prototype.requestAnsiMode=function(t){return this._write("\x1B["+(t||"")+"$p")},r.prototype.decrqmp=r.prototype.requestPrivateMode=function(t){return this._write("\x1B[?"+(t||"")+"$p")},r.prototype.decscl=r.prototype.setConformanceLevel=function(){return this._write("\x1B["+p.call(arguments).join(";")+'"p')},r.prototype.decll=r.prototype.loadLEDs=function(t){return this._write("\x1B["+(t||"")+"q")},r.prototype.decscusr=r.prototype.setCursorStyle=function(t){switch(t){case"blinking block":t=1;break;case"block":case"steady block":t=2;break;case"blinking underline":t=3;break;case"underline":case"steady underline":t=4;break;case"blinking bar":t=5;break;case"bar":case"steady bar":t=6;break}return t===2&&this.has("Se")?this.put.Se():this.has("Ss")?this.put.Ss(t):this._write("\x1B["+(t||1)+" q")},r.prototype.decsca=r.prototype.setCharProtectionAttr=function(t){return this._write("\x1B["+(t||0)+'"q')},r.prototype.restorePrivateValues=function(){return this._write("\x1B[?"+p.call(arguments).join(";")+"r")},r.prototype.deccara=r.prototype.setAttrInRectangle=function(){return this._write("\x1B["+p.call(arguments).join(";")+"$r")},r.prototype.savePrivateValues=function(){return this._write("\x1B[?"+p.call(arguments).join(";")+"s")},r.prototype.manipulateWindow=function(){var t=p.call(arguments),e=typeof t[t.length-1]=="function"?t.pop():function(){};return this.response("window-manipulation","\x1B["+t.join(";")+"t",e)},r.prototype.getWindowSize=function(t){return this.manipulateWindow(18,t)},r.prototype.decrara=r.prototype.reverseAttrInRectangle=function(){return this._write("\x1B["+p.call(arguments).join(";")+"$t")},r.prototype.setTitleModeFeature=function(){return this._twrite("\x1B[>"+p.call(arguments).join(";")+"t")},r.prototype.decswbv=r.prototype.setWarningBellVolume=function(t){return this._write("\x1B["+(t||"")+" t")},r.prototype.decsmbv=r.prototype.setMarginBellVolume=function(t){return this._write("\x1B["+(t||"")+" u")},r.prototype.deccra=r.prototype.copyRectangle=function(){return this._write("\x1B["+p.call(arguments).join(";")+"$v")},r.prototype.decefr=r.prototype.enableFilterRectangle=function(){return this._write("\x1B["+p.call(arguments).join(";")+"'w")},r.prototype.decreqtparm=r.prototype.requestParameters=function(t){return this._write("\x1B["+(t||0)+"x")},r.prototype.decsace=r.prototype.selectChangeExtent=function(t){return this._write("\x1B["+(t||0)+"x")},r.prototype.decfra=r.prototype.fillRectangle=function(){return this._write("\x1B["+p.call(arguments).join(";")+"$x")},r.prototype.decelr=r.prototype.enableLocatorReporting=function(){return this._write("\x1B["+p.call(arguments).join(";")+"'z")},r.prototype.decera=r.prototype.eraseRectangle=function(){return this._write("\x1B["+p.call(arguments).join(";")+"$z")},r.prototype.decsle=r.prototype.setLocatorEvents=function(){return this._write("\x1B["+p.call(arguments).join(";")+"'{")},r.prototype.decsera=r.prototype.selectiveEraseRectangle=function(){return this._write("\x1B["+p.call(arguments).join(";")+"${")},r.prototype.decrqlp=r.prototype.req_mouse_pos=r.prototype.reqmp=r.prototype.requestLocatorPosition=function(t,e){if(this.has("req_mouse_pos")){var i=this.tput.req_mouse_pos(t);return this.response("locator-position",i,e)}return this.response("locator-position","\x1B["+(t||"")+"'|",e)},r.prototype.decic=r.prototype.insertColumns=function(){return this._write("\x1B["+p.call(arguments).join(";")+" }")},r.prototype.decdc=r.prototype.deleteColumns=function(){return this._write("\x1B["+p.call(arguments).join(";")+" ~")},r.prototype.out=function(t){var e=Array.prototype.slice.call(arguments,1);this.ret=!0;var i=this[t].apply(this,e);return this.ret=!1,i},r.prototype.sigtstp=function(t){var e=this.pause();process.once("SIGCONT",function(){e(),t&&t()}),process.kill(process.pid,"SIGTSTP")},r.prototype.pause=function(t){var e=this,i=this.isAlt,s=this.mouseEnabled;this.lsaveCursor("pause"),i&&this.normalBuffer(),this.showCursor(),s&&this.disableMouse();var o=this.output.write;return this.output.write=function(){},this.input.setRawMode&&this.input.setRawMode(!1),this.input.pause(),this._resume=function(){delete e._resume,e.input.setRawMode&&e.input.setRawMode(!0),e.input.resume(),e.output.write=o,i&&e.alternateBuffer(),s&&e.enableMouse(),e.lrestoreCursor("pause",!0),t&&t()}},r.prototype.resume=function(){if(this._resume)return this._resume()};function k(t,e,i){var s=t.listeners(e);t.removeAllListeners(e),t.on(e,i),s.forEach(function(o){t.on(e,o)})}function E(t){return p.call(arguments,1).forEach(function(e){Object.keys(e).forEach(function(i){t[i]=e[i]})}),t}module.exports=r; //# sourceMappingURL=program.js.map