'use strict'
var consoleStrings = require('./console-strings.js')
var renderTemplate = require('./render-template.js')
var validate = require('aproba')

var Plumbing = module.exports = function (theme, template, width) {
  if (!width) width = 80
  validate('OAN', [theme, template, width])
  this.showing = false
  this.theme = theme
  this.width = width
  this.template = template
}
Plumbing.prototype = {}

Plumbing.prototype.setTheme = function (theme) {
  validate('O', [theme])
  this.theme = theme
}

Plumbing.prototype.setTemplate = function (template) {
  validate('A', [template])
  this.template = template
}

Plumbing.prototype.setWidth = function (width) {
  validate('N', [width])
  this.width = width
}

Plumbing.prototype.hide = function () {
  return consoleStrings.gotoSOL() + consoleStrings.eraseLine()
}

Plumbing.prototype.hideCursor = consoleStrings.hideCursor

Plumbing.prototype.showCursor = consoleStrings.showCursor

Plumbing.prototype.show = function (status) {
  var values = Object.create(this.theme)
  for (var key in status) {
    values[key] = status[key]
  }

  return renderTemplate(this.width, this.template, values) +
         consoleStrings.eraseLine() + consoleStrings.gotoSOL()
}

'use strict'
var consoleStrings = require('./console-strings.js')
var renderTemplate = require('./render-template.js')
var validate = require('aproba')

var Plumbing = module.exports = function (theme, template, width) {
  if (!width) width = 80
  validate('OAN', [theme, template, width])
  this.showing = false
  this.theme = theme
  this.width = width
  this.template = template
}
Plumbing.prototype = {}

Plumbing.prototype.setTheme = function (theme) {
  validate('O', [theme])
  this.theme = theme
}

Plumbing.prototype.setTemplate = function (template) {
  validate('A', [template])
  this.template = template
}

Plumbing.prototype.setWidth = function (width) {
  validate('N', [width])
  this.width = width
}

Plumbing.prototype.hide = function () {
  return consoleStrings.gotoSOL() + consoleStrings.eraseLine()
}

Plumbing.prototype.hideCursor = consoleStrings.hideCursor

Plumbing.prototype.showCursor = consoleStrings.showCursor

Plumbing.prototype.show = function (status) {
  var values = Object.create(this.theme)
  for (var key in status) {
    values[key] = status[key]
  }

  return renderTemplate(this.width, this.template, values).trim() +
         consoleStrings.eraseLine() + consoleStrings.gotoSOL()
}

Trim the output line, since we're erasing to EOL anyway
Trim the output line, since we're erasing to EOL anyway

Currently renderTemplate ALWAYS produces a string of the length you specify,
even if it has to pad stuff to produce that.  This renders the
"erase-to-eol" command meaningless, so we either should ditch that or we
should trim the renderTemplate output. Right now I'm opting for the
latter, but testing the former would be useful too.
