add sendFocus option. see #149.

This commit is contained in:
Christopher Jeffrey 2015-07-04 03:30:26 -07:00
parent 90367cd891
commit 77bd73b4c8
4 changed files with 51 additions and 3 deletions

View File

@ -332,6 +332,7 @@ The screen on which every other node renders.
replaced by `'??'`, `'?'`, `''` respectively. (NOTE: iTerm2 cannot display
combining characters properly. Blessed simply removes them from an element's
content if iTerm2 is detected).
- __sendFocus__ - send focus events after mouse is enabled.
##### Properties:

View File

@ -3202,10 +3202,17 @@ Program.prototype.setMouse = function(opt, enable) {
opt.vt200Hilite = opt.hiliteTracking;
}
if (enable) {
if (enable === true) {
if (this._currentMouse) {
this.setMouse(opt);
Object.keys(opt).forEach(function(key) {
this._currentMouse[key] = opt[key];
}, this);
return;
}
this._currentMouse = opt;
this.mouseEnabled = true;
} else {
} else if (enable === false) {
delete this._currentMouse;
this.mouseEnabled = false;
}

View File

@ -352,6 +352,9 @@ Screen.prototype._listenMouse = function(el) {
this._listenedMouse = true;
this.program.enableMouse();
if (this.options.sendFocus) {
this.program.setMouse({ sendFocus: true }, true);
}
this.on('render', function() {
self._needsClickableSort = true;
@ -1648,7 +1651,12 @@ Screen.prototype.spawn = function(file, args, options) {
program.alternateBuffer();
// program.csr(0, program.rows - 1);
if (mouse) program.enableMouse();
if (mouse) {
program.enableMouse();
if (self.options.sendFocus) {
self.program.setMouse({ sendFocus: true }, true);
}
}
screen.alloc();
screen.render();

View File

@ -18,6 +18,11 @@ program.alternateBuffer();
program.enableMouse();
program.hideCursor();
program.setMouse({ sendFocus: true }, true);
//program._currentMouse.sendFocus = true;
//program.enableMouse(program._currentMouse);
//program.write('\x1b[?1004h');
program.on('mouse', function(data) {
program.cup(data.y, data.x);
program.write(' ', 'blue bg');
@ -25,6 +30,33 @@ program.on('mouse', function(data) {
program.write(util.inspect(data));
});
program.on('resize', function(data) {
setTimeout(function() {
program.clear();
program.cup(0, 0);
program.write(util.inspect({ cols: program.cols, rows: program.rows }));
}, 200);
});
process.on('SIGWINCH', function(data) {
setTimeout(function() {
program.cup(1, 0);
program.write(util.inspect({ winch: true, cols: program.cols, rows: program.rows }));
}, 200);
});
program.on('focus', function(data) {
program.clear();
program.cup(0, 0);
program.write('FOCUSIN');
});
program.on('blur', function(data) {
program.clear();
program.cup(0, 0);
program.write('FOCUSOUT');
});
program.key(['q', 'escape', 'C-c'], function() {
program.showCursor();
program.disableMouse();