neo-neo-bblessed
Version:
A fork of neo-blessed (which is a fork of blessed) with bug fixes and maintenance.
3 lines (2 loc) • 2.51 kB
JavaScript
var F=Object.create;var T=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var q=(t,i,n,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of _(i))!S.call(t,s)&&s!==n&&T(t,s,{get:()=>i[s],enumerable:!(r=k(i,s))||r.enumerable});return t};var p=(t,i,n)=>(n=t!=null?F(C(t)):{},q(i||!t||!t.__esModule?T(n,"default",{value:t,enumerable:!0}):n,t));const v=require("fs"),I=require("./node"),w=require("./box");function c(t){if(!(this instanceof I))return new c(t);t=t||{},t.font=t.font||require.resolve("../../usr/fonts/ter-u14n.json"),t.fontBold=t.fontBold||require.resolve("../../usr/fonts/ter-u14b.json"),this.fch=t.fch,this.ratio={},this.font=this.loadFont(t.font),this.fontBold=this.loadFont(t.fontBold),w.call(this,t),this.style.bold&&(this.font=this.fontBold)}c.prototype.__proto__=w.prototype,c.prototype.type="bigtext",c.prototype.loadFont=function(t){const i=this;let n,r;n=JSON.parse(v.readFileSync(t,"utf8")),this.ratio.width=n.width,this.ratio.height=n.height;function s(a,e){let g,l;for(;e.length>i.ratio.height;)e.shift(),e.pop();for(e=e.map(function(x){let o=x.split("").map(function(u){return u===" "?0:1});for(;o.length<i.ratio.width;)o.push(0);return o});e.length<i.ratio.height;){for(g=[],l=0;l<i.ratio.width;l++)g.push(0);e.push(g)}return e}return r=Object.keys(n.glyphs).reduce(function(a,e){const g=n.glyphs[e].map;return a[e]=s(e,g),a},{}),delete r[" "],r},c.prototype.setContent=function(t){this.content="",this.text=t||""},c.prototype.render=function(){(this.position.width==null||this._shrinkWidth)&&(this.position.width=this.ratio.width*this.text.length+1,this._shrinkWidth=!0),(this.position.height==null||this._shrinkHeight)&&(this.position.height=this.ratio.height+0,this._shrinkHeight=!0);const t=this._render();if(!t)return;const i=this.screen.lines,n=t.xi+this.ileft,r=t.yi+this.itop,s=t.xl-this.iright,a=t.yl-this.ibottom,e=this.sattr(this.style),g=e&511,l=e>>9&511,B=(e>>18&511)<<18|g<<9|l;for(let o=n,u=0;o<s;o+=this.ratio.width,u++){const b=this.text[u];if(!b)break;const m=this.font[b];if(m)for(let h=r;h<Math.min(a,r+this.ratio.height);h++){if(!i[h])continue;const y=m[h-r];if(y){for(let f=0;f<this.ratio.width;f++){const d=y[f];if(d==null)break;this.fch&&this.fch!==" "?(i[h][o+f][0]=e,i[h][o+f][1]=d===1?this.fch:this.ch):(i[h][o+f][0]=d===1?B:e,i[h][o+f][1]=d===1?" ":this.ch)}i[h].dirty=!0}}}return t},module.exports=c;
//# sourceMappingURL=bigtext.js.map