minor fixes for ANSIImage.

This commit is contained in:
Christopher Jeffrey 2015-07-17 03:17:59 -07:00
parent 97d72926a5
commit b9005e6bfe

View File

@ -75,21 +75,26 @@ ANSIImage.curl = function(url) {
};
ANSIImage.prototype.setImage = function(file) {
var self = this;
this.file = typeof file === 'string' ? file : null;
if (/^https?:/.test(file)) {
file = ANSIImage.curl(file);
}
var width = this.position.width;
var height = this.position.height;
if (width != null) {
width = this.width;
}
if (height != null) {
height = this.height;
}
try {
this.setContent('');
this.img = tng(file, {
colors: colors,
width: width,
@ -99,17 +104,16 @@ ANSIImage.prototype.setImage = function(file) {
speed: this.options.speed,
filename: this.file
});
if (width == null || height == null) {
this.width = this.img.cellmap[0].length;
this.height = this.img.cellmap.length;
}
if (this.img.frames && this.options.animate) {
this.img.play(function(bmp, cellmap) {
self.cellmap = cellmap;
self.screen.render();
});
this.play();
} else {
self.cellmap = self.img.cellmap;
this.cellmap = this.img.cellmap;
}
} catch (e) {
this.setContent('Image Error: ' + e.message);
@ -118,8 +122,12 @@ ANSIImage.prototype.setImage = function(file) {
}
};
ANSIImage.prototype.play = function() {
return this.img.play();
ANSIImage.prototype.play = function(callback) {
var self = this;
return this.img.play(callback || function(bmp, cellmap) {
self.cellmap = cellmap;
self.screen.render();
});
};
ANSIImage.prototype.pause = function() {
@ -131,7 +139,7 @@ ANSIImage.prototype.stop = function() {
};
ANSIImage.prototype.clearImage = function() {
if (this.img && this.img.frames) {
if (this.img) {
this.stop();
}
this.setContent('');