Compare commits

..

8 commits

Author SHA1 Message Date
48db545c78 change the process title 2021-09-03 07:07:43 +03:00
de541f690d also reset color 2021-09-03 07:06:26 +03:00
a106771e5b show cursor after hiding it 2021-09-03 07:04:28 +03:00
9fe6f36c1d rename error system to popup system 2021-09-03 07:00:03 +03:00
0f0e828c52 improve error render system 2021-09-03 06:59:20 +03:00
f3d220f28c fancier error popups 2021-09-03 06:42:04 +03:00
b687772d31 add some render modes 2021-09-03 06:33:54 +03:00
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'); const mpris = require('./mpris');
async function main() { async function main() {
process.title = 'bouncy';
mpris.init(render.error, render.warning, render.info); 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); 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) - a machine running dbus and mpris (typically linux)
- nodejs >=14 - nodejs >=14
## how-to ## how-to install
`npm install` and `node index.js` `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

125
render.js
View file

@ -1,5 +1,29 @@
const readline = require('readline'); 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 plas = [' ', '.', '*', '/', '0'];
const progressChars = ['▏', '▎', '▍', '▌', '▋', '▊', '▉']; const progressChars = ['▏', '▎', '▍', '▌', '▋', '▊', '▉'];
//const progressChars = ['0', '1', '2', '3', '4', '5', '6', '7']; //const progressChars = ['0', '1', '2', '3', '4', '5', '6', '7'];
@ -30,9 +54,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 popups = [];
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) {
@ -59,7 +82,7 @@ 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;
let w = process.stdout.columns; let w = process.stdout.columns;
let h = process.stdout.rows; let h = process.stdout.rows;
@ -74,35 +97,81 @@ function render(artist, album, title, songStart, songEnd, pauseSpot, paused) {
} }
// leaving the coordinates as non-integer values is very undefined behavior // leaving the coordinates as non-integer values is very undefined behavior
let texts = [ let texts = [];
{
switch (mode) {
case 0:
texts.push({
value: ' ' + displaytitle + ' ', value: ' ' + displaytitle + ' ',
x: Math.round(w / 2 - displaytitle.length / 2 + Math.sin(time) * 5), x: Math.round(w / 2 - displaytitle.length / 2 + Math.sin(time) * 5),
y: Math.floor(h / 2) - 1, y: Math.floor(h / 2) - 1,
color: '\033[7;1m' color: '\033[7;1m'
}, });
{ texts.push({
value: ' ' + displayalbum + ' ', value: ' ' + displayalbum + ' ',
x: Math.round(w / 2 - displayalbum.length / 2 - Math.sin(time) * 5), x: Math.round(w / 2 - displayalbum.length / 2 - Math.sin(time) * 5),
y: Math.floor(h / 2) + 1, y: Math.floor(h / 2) + 1,
color: '\033[7m' 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 i = 0;
let symbol = '⚠️'; for (let popup of popups) {
if (errorType === 2) symbol = ''; popup.timer -= dt;
if (popup.timer < 0) {
let color = '\033[41;37m'; popups.splice(i, 1);
if (errorType === 1) color = '\033[43;37m'; } else {
if (errorType === 2) color = '\033[44;37m'; let symbol = ['⚠️', '⚠️', ''][popup.type];
let color = ['\033[41;37m', '\033[43;37m', '\033[44;37m'][popup.type];
let text = ` ${symbol} ${popup.text} `;
texts.push({ texts.push({
value: ` ${symbol} ${errorText} `, value: ' '.repeat(text.length) + text,
x: 4, x: -text.length * 2 + Math.round((text.length + 3) * outCirc(Math.min(popup.timer, 1))),
y: Math.round(3 * outCirc(Math.min(errorTimer, 1))), y: 3 + i,
color: color color: color
}); });
i++;
}
}
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 reset = '\033[0m';
@ -179,21 +248,9 @@ function render(artist, album, title, songStart, songEnd, pauseSpot, paused) {
} }
} }
function error(content) { function error(content) {popups.push({text: content, timer: errorDuration, type: 0});}
errorText = content; function warning(content) {popups.push({text: content, timer: errorDuration, type: 1});}
errorTimer = errorDuration; function info(content) {popups.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;