Code coverage report for slap/lib/ui/Field.js

Statements: 76.67% (23 / 30)      Branches: 40% (4 / 10)      Functions: 60% (3 / 5)      Lines: 91.67% (22 / 24)      Ignored: none     

All files » slap/lib/ui/ » Field.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 421 1   1 1 1   1 1   1 4   4   4             4 4   1   1 1 1 4 4 15         4     1  
var blessed = require('blessed');
var _ = require('lazy.js');
 
var Slap = require('./Slap');
var Editor = require('./Editor');
var BaseForm = require('./BaseForm');
 
var util = require('../util');
var textUtil = require('../textUtil');
 
function Field (opts) {
  var self = this;
 
  Iif (!(self instanceof blessed.Node)) return new Field(opts);
 
  Editor.call(self, _({
      height: 1,
      multiLine: false
    })
    .merge(Slap.global.options.field || {})
    .merge(opts || {})
    .toObject());
  Eif (self.parent instanceof BaseForm) self.form = self.parent;
  self.language(false);
}
Field.prototype.__proto__ = Editor.prototype;
 
Field.prototype.submit = function (value) { this.emit('submit', value); }
Field.prototype.cancel = function () { this.emit('cancel'); }
Field.prototype._initHandlers = function () {
  var self = this;
  self.on('keypress', function (ch, key) {
    switch (util.getBinding(self.options.bindings, key)) {
      case 'submit': self.submit(self.textBuf.getText()); return false;
      case 'cancel': self.cancel(); return false;
    };
  });
  return Editor.prototype._initHandlers.apply(self, arguments);
}
 
module.exports = Field;