Compare commits
8 commits
8bcce51e56
...
48db545c78
Author | SHA1 | Date | |
---|---|---|---|
48db545c78 | |||
de541f690d | |||
a106771e5b | |||
9fe6f36c1d | |||
0f0e828c52 | |||
f3d220f28c | |||
b687772d31 | |||
509f4c17dd |
4 changed files with 109 additions and 47 deletions
1
index.js
1
index.js
|
@ -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
BIN
logosmall.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
|
@ -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
147
render.js
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue