fix initial setContent call. fix spawn() cursor handling.

This commit is contained in:
Christopher Jeffrey 2013-07-23 16:37:54 -05:00
parent da49a89b28
commit 9aaabacf68
2 changed files with 38 additions and 41 deletions

View File

@ -1416,7 +1416,7 @@ Program.prototype.lrestoreCursor = function(key, hide) {
var key = key || 'local', pos; var key = key || 'local', pos;
if (!this._saved || !this._saved[key]) return; if (!this._saved || !this._saved[key]) return;
pos = this._saved[key]; pos = this._saved[key];
delete this._saved[key]; //delete this._saved[key];
this.cup(pos.y, pos.x); this.cup(pos.y, pos.x);
if (hide && pos.hidden !== this.cursorHidden) { if (hide && pos.hidden !== this.cursorHidden) {
if (pos.hidden) { if (pos.hidden) {
@ -1745,6 +1745,7 @@ Program.prototype.eraseInDisplay = function(param) {
}; };
Program.prototype.clear = function() { Program.prototype.clear = function() {
this.x = this.y = 0;
if (this.tput) return this.put.clear(); if (this.tput) return this.put.clear();
return this.write('\x1b[H\x1b[J'); return this.write('\x1b[H\x1b[J');
// return this.ed('all'); // return this.ed('all');
@ -3372,11 +3373,18 @@ Program.prototype.out = function(name) {
Program.prototype.sigtstp = function(callback) { Program.prototype.sigtstp = function(callback) {
var self = this var self = this
, isAlt = this.isAlt , isAlt = this.isAlt
, currentMouse = this._currentMouse , currentMouse = this._currentMouse;
, cursorHidden = this.cursorHidden;
this.lsaveCursor('sigtstp');
//this.csr(0, screen.height - 1);
if (isAlt) this.normalBuffer();
this.showCursor();
if (currentMouse) this.disableMouse();
var write = this.output.write; var write = this.output.write;
this.output.write = function() {}; this.output.write = function() {};
this.input.setRawMode(false);
this.input.pause();
process.once('SIGCONT', function() { process.once('SIGCONT', function() {
self.input.setRawMode(true); self.input.setRawMode(true);
@ -3384,21 +3392,13 @@ Program.prototype.sigtstp = function(callback) {
self.output.write = write; self.output.write = write;
if (isAlt) self.alternateBuffer(); if (isAlt) self.alternateBuffer();
if (cursorHidden) self.hideCursor(); //self.csr(0, screen.height - 1);
if (currentMouse) self.enableMouse(); if (currentMouse) self.enableMouse();
self.lrestoreCursor('sigtstp', true);
self.cup(self.y, self.x);
if (callback) callback(); if (callback) callback();
}); });
if (currentMouse) this.disableMouse();
if (cursorHidden) this.showCursor();
if (isAlt) this.normalBuffer();
this.input.setRawMode(false);
this.input.pause();
process.kill(process.pid, 'SIGTSTP'); process.kill(process.pid, 'SIGTSTP');
}; };

View File

@ -1395,49 +1395,45 @@ Screen.prototype.spawn = function(file, args, options) {
args = []; args = [];
} }
var options = options || {} var screen = this
, program = screen.program
, options = options || {}
, spawn = require('child_process').spawn , spawn = require('child_process').spawn
, screen = this; , mouse = program._currentMouse
, ps;
options.stdio = 'inherit'; options.stdio = 'inherit';
screen.program.saveCursor(); program.lsaveCursor('spawn');
screen.program.normalBuffer(); //program.csr(0, program.rows - 1);
screen.program.showCursor(); program.normalBuffer();
program.showCursor();
if (mouse) program.disableMouse();
var listenedMouse = screen._listenedMouse; var write = program.output.write;
if (listenedMouse) { program.output.write = function() {};
screen.program.disableMouse(); program.input.pause();
} program.input.setRawMode(false);
var write = screen.program.output.write;
screen.program.output.write = function() {};
screen.program.input.pause();
screen.program.input.setRawMode(false);
var resume = function() { var resume = function() {
if (resume.done) return; if (resume.done) return;
resume.done = true; resume.done = true;
screen.program.input.setRawMode(true); program.input.setRawMode(true);
screen.program.input.resume(); program.input.resume();
screen.program.output.write = write; program.output.write = write;
screen.program.alternateBuffer(); program.alternateBuffer();
// Restoring the cursor, or resetting to program.x/y - either works. //program.csr(0, program.rows - 1);
// Technically, restoring cursor might be more foolproof. if (mouse) program.enableMouse();
// screen.program.cup(screen.program.y, screen.program.x);
screen.program.restoreCursor();
screen.program.hideCursor();
if (listenedMouse) {
screen.program.enableMouse();
}
screen.alloc(); screen.alloc();
screen.render(); screen.render();
screen.program.lrestoreCursor('spawn', true);
}; };
var ps = spawn(file, args, options); ps = spawn(file, args, options);
ps.on('error', resume); ps.on('error', resume);
@ -1560,6 +1556,7 @@ Screen.prototype.sigtstp = function(callback) {
this.program.sigtstp(function() { this.program.sigtstp(function() {
self.alloc(); self.alloc();
self.render(); self.render();
self.program.lrestoreCursor('sigtstp', true);
if (callback) callback(); if (callback) callback();
}); });
}; };
@ -1662,7 +1659,7 @@ function Element(options) {
this.parseTags = options.parseTags || options.tags; this.parseTags = options.parseTags || options.tags;
this.setContent(options.content || ''); this.setContent(options.content || '', true);
if (options.label) { if (options.label) {
this.append(new Box({ this.append(new Box({