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