neo-neo-bblessed
Version:
A fork of neo-blessed (which is a fork of blessed) with bug fixes and maintenance.
3 lines (2 loc) • 1.99 kB
JavaScript
var r=require("child_process"),o=require("../colors"),l=require("./node"),s=require("./box"),h=require("../../vendor/tng.js");function i(e){var n=this;if(!(this instanceof l))return new i(e);e=e||{},e.shrink=!0,s.call(this,e),this.scale=this.options.scale||1,this.options.animate=this.options.animate!==!1,this._noFill=!0,this.options.file&&this.setImage(this.options.file),this.screen.on("prerender",function(){var t=n.lpos;t&&n.screen.clearRegion(t.xi,t.xl,t.yi,t.yl)}),this.on("destroy",function(){n.stop()})}i.prototype.__proto__=s.prototype,i.prototype.type="ansiimage",i.curl=function(e){try{return r.execFileSync("curl",["-s","-A","",e],{stdio:["ignore","pipe","ignore"]})}catch(n){}try{return r.execFileSync("wget",["-U","","-O","-",e],{stdio:["ignore","pipe","ignore"]})}catch(n){}throw new Error("curl or wget failed.")},i.prototype.setImage=function(e){this.file=typeof e=="string"?e:null,/^https?:/.test(e)&&(e=i.curl(e));var n=this.position.width,t=this.position.height;n!=null&&(n=this.width),t!=null&&(t=this.height);try{this.setContent(""),this.img=h(e,{colors:o,width:n,height:t,scale:this.scale,ascii:this.options.ascii,speed:this.options.speed,filename:this.file}),(n==null||t==null)&&(this.width=this.img.cellmap[0].length,this.height=this.img.cellmap.length),this.img.frames&&this.options.animate?this.play():this.cellmap=this.img.cellmap}catch(a){this.setContent("Image Error: "+a.message),this.img=null,this.cellmap=null}},i.prototype.play=function(){var e=this;if(this.img)return this.img.play(function(n,t){e.cellmap=t,e.screen.render()})},i.prototype.pause=function(){if(this.img)return this.img.pause()},i.prototype.stop=function(){if(this.img)return this.img.stop()},i.prototype.clearImage=function(){this.stop(),this.setContent(""),this.img=void 0,this.cellmap=void 0},i.prototype.render=function(){var e=this._render();if(e)return this.img&&this.cellmap&&this.img.renderElement(this.cellmap,this),e},module.exports=i;
//# sourceMappingURL=ansiimage.js.map