diff --git a/lib/widget.js b/lib/widget.js index a6e9817..55f4742 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -170,6 +170,13 @@ Screen._default = null; Screen.prototype.__proto__ = Node.prototype; +Screen._addListener = Screen.prototype.addListener; +Screen.prototype.on = +Screen.prototype.addListener = function(type, listener) { + if (type === 'keypress') this._listenKeys(); + return Screen._addListener.apply(this, arguments); +}; + // TODO: Bubble events. Screen.prototype._listenMouse = function(el, hover) { var self = this; diff --git a/test/widget-pos.js b/test/widget-pos.js new file mode 100644 index 0000000..708d008 --- /dev/null +++ b/test/widget-pos.js @@ -0,0 +1,49 @@ +var blessed = require('blessed') + , program = blessed(); + +var screen = new blessed.Screen({ + program: program +}); + +var main = new blessed.Box({ + width: '75%', + height: '75%', + bg: 3, + top: 2, + left: 2, + content: 'Welcome to my program' +}); + +screen.append(main); + +var inner = new blessed.Box({ + width: '50%', + height: '50%', + bg: 4, + top: 2, + left: 2, + content: 'Hello' +}); + +main.append(inner); + +inner.setContent(inner.content + '\n' + JSON.stringify({ + left: inner.left, + right: inner.right, + top: inner.top, + bottom: inner.bottom, + width: inner.width, + height: inner.height, + rleft: inner.rleft, + rright: inner.rright, + rtop: inner.rtop, + rbottom: inner.rbottom +})); + +screen.on('keypress', function(ch, key) { + if (key.name === 'escape' || key.name === 'q') { + return process.exit(0); + } +}); + +screen.render();