Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bin/sonic.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@ function cleanup(exitCode = 0) {
]).then(() => process.exit(exitCode));
}

// A crash must still stop the music and give the terminal back.
function crash(err) {
try { ui.cleanup(); } catch {}
if (player.proc) {
try { player.proc.kill('SIGKILL'); } catch {}
}
if (process.stdin.isTTY && process.stdin.isRaw) process.stdin.setRawMode(false);
console.error(`\nsonic hit a bug and stopped: ${err?.message || err}`);
console.error('please report it: https://github.com/sethmills21/sonic/issues');
if (process.env.SONIC_DEBUG) console.error(err?.stack);
process.exit(1);
}

process.on('uncaughtException', crash);
process.on('unhandledRejection', crash);
process.on('SIGINT', () => cleanup(0));
process.on('SIGTERM', () => cleanup(0));
process.on('exit', () => {
Expand Down
3 changes: 2 additions & 1 deletion lib/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ export class UI {
const parts = [];
if (typeof options.volume === 'number') {
const steps = 10;
const filled = Math.round((options.volume / 100) * steps);
// mpv goes to 150; past 100 the meter stays full and the number keeps counting.
const filled = Math.max(0, Math.min(steps, Math.round((options.volume / 100) * steps)));
const meter = chalk.hex(theme.accent)('━'.repeat(filled)) + chalk.hex(theme.muted)('─'.repeat(steps - filled));
parts.push(`${chalk.hex(theme.muted)('vol')} ${meter} ${chalk.hex(theme.muted)(String(options.volume))}`);
}
Expand Down
Loading