You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plumbing.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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) {
  7. width = 80
  8. }
  9. validate('OAN', [theme, template, width])
  10. this.showing = false
  11. this.theme = theme
  12. this.width = width
  13. this.template = template
  14. }
  15. Plumbing.prototype = {}
  16. Plumbing.prototype.setTheme = function (theme) {
  17. validate('O', [theme])
  18. this.theme = theme
  19. }
  20. Plumbing.prototype.setTemplate = function (template) {
  21. validate('A', [template])
  22. this.template = template
  23. }
  24. Plumbing.prototype.setWidth = function (width) {
  25. validate('N', [width])
  26. this.width = width
  27. }
  28. Plumbing.prototype.hide = function () {
  29. return consoleControl.gotoSOL() + consoleControl.eraseLine()
  30. }
  31. Plumbing.prototype.hideCursor = consoleControl.hideCursor
  32. Plumbing.prototype.showCursor = consoleControl.showCursor
  33. Plumbing.prototype.show = function (status) {
  34. var values = Object.create(this.theme)
  35. for (var key in status) {
  36. values[key] = status[key]
  37. }
  38. return renderTemplate(this.width, this.template, values).trim() +
  39. consoleControl.color('reset') +
  40. consoleControl.eraseLine() + consoleControl.gotoSOL()
  41. }