improve w3m checking for Image element and screen.displayImage.

This commit is contained in:
Christopher Jeffrey 2015-02-09 00:09:30 -08:00
parent 4c1e020b42
commit cce38f9f21

View File

@ -6563,11 +6563,9 @@ function Image(options) {
Box.call(this, options);
if (Image.hasW3MDisplay == null && !Image._checkingW3MDisplay) {
if (Image.hasW3MDisplay == null) {
if (fs.existsSync(Image.w3mdisplay)) {
Image.hasW3MDisplay = true;
} else {
this._waitForW3MDisplay();
}
}
@ -6592,11 +6590,10 @@ Image.prototype.render = function() {
Image.prototype.spawn = function(file, args, opt, callback) {
var self = this;
if (Image._checkingW3MDisplay) {
setTimeout(function() {
if (Image.hasW3MDisplay == null) {
return this._waitForW3MDisplay(function() {
return self.spawn(file, args, opt, callback);
}, 500);
return;
});
}
if (Image.hasW3MDisplay === false) {
@ -6902,17 +6899,6 @@ Screen.prototype.displayImage = function(file, callback) {
return callback(new Error('No image.'));
}
if (Image.hasW3M == null) {
return this._waitForW3M(function() {
return self.displayImage(file, callback);
});
}
if (Image.hasW3M === false) {
if (!callback) return;
return callback(new Error('W3M not available.'));
}
var file = path.resolve(process.cwd(), file);
var args = ['w3m', '-T', 'text/html'];
var input = '<title>press q to exit</title>'
@ -6940,29 +6926,6 @@ Screen.prototype.displayImage = function(file, callback) {
ps.stdin.end();
};
Screen.prototype._waitForW3M = function(callback) {
var self = this;
if (Image.hasW3M == null) {
if (Image._checkingW3M) {
setTimeout(function() {
return self._waitForW3M(callback);
}, 500);
return;
}
Image._checkingW3M = true;
return this.exec(process.env.SHELL, ['-c', 'type w3m'], {stdio: 'ignore'}, function(err, success) {
Image._checkingW3M = false;
Image.hasW3M = !!success;
return self._waitForW3M(callback);
});
}
if (callback) callback();
};
/**
* Helpers
*/