diff --git a/lib/widgets/w3mimage.js b/lib/widgets/w3mimage.js index 4dc969a..1fefda2 100644 --- a/lib/widgets/w3mimage.js +++ b/lib/widgets/w3mimage.js @@ -1,5 +1,5 @@ /** - * image.js - w3m image element for blessed + * w3mimage.js - w3m image element for blessed * Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License). * https://github.com/chjj/blessed */ @@ -17,16 +17,16 @@ var Node = require('./node'); var Box = require('./box'); /** - * Image + * W3MImage * Good example of w3mimgdisplay commands: * https://github.com/hut/ranger/blob/master/ranger/ext/img_display.py */ -function Image(options) { +function W3MImage(options) { var self = this; if (!(this instanceof Node)) { - return new Image(options); + return new W3MImage(options); } options = options || {}; @@ -34,21 +34,21 @@ function Image(options) { Box.call(this, options); if (options.w3m) { - Image.w3mdisplay = options.w3m; + W3MImage.w3mdisplay = options.w3m; } - if (Image.hasW3MDisplay == null) { - if (fs.existsSync(Image.w3mdisplay)) { - Image.hasW3MDisplay = true; + if (W3MImage.hasW3MDisplay == null) { + if (fs.existsSync(W3MImage.w3mdisplay)) { + W3MImage.hasW3MDisplay = true; } else if (options.search !== false) { var file = helpers.findFile('/usr', 'w3mimgdisplay') || helpers.findFile('/lib', 'w3mimgdisplay') || helpers.findFile('/bin', 'w3mimgdisplay'); if (file) { - Image.hasW3MDisplay = true; - Image.w3mdisplay = file; + W3MImage.hasW3MDisplay = true; + W3MImage.w3mdisplay = file; } else { - Image.hasW3MDisplay = false; + W3MImage.hasW3MDisplay = false; } } } @@ -82,7 +82,7 @@ function Image(options) { // self.screen.program.flush(); // if (!self._noImage) return; // function display(el, next) { - // if (el.type === 'image' && el.file) { + // if (el.type === 'w3mimage' && el.file) { // el.setImage(el.file, next); // } else { // next(); @@ -116,13 +116,13 @@ function Image(options) { } } -Image.prototype.__proto__ = Box.prototype; +W3MImage.prototype.__proto__ = Box.prototype; -Image.prototype.type = 'w3mimage'; +W3MImage.prototype.type = 'w3mimage'; -Image.w3mdisplay = '/usr/lib/w3m/w3mimgdisplay'; +W3MImage.w3mdisplay = '/usr/lib/w3m/w3mimgdisplay'; -Image.prototype.spawn = function(file, args, opt, callback) { +W3MImage.prototype.spawn = function(file, args, opt, callback) { var screen = this.screen , opt = opt || {} , spawn = require('child_process').spawn @@ -144,7 +144,7 @@ Image.prototype.spawn = function(file, args, opt, callback) { return ps; }; -Image.prototype.setImage = function(img, callback) { +W3MImage.prototype.setImage = function(img, callback) { var self = this; if (this._settingImage) { @@ -163,7 +163,7 @@ Image.prototype.setImage = function(img, callback) { } }; - if (Image.hasW3MDisplay === false) { + if (W3MImage.hasW3MDisplay === false) { reset(); if (!callback) return; return callback(new Error('W3M Image Display not available.')); @@ -242,7 +242,7 @@ Image.prototype.setImage = function(img, callback) { }); }; -Image.prototype.renderImage = function(img, ratio, callback) { +W3MImage.prototype.renderImage = function(img, ratio, callback) { var self = this; if (cp.execSync) { @@ -254,7 +254,7 @@ Image.prototype.renderImage = function(img, ratio, callback) { } } - if (Image.hasW3MDisplay === false) { + if (W3MImage.hasW3MDisplay === false) { if (!callback) return; return callback(new Error('W3M Image Display not available.')); } @@ -279,7 +279,7 @@ Image.prototype.renderImage = function(img, ratio, callback) { cwd: process.env.HOME }; - var ps = self.spawn(Image.w3mdisplay, [], opt, function(err, success) { + var ps = self.spawn(W3MImage.w3mdisplay, [], opt, function(err, success) { if (!callback) return; return err ? callback(err) @@ -311,7 +311,7 @@ Image.prototype.renderImage = function(img, ratio, callback) { }); }; -Image.prototype.clearImage = function(callback) { +W3MImage.prototype.clearImage = function(callback) { var self = this; if (cp.execSync) { @@ -323,7 +323,7 @@ Image.prototype.clearImage = function(callback) { } } - if (Image.hasW3MDisplay === false) { + if (W3MImage.hasW3MDisplay === false) { if (!callback) return; return callback(new Error('W3M Image Display not available.')); } @@ -339,7 +339,7 @@ Image.prototype.clearImage = function(callback) { cwd: process.env.HOME }; - var ps = this.spawn(Image.w3mdisplay, [], opt, function(err, success) { + var ps = this.spawn(W3MImage.w3mdisplay, [], opt, function(err, success) { if (!callback) return; return err ? callback(err) @@ -373,7 +373,7 @@ Image.prototype.clearImage = function(callback) { ps.stdin.end(); }; -Image.prototype.imageSize = function(callback) { +W3MImage.prototype.imageSize = function(callback) { var self = this; var img = this.file; @@ -386,7 +386,7 @@ Image.prototype.imageSize = function(callback) { } } - if (Image.hasW3MDisplay === false) { + if (W3MImage.hasW3MDisplay === false) { if (!callback) return; return callback(new Error('W3M Image Display not available.')); } @@ -402,7 +402,7 @@ Image.prototype.imageSize = function(callback) { cwd: process.env.HOME }; - var ps = this.spawn(Image.w3mdisplay, [], opt); + var ps = this.spawn(W3MImage.w3mdisplay, [], opt); var buf = ''; @@ -433,7 +433,7 @@ Image.prototype.imageSize = function(callback) { ps.stdin.end(); }; -Image.prototype.termSize = function(callback) { +W3MImage.prototype.termSize = function(callback) { var self = this; if (cp.execSync) { @@ -445,7 +445,7 @@ Image.prototype.termSize = function(callback) { } } - if (Image.hasW3MDisplay === false) { + if (W3MImage.hasW3MDisplay === false) { if (!callback) return; return callback(new Error('W3M Image Display not available.')); } @@ -456,7 +456,7 @@ Image.prototype.termSize = function(callback) { cwd: process.env.HOME }; - var ps = this.spawn(Image.w3mdisplay, ['-test'], opt); + var ps = this.spawn(W3MImage.w3mdisplay, ['-test'], opt); var buf = ''; @@ -492,7 +492,7 @@ Image.prototype.termSize = function(callback) { ps.stdin.end(); }; -Image.prototype.getPixelRatio = function(callback) { +W3MImage.prototype.getPixelRatio = function(callback) { var self = this; if (cp.execSync) { @@ -524,10 +524,10 @@ Image.prototype.getPixelRatio = function(callback) { }); }; -Image.prototype.renderImageSync = function(img, ratio) { +W3MImage.prototype.renderImageSync = function(img, ratio) { var self = this; - if (Image.hasW3MDisplay === false) { + if (W3MImage.hasW3MDisplay === false) { throw new Error('W3M Image Display not available.'); } @@ -565,7 +565,7 @@ Image.prototype.renderImageSync = function(img, ratio) { }; try { - cp.execFileSync(Image.w3mdisplay, [], { + cp.execFileSync(W3MImage.w3mdisplay, [], { env: process.env, encoding: 'utf8', input: input, @@ -578,8 +578,8 @@ Image.prototype.renderImageSync = function(img, ratio) { return true; }; -Image.prototype.clearImageSync = function() { - if (Image.hasW3MDisplay === false) { +W3MImage.prototype.clearImageSync = function() { + if (W3MImage.hasW3MDisplay === false) { throw new Error('W3M Image Display not available.'); } @@ -611,7 +611,7 @@ Image.prototype.clearImageSync = function() { delete this._lastSize; try { - cp.execFileSync(Image.w3mdisplay, [], { + cp.execFileSync(W3MImage.w3mdisplay, [], { env: process.env, encoding: 'utf8', input: input, @@ -624,10 +624,10 @@ Image.prototype.clearImageSync = function() { return true; }; -Image.prototype.imageSizeSync = function() { +W3MImage.prototype.imageSizeSync = function() { var img = this.file; - if (Image.hasW3MDisplay === false) { + if (W3MImage.hasW3MDisplay === false) { throw new Error('W3M Image Display not available.'); } @@ -639,7 +639,7 @@ Image.prototype.imageSizeSync = function() { var input = '5;' + img + '\n'; try { - buf = cp.execFileSync(Image.w3mdisplay, [], { + buf = cp.execFileSync(W3MImage.w3mdisplay, [], { env: process.env, encoding: 'utf8', input: input, @@ -658,15 +658,15 @@ Image.prototype.imageSizeSync = function() { }; }; -Image.prototype.termSizeSync = function(_, recurse) { - if (Image.hasW3MDisplay === false) { +W3MImage.prototype.termSizeSync = function(_, recurse) { + if (W3MImage.hasW3MDisplay === false) { throw new Error('W3M Image Display not available.'); } var buf = ''; try { - buf = cp.execFileSync(Image.w3mdisplay, ['-test'], { + buf = cp.execFileSync(W3MImage.w3mdisplay, ['-test'], { env: process.env, encoding: 'utf8', timeout: 1000 @@ -694,7 +694,7 @@ Image.prototype.termSizeSync = function(_, recurse) { }; }; -Image.prototype.getPixelRatioSync = function() { +W3MImage.prototype.getPixelRatioSync = function() { var self = this; // XXX We could cache this, but sometimes it's better @@ -714,7 +714,7 @@ Image.prototype.getPixelRatioSync = function() { return this._ratio; }; -Image.prototype.displayImage = function(callback) { +W3MImage.prototype.displayImage = function(callback) { return this.screen.displayImage(this.file, callback); }; @@ -722,4 +722,4 @@ Image.prototype.displayImage = function(callback) { * Expose */ -module.exports = Image; +module.exports = W3MImage;