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.12 kB
JavaScript
const i=require("./node"),c=require("./input");function r(t){const e=this;if(!(this instanceof i))return new r(t);t=t||{},c.call(this,t),this.text=t.content||t.text||"",this.checked=this.value=t.checked||!1,this.on("keypress",function(n,o){(o.name==="enter"||o.name==="space")&&(e.toggle(),e.screen.render())}),t.mouse&&this.on("click",function(){e.toggle(),e.screen.render()}),this.on("focus",function(){const n=e.lpos;n&&(e.screen.program.lsaveCursor("checkbox"),e.screen.program.cup(n.yi,n.xi+1),e.screen.program.showCursor())}),this.on("blur",function(){e.screen.program.lrestoreCursor("checkbox",!0)})}r.prototype.__proto__=c.prototype,r.prototype.type="checkbox",r.prototype.render=function(){return this.clearPos(!0),this.setContent("["+(this.checked?"x":" ")+"] "+this.text,!0),this._render()},r.prototype.check=function(){this.checked||(this.checked=this.value=!0,this.emit("check"))},r.prototype.uncheck=function(){this.checked&&(this.checked=this.value=!1,this.emit("uncheck"))},r.prototype.toggle=function(){return this.checked?this.uncheck():this.check()},module.exports=r;
//# sourceMappingURL=checkbox.js.map