add some render modes
This commit is contained in:
parent
509f4c17dd
commit
b687772d31
1 changed files with 78 additions and 15 deletions
91
render.js
91
render.js
|
@ -1,5 +1,26 @@
|
|||
const readline = require('readline');
|
||||
|
||||
readline.emitKeypressEvents(process.stdin);
|
||||
|
||||
if (process.stdin.isTTY) {
|
||||
process.stdin.setRawMode(true);
|
||||
}
|
||||
|
||||
const modes = ['classic', 'bottom', 'top'];
|
||||
let mode = 0;
|
||||
|
||||
let modePopup = 0;
|
||||
const modePopupDuration = 2;
|
||||
|
||||
process.stdin.on('keypress', (str, key) => {
|
||||
if (key.name === 'space') {
|
||||
mode++;
|
||||
mode = mode % modes.length;
|
||||
modePopup = modePopupDuration;
|
||||
}
|
||||
if (key.sequence === '\x03' || key.sequence === '\x04') process.exit(0); // ctrl+c, ctrl+d
|
||||
});
|
||||
|
||||
const plas = [' ', '.', '*', '/', '0'];
|
||||
const progressChars = ['▏', '▎', '▍', '▌', '▋', '▊', '▉'];
|
||||
//const progressChars = ['0', '1', '2', '3', '4', '5', '6', '7'];
|
||||
|
@ -60,6 +81,7 @@ 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;
|
||||
|
||||
|
@ -74,20 +96,52 @@ function render(artist, album, title, songStart, songEnd, pauseSpot, paused) {
|
|||
}
|
||||
|
||||
// leaving the coordinates as non-integer values is very undefined behavior
|
||||
let texts = [
|
||||
{
|
||||
value: ' ' + displaytitle + ' ',
|
||||
x: Math.round(w / 2 - displaytitle.length / 2 + Math.sin(time) * 5),
|
||||
y: Math.floor(h / 2) - 1,
|
||||
color: '\033[7;1m'
|
||||
},
|
||||
{
|
||||
value: ' ' + displayalbum + ' ',
|
||||
x: Math.round(w / 2 - displayalbum.length / 2 - Math.sin(time) * 5),
|
||||
y: Math.floor(h / 2) + 1,
|
||||
color: '\033[7m'
|
||||
}
|
||||
];
|
||||
let texts = [];
|
||||
|
||||
switch (mode) {
|
||||
case 0:
|
||||
texts.push({
|
||||
value: ' ' + displaytitle + ' ',
|
||||
x: Math.round(w / 2 - displaytitle.length / 2 + Math.sin(time) * 5),
|
||||
y: Math.floor(h / 2) - 1,
|
||||
color: '\033[7;1m'
|
||||
});
|
||||
texts.push({
|
||||
value: ' ' + displayalbum + ' ',
|
||||
x: Math.round(w / 2 - displayalbum.length / 2 - Math.sin(time) * 5),
|
||||
y: Math.floor(h / 2) + 1,
|
||||
color: '\033[7m'
|
||||
});
|
||||
break;
|
||||
case 1:
|
||||
texts.push({
|
||||
value: ' ' + displaytitle + ' '.repeat(w),
|
||||
x: 0,
|
||||
y: h - 3,
|
||||
color: '\033[7;1m'
|
||||
});
|
||||
texts.push({
|
||||
value: ' ' + displayalbum + ' '.repeat(w),
|
||||
x: 0,
|
||||
y: h - 2,
|
||||
color: '\033[7m'
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
texts.push({
|
||||
value: ' ' + displaytitle + ' '.repeat(w),
|
||||
x: 0,
|
||||
y: 0,
|
||||
color: '\033[7;1m'
|
||||
});
|
||||
texts.push({
|
||||
value: ' ' + displayalbum + ' '.repeat(w),
|
||||
x: 0,
|
||||
y: 1,
|
||||
color: '\033[7m'
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
if (errorText && errorTimer > 0) {
|
||||
let symbol = '⚠️';
|
||||
|
@ -105,6 +159,15 @@ function render(artist, album, title, songStart, songEnd, pauseSpot, paused) {
|
|||
});
|
||||
}
|
||||
|
||||
if (modePopup > 0) {
|
||||
texts.push({
|
||||
value: modes[mode],
|
||||
x: Math.floor(w - ((modes[mode].length + 2) * outCirc(Math.min(modePopup, 1)))),
|
||||
y: 0,
|
||||
color: '\033[40;37m'
|
||||
});
|
||||
}
|
||||
|
||||
let reset = '\033[0m';
|
||||
|
||||
let now = paused ? pauseSpot : Date.now();
|
||||
|
|
Loading…
Reference in a new issue