1'use strict' 2var consoleControl = require('console-control-strings') 3var renderTemplate = require('./render-template.js') 4var validate = require('aproba') 5 6var Plumbing = module.exports = function (theme, template, width) { 7 if (!width) width = 80 8 validate('OAN', [theme, template, width]) 9 this.showing = false 10 this.theme = theme 11 this.width = width 12 this.template = template 13} 14Plumbing.prototype = {} 15 16Plumbing.prototype.setTheme = function (theme) { 17 validate('O', [theme]) 18 this.theme = theme 19} 20 21Plumbing.prototype.setTemplate = function (template) { 22 validate('A', [template]) 23 this.template = template 24} 25 26Plumbing.prototype.setWidth = function (width) { 27 validate('N', [width]) 28 this.width = width 29} 30 31Plumbing.prototype.hide = function () { 32 return consoleControl.gotoSOL() + consoleControl.eraseLine() 33} 34 35Plumbing.prototype.hideCursor = consoleControl.hideCursor 36 37Plumbing.prototype.showCursor = consoleControl.showCursor 38 39Plumbing.prototype.show = function (status) { 40 var values = Object.create(this.theme) 41 for (var key in status) { 42 values[key] = status[key] 43 } 44 45 return renderTemplate(this.width, this.template, values).trim() + 46 consoleControl.color('reset') + 47 consoleControl.eraseLine() + consoleControl.gotoSOL() 48} 49