tidal-cli-client
Version:
You can now use Tidal on linux. With your loved CLI. <3
55 lines (44 loc) • 1.61 kB
JavaScript
const blessed = require("blessed");
const BaseElement = require("../../abstract/BaseElement");
const imageSize = require("image-size");
module.exports = class extends BaseElement {
constructor(parent, options, imageSrc = undefined) {
super(parent);
this.options = options;
this.updateElement(imageSrc);
}
updateElement(imageSrc) {
if(!imageSrc) {
return;
}
this.imageSrc = imageSrc;
if(!this.options.pixelRatio) {
this.element = blessed.text(Object.assign({}, this.options, {
width: (this.options.width * 100) + "%",
height: (this.options.height * 100) + "%",
content: "Images are not displayed.\nTo display images install w3m and w3m-img."
}));
return;
}
let width;
let height;
let imageDiemensions = imageSize(this.imageSrc);
let proportions = imageDiemensions.width / imageDiemensions.height;
let masterParent = this.getMasterParent();
if(this.options.width) {
width = (this.options.pixelRatio.tw * masterParent.width * this.options.width) / this.options.pixelRatio.tw;
height = (this.options.pixelRatio.tw * masterParent.width * this.options.width) / this.options.pixelRatio.th / proportions;
}
else if(this.options.height) {
width = (this.options.pixelRatio.th * masterParent.height * this.options.height) / this.options.pixelRatio.tw;
height = (this.options.pixelRatio.th * masterParent.height * this.options.height) / this.options.pixelRatio.th / proportions;
}
this.element = blessed.image(Object.assign({}, this.options, {
type: "overlay",
width,
height,
file: this.imageSrc,
search: true
}));
}
};