From 0f0e828c524e8c06d0d7903408cf64e9d11419f0 Mon Sep 17 00:00:00 2001 From: jill Date: Fri, 3 Sep 2021 06:59:20 +0300 Subject: [PATCH] improve error render system --- render.js | 54 ++++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/render.js b/render.js index 0fcd72d..b7c7348 100644 --- a/render.js +++ b/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;