improve error render system

This commit is contained in:
jill 2021-09-03 06:59:20 +03:00
parent f3d220f28c
commit 0f0e828c52
1 changed files with 22 additions and 32 deletions

View File

@ -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'; texts.push({
if (errorType === 1) color = '\033[43;37m'; value: ' '.repeat(text.length) + text,
if (errorType === 2) color = '\033[44;37m'; x: -text.length * 2 + Math.round((text.length + 3) * outCirc(Math.min(err.timer, 1))),
y: 3 + i,
color: color
});
let text = ` ${symbol} ${errorText} `; i++;
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
});
} }
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;