UNPKG

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.98 kB
const f=require("./node"),h=require("./input");function l(e){const r=this;if(!(this instanceof f))return new l(e);e=e||{},h.call(this,e),this.filled=e.filled||0,typeof this.filled=="string"&&(this.filled=+this.filled.slice(0,-1)),this.value=this.filled,this.pch=e.pch||" ",e.ch&&(this.pch=e.ch,this.ch=" "),e.bch&&(this.ch=e.bch),this.style.bar||(this.style.bar={},this.style.bar.fg=e.barFg,this.style.bar.bg=e.barBg),this.orientation=e.orientation||"horizontal",e.keys&&this.on("keypress",function(n,i){let t,s;if(r.orientation==="horizontal"?(t=["left","h"],s=["right","l"]):r.orientation==="vertical"&&(t=["down","j"],s=["up","k"]),i.name===t[0]||e.vi&&i.name===t[1]){r.progress(-5),r.screen.render();return}if(i.name===s[0]||e.vi&&i.name===s[1]){r.progress(5),r.screen.render();return}}),e.mouse&&this.on("click",function(n){let i,t,s,o;r.lpos&&(r.orientation==="horizontal"?(i=n.x-r.lpos.xi,s=r.lpos.xl-r.lpos.xi-r.iwidth,o=i/s*100|0):r.orientation==="vertical"&&(t=n.y-r.lpos.yi,s=r.lpos.yl-r.lpos.yi-r.iheight,o=t/s*100|0),r.setProgress(o))})}l.prototype.__proto__=h.prototype,l.prototype.type="progress-bar",l.prototype.render=function(){const e=this._render();if(!e)return null;let r=e.xi,n=e.xl,i=e.yi,t=e.yl,s;if(this.border&&(r++,i++,n--,t--),this.orientation==="horizontal"?n=r+(n-r)*(this.filled/100)|0:this.orientation==="vertical"&&(i=i+(t-i-((t-i)*(this.filled/100)|0))),s=this.sattr(this.style.bar),this.screen.fillRegion(s,this.pch,r,n,i,t),this.content){const o=this.screen.lines[i];for(let a=0;a<this.content.length;a++)o[r+a][1]=this.content[a];o.dirty=!0}return e},l.prototype.progress=function(e){this.filled+=e,this.filled<0?this.filled=0:this.filled>100&&(this.filled=100),this.filled===100&&this.emit("complete"),this.value=this.filled},l.prototype.setProgress=function(e){this.filled=0,this.progress(e)},l.prototype.reset=function(){this.emit("reset"),this.filled=0,this.value=this.filled},module.exports=l; //# sourceMappingURL=progressbar.js.map