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