a zip code crypto-currency system good for red ONLY

plumbing.js 1.2KB

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