improve error render system
This commit is contained in:
parent
f3d220f28c
commit
0f0e828c52
1 changed files with 22 additions and 32 deletions
48
render.js
48
render.js
|
@ -51,9 +51,8 @@ function plasma(x, y, time, k) {
|
||||||
let displaytitle = '';
|
let displaytitle = '';
|
||||||
let displayalbum = '';
|
let displayalbum = '';
|
||||||
|
|
||||||
let errorText = '';
|
// type: 0 = error, 1 = warning, 2 = info
|
||||||
let errorTimer = 0;
|
let errors = [];
|
||||||
let errorType = 0; // 0 = error, 1 = warning, 2 = info
|
|
||||||
|
|
||||||
function transform(old, n) {
|
function transform(old, n) {
|
||||||
if (old.length < n.length) {
|
if (old.length < n.length) {
|
||||||
|
@ -80,7 +79,6 @@ let time = 0;
|
||||||
function render(artist, album, title, songStart, songEnd, pauseSpot, paused) {
|
function render(artist, album, title, songStart, songEnd, pauseSpot, paused) {
|
||||||
let dt = refreshrate / 1000
|
let dt = refreshrate / 1000
|
||||||
time += dt;
|
time += dt;
|
||||||
errorTimer -= dt;
|
|
||||||
modePopup -= dt;
|
modePopup -= dt;
|
||||||
let w = process.stdout.columns;
|
let w = process.stdout.columns;
|
||||||
let h = process.stdout.rows;
|
let h = process.stdout.rows;
|
||||||
|
@ -143,21 +141,25 @@ function render(artist, album, title, songStart, songEnd, pauseSpot, paused) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorText && errorTimer > 0) {
|
let i = 0;
|
||||||
let symbol = '⚠️';
|
for (let err of errors) {
|
||||||
if (errorType === 2) symbol = 'ℹ';
|
err.timer -= dt;
|
||||||
|
if (err.timer < 0) {
|
||||||
|
errors.splice(i, 1);
|
||||||
|
} else {
|
||||||
|
let symbol = ['⚠️', '⚠️', 'ℹ'][err.type];
|
||||||
|
let color = ['\033[41;37m', '\033[43;37m', '\033[44;37m'][err.type];
|
||||||
|
let text = ` ${symbol} ${err.text} `;
|
||||||
|
|
||||||
let color = '\033[41;37m';
|
|
||||||
if (errorType === 1) color = '\033[43;37m';
|
|
||||||
if (errorType === 2) color = '\033[44;37m';
|
|
||||||
|
|
||||||
let text = ` ${symbol} ${errorText} `;
|
|
||||||
texts.push({
|
texts.push({
|
||||||
value: ' '.repeat(text.length) + text,
|
value: ' '.repeat(text.length) + text,
|
||||||
x: -text.length * 2 + Math.round((text.length + 3) * outCirc(Math.min(errorTimer, 1))),
|
x: -text.length * 2 + Math.round((text.length + 3) * outCirc(Math.min(err.timer, 1))),
|
||||||
y: 3,
|
y: 3 + i,
|
||||||
color: color
|
color: color
|
||||||
});
|
});
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modePopup > 0) {
|
if (modePopup > 0) {
|
||||||
|
@ -243,21 +245,9 @@ function render(artist, album, title, songStart, songEnd, pauseSpot, paused) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function error(content) {
|
function error(content) {errors.push({text: content, timer: errorDuration, type: 0});}
|
||||||
errorText = content;
|
function warning(content) {errors.push({text: content, timer: errorDuration, type: 1});}
|
||||||
errorTimer = errorDuration;
|
function info(content) {errors.push({text: content, timer: errorDuration, type: 2});}
|
||||||
errorType = 0;
|
|
||||||
}
|
|
||||||
function warning(content) {
|
|
||||||
errorText = content;
|
|
||||||
errorTimer = errorDuration;
|
|
||||||
errorType = 1;
|
|
||||||
}
|
|
||||||
function info(content) {
|
|
||||||
errorText = content;
|
|
||||||
errorTimer = errorDuration;
|
|
||||||
errorType = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.render = render;
|
module.exports.render = render;
|
||||||
module.exports.refreshrate = refreshrate;
|
module.exports.refreshrate = refreshrate;
|
||||||
|
|
Loading…
Reference in a new issue