# Code coverage report for lib/ui/Button.js

## Statements: 85.71% (18 / 21) Branches: 33.33% (2 / 6) Functions: 66.67% (2 / 3) Lines: 94.74% (18 / 19) Ignored: none

All files » lib/ui/ » Button.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
    341
    1

    1
    1

    1

    1
    3

    3

    3

    3
    3
    3

    1
    1
    3
    3

    3

    1
     var blessed = require('blessed');
    var _ = require('lazy.js');

    var Slap = require('./Slap');
    var BaseElement = require('./BaseElement');

    var util = require('../util');

    function Button (opts) {
      var self = this;

      Iif (!(self instanceof blessed.Node)) return new Button(opts);

      opts = _(Slap.global.options.button).merge({
        mouse: true,
        focusable: true,
        shrink: true,
        padding: {left: 1, right: 1}
      }).merge(opts || {}).toObject();
      opts.style.focus = opts.style.hover;
      blessed.Button.call(self, opts);
      BaseElement.call(self, opts);
    }
    Button.prototype.__proto__ = blessed.Button.prototype;
    Button.prototype._initHandlers = function () {
      var self = this;
      self.on('keypress', function (ch, key) {
        if (key.name === 'enter') self.slap._stopKeyPropagation().done(); // FIXME: hack
      });
      return BaseElement.prototype._initHandlers.apply(self, arguments);
    };

    module.exports = Button;