From cce38f9f21807426b64c95e3544a078d2eff7f2f Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 9 Feb 2015 00:09:30 -0800 Subject: [PATCH] improve w3m checking for Image element and screen.displayImage. --- lib/widget.js | 45 ++++----------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index e34de9d..f213c65 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -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 = 'press q to exit' @@ -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 */