debug log.

This commit is contained in:
Christopher Jeffrey 2015-04-04 02:23:43 -07:00
parent 7afb791950
commit bb4a8c82aa
3 changed files with 26 additions and 17 deletions

View File

@ -10,7 +10,12 @@
process.title = 'multiplex.js'; process.title = 'multiplex.js';
var blessed = require('blessed') var blessed = require('blessed')
, screen = blessed.screen(); , screen;
screen = blessed.screen({
smartCSR: true,
log: process.env.HOME + '/blessed-terminal.log'
});
var left = blessed.terminal({ var left = blessed.terminal({
parent: screen, parent: screen,
@ -33,6 +38,10 @@ var left = blessed.terminal({
} }
}); });
left.pty.on('data', function(data) {
screen.log(JSON.stringify(data));
});
var right = blessed.terminal({ var right = blessed.terminal({
parent: screen, parent: screen,
cursor: 'block', cursor: 'block',

View File

@ -474,7 +474,7 @@ Screen.prototype.leave = function() {
Screen.prototype.postEnter = function() { Screen.prototype.postEnter = function() {
var self = this; var self = this;
if (this.options.debug) { if (this.options.debug) {
this._debugLog = new Log({ this.debugLog = new Log({
parent: this, parent: this,
hidden: true, hidden: true,
draggable: true, draggable: true,
@ -504,34 +504,34 @@ Screen.prototype.postEnter = function() {
} }
}); });
this._debugLog._.toggle = function() { this.debugLog.toggle = function() {
if (self._debugLog.hidden) { if (self.debugLog.hidden) {
self.saveFocus(); self.saveFocus();
self._debugLog.show(); self.debugLog.show();
self._debugLog.setFront(); self.debugLog.setFront();
self._debugLog.focus(); self.debugLog.focus();
} else { } else {
self._debugLog.hide(); self.debugLog.hide();
self.restoreFocus(); self.restoreFocus();
} }
self.render(); self.render();
}; };
this._debugLog.key(['q', 'escape'], self._debugLog._.toggle); this.debugLog.key(['q', 'escape'], self.debugLog.toggle);
this.key('f12', self._debugLog._.toggle); this.key('f12', self.debugLog.toggle);
} }
}; };
Screen.prototype.log = function() { Screen.prototype.log = function() {
if (this._debugLog) { if (this.debugLog) {
this._debugLog.log.apply(this._debugLog, arguments); this.debugLog.log.apply(this.debugLog, arguments);
} }
return this.program.log.apply(this.program, arguments); return this.program.log.apply(this.program, arguments);
}; };
Screen.prototype.debug = function() { Screen.prototype.debug = function() {
if (this._debugLog) { if (this.debugLog) {
this._debugLog.log.apply(this._debugLog, arguments); this.debugLog.log.apply(this.debugLog, arguments);
} }
return this.program.debug.apply(this.program, arguments); return this.program.debug.apply(this.program, arguments);
}; };

View File

@ -14,13 +14,13 @@ screen = blessed.screen({
debug: true debug: true
}); });
screen._debugLog.parseTags = true; screen.debugLog.parseTags = true;
var logs = ''; var logs = '';
require('./tail')(__dirname + '/logs/widget.log').on('line', function(line) { require('./tail')(__dirname + '/logs/widget.log').on('line', function(line) {
if (!screen._debugLog.hidden) return; if (!screen.debugLog.hidden) return;
logs += line + '\n'; logs += line + '\n';
}); });
screen._debugLog.on('show', function() { screen.debugLog.on('show', function() {
if (logs) { if (logs) {
screen.debug(logs); screen.debug(logs);
logs = ''; logs = '';