Compare commits

...

8 Commits

Author SHA1 Message Date
jill 48db545c78 change the process title 2021-09-03 07:07:43 +03:00
jill de541f690d also reset color 2021-09-03 07:06:26 +03:00
jill a106771e5b show cursor after hiding it 2021-09-03 07:04:28 +03:00
jill 9fe6f36c1d rename error system to popup system 2021-09-03 07:00:03 +03:00
jill 0f0e828c52 improve error render system 2021-09-03 06:59:20 +03:00
jill f3d220f28c fancier error popups 2021-09-03 06:42:04 +03:00
jill b687772d31 add some render modes 2021-09-03 06:33:54 +03:00
jill 509f4c17dd smaller ver of the logo 2021-09-03 02:24:54 +03:00
4 changed files with 109 additions and 47 deletions

View File

@ -2,6 +2,7 @@ const render = require('./render');
const mpris = require('./mpris');
async function main() {
process.title = 'bouncy';
mpris.init(render.error, render.warning, render.info);
setInterval(() => {render.render(mpris.getArtist(), mpris.getAlbum(), mpris.getTitle(), mpris.getSongStart(), mpris.getSongEnd(), mpris.getSongPauseSpot(), mpris.getSongPaused())}, render.refreshrate);
}

BIN
logosmall.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -11,8 +11,12 @@ bouncy is a tiny script that hooks onto mpris to read your currently listening s
- a machine running dbus and mpris (typically linux)
- nodejs >=14
## how-to
## how-to install
`npm install` and `node index.js`
the music player string defaults to `org.mpris.MediaPlayer2.rhythmbox`, however you can use the `BOUNCY_MUSICPLAYER` environment value to change it to another music player name
the music player string defaults to `org.mpris.MediaPlayer2.rhythmbox`, however you can use the `BOUNCY_MUSICPLAYER` environment value to change it to another music player name
## usage
press space to switch between modes

147
render.js
View File

@ -1,5 +1,29 @@
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
});
process.on('exit', () => {
process.stdout.write('\x1B[?25h\033[0m'); // show cursor
})
const plas = [' ', '.', '*', '/', '0'];
const progressChars = ['▏', '▎', '▍', '▌', '▋', '▊', '▉'];
//const progressChars = ['0', '1', '2', '3', '4', '5', '6', '7'];
@ -30,9 +54,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 popups = [];
function transform(old, n) {
if (old.length < n.length) {
@ -59,7 +82,7 @@ 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;
@ -74,34 +97,80 @@ 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;
}
let i = 0;
for (let popup of popups) {
popup.timer -= dt;
if (popup.timer < 0) {
popups.splice(i, 1);
} else {
let symbol = ['⚠️', '⚠️', ''][popup.type];
let color = ['\033[41;37m', '\033[43;37m', '\033[44;37m'][popup.type];
let text = ` ${symbol} ${popup.text} `;
texts.push({
value: ' '.repeat(text.length) + text,
x: -text.length * 2 + Math.round((text.length + 3) * outCirc(Math.min(popup.timer, 1))),
y: 3 + i,
color: color
});
i++;
}
];
if (errorText && errorTimer > 0) {
let symbol = '⚠️';
if (errorType === 2) symbol = '';
let color = '\033[41;37m';
if (errorType === 1) color = '\033[43;37m';
if (errorType === 2) color = '\033[44;37m';
}
if (modePopup > 0) {
texts.push({
value: ` ${symbol} ${errorText} `,
x: 4,
y: Math.round(3 * outCirc(Math.min(errorTimer, 1))),
color: color
value: modes[mode],
x: Math.floor(w - ((modes[mode].length + 2) * outCirc(Math.min(modePopup, 1)))),
y: 0,
color: '\033[40;37m'
});
}
@ -154,7 +223,7 @@ function render(artist, album, title, songStart, songEnd, pauseSpot, paused) {
let pChar = progressChars[Math.floor(blockProgress * progressChars.length)];
let color = (x / (w - 1) > (Math.floor(progress * w) / w)) ? '\033[40;37m' : '\033[47;30m';
let pause = (paused && x === (w - 2)) ? '⏸' : null;
sum += color + (pause || (timerString[x - 1] === ' ' ? null : timerString[x - 1]) || (inProgressArea ? pChar : ' ')) + '\033[0m';
@ -179,21 +248,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) {popups.push({text: content, timer: errorDuration, type: 0});}
function warning(content) {popups.push({text: content, timer: errorDuration, type: 1});}
function info(content) {popups.push({text: content, timer: errorDuration, type: 2});}
module.exports.render = render;
module.exports.refreshrate = refreshrate;