neo-neo-bblessed
Version:
A fork of neo-blessed (which is a fork of blessed) with bug fixes and maintenance.
3 lines (2 loc) • 3.23 kB
JavaScript
const m=require("./node"),g=require("./box"),y=require("./list"),_=require("./table");function o(e){const s=this;if(!(this instanceof m))return new o(e);e=e||{},e.normalShrink=!0,e.style=e.style||{},e.style.border=e.style.border||{},e.style.header=e.style.header||{},e.style.cell=e.style.cell||{},this.__align=e.align||"center",delete e.align,e.style.selected=e.style.cell.selected,e.style.item=e.style.cell;const t=e.border;t&&t.top===!1&&t.bottom===!1&&t.left===!1&&t.right===!1&&delete e.border,y.call(this,e),e.border=t,this._header=new g({parent:this,left:this.screen.autoPadding?0:this.ileft,top:0,width:"shrink",height:1,style:e.style.header,tags:e.parseTags||e.tags}),this.on("scroll",function(){s._header.setFront(),s._header.rtop=s.childBase,s.screen.autoPadding||(s._header.rtop=s.childBase+(s.border?1:0))}),this.pad=e.pad!=null?e.pad:2,this.setData(e.rows||e.data),this.on("attach",function(){s.setData(s.rows)}),this.on("resize",function(){const a=s.selected;s.setData(s.rows),s.select(a),s.screen.render()})}o.prototype.__proto__=y.prototype,o.prototype.type="list-table",o.prototype._calculateMaxes=_.prototype._calculateMaxes,o.prototype.setRows=o.prototype.setData=function(e){const s=this,t=this.__align,a=this.selected,n=this.items.slice();let r=this.ritems[this.selected];this.visible&&this.lpos&&this.clearPos(),this.clearItems(),this.rows=e||[],this._calculateMaxes(),this._maxes&&(this.addItem(""),this.rows.forEach(function(i,f){const h=f===0;let d="";i.forEach(function(l,b){const u=s._maxes[b];let c=s.strWidth(l);for(b!==0&&(d+=" ");c<u;)t==="center"?(l=" "+l+" ",c+=2):t==="left"?(l=l+" ",c+=1):t==="right"&&(l=" "+l,c+=1);c>u&&(t==="center"?(l=l.substring(1),c--):t==="left"?(l=l.slice(0,-1),c--):t==="right"&&(l=l.substring(1),c--)),d+=l}),h?s._header.setContent(d):s.addItem(d)}),this._header.setFront(),r=this.ritems.indexOf(r),~r?this.select(r):this.items.length===n.length?this.select(a):this.select(Math.min(a,this.items.length-1)))},o.prototype._select=o.prototype.select,o.prototype.select=function(e){e===0&&(e=1),e<=this.childBase&&this.setScroll(this.childBase-1),this._select(e),this.scrollTo(this.selected-1),this.rows&&this.selected&&this.emit("selectrow",this.rows[this.selected],this.selected)},o.prototype.render=function(){const e=this,s=this._render();if(!s)return;if(this._calculateMaxes(),!this._maxes)return s;const t=this.screen.lines,a=s.xi,n=s.yi;let r,i,f;const h=this.sattr(this.style.border),d=s.yl-s.yi-this.ibottom;let l=this.border;if(!this.border&&this.options.border&&(l=this.options.border),!l||this.options.noCellBorders)return s;for(i=0,f=0;f<d+1&&t[n+i];f++)r=0,e._maxes.slice(0,-1).forEach(function(b){r+=b,t[n+i][a+r+1]&&(i===0?(r++,t[n+i][a+r][0]=h,t[n+i][a+r][1]="\u252C",l.top||(t[n+i][a+r][1]="\u2502"),t[n+i].dirty=!0):i===d?(r++,t[n+i][a+r][0]=h,t[n+i][a+r][1]="\u2534",l.bottom||(t[n+i][a+r][1]="\u2502"),t[n+i].dirty=!0):r++)}),i+=1;for(i=1;i<d&&t[n+i];i++)r=0,e._maxes.slice(0,-1).forEach(function(b){if(r+=b,!!t[n+i][a+r+1]){if(e.options.fillCellBorders!==!1){const u=t[n+i][a+r][0]&511;r++,t[n+i][a+r][0]=h&-512|u}else r++,t[n+i][a+r][0]=h;t[n+i][a+r][1]="\u2502",t[n+i].dirty=!0}});return s},module.exports=o;
//# sourceMappingURL=listtable.js.map