mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-02-03 06:34:05 +00:00
improve w3m checking for Image element and screen.displayImage.
This commit is contained in:
parent
4c1e020b42
commit
cce38f9f21
@ -6563,11 +6563,9 @@ function Image(options) {
|
|||||||
|
|
||||||
Box.call(this, options);
|
Box.call(this, options);
|
||||||
|
|
||||||
if (Image.hasW3MDisplay == null && !Image._checkingW3MDisplay) {
|
if (Image.hasW3MDisplay == null) {
|
||||||
if (fs.existsSync(Image.w3mdisplay)) {
|
if (fs.existsSync(Image.w3mdisplay)) {
|
||||||
Image.hasW3MDisplay = true;
|
Image.hasW3MDisplay = true;
|
||||||
} else {
|
|
||||||
this._waitForW3MDisplay();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6592,11 +6590,10 @@ Image.prototype.render = function() {
|
|||||||
Image.prototype.spawn = function(file, args, opt, callback) {
|
Image.prototype.spawn = function(file, args, opt, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (Image._checkingW3MDisplay) {
|
if (Image.hasW3MDisplay == null) {
|
||||||
setTimeout(function() {
|
return this._waitForW3MDisplay(function() {
|
||||||
return self.spawn(file, args, opt, callback);
|
return self.spawn(file, args, opt, callback);
|
||||||
}, 500);
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Image.hasW3MDisplay === false) {
|
if (Image.hasW3MDisplay === false) {
|
||||||
@ -6902,17 +6899,6 @@ Screen.prototype.displayImage = function(file, callback) {
|
|||||||
return callback(new Error('No image.'));
|
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 file = path.resolve(process.cwd(), file);
|
||||||
var args = ['w3m', '-T', 'text/html'];
|
var args = ['w3m', '-T', 'text/html'];
|
||||||
var input = '<title>press q to exit</title>'
|
var input = '<title>press q to exit</title>'
|
||||||
@ -6940,29 +6926,6 @@ Screen.prototype.displayImage = function(file, callback) {
|
|||||||
ps.stdin.end();
|
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
|
* Helpers
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user