devpulse
Version:
A powerful terminal-based focus timer with enhanced notifications
104 lines (86 loc) ⢠3.26 kB
text/typescript
import chalk from "chalk";
import ora from "ora";
console.log(chalk.blue("š§ DevPulse - Enhanced Focus Timer"));
// CLI Args
const args = process.argv.slice(2);
const command = args[0];
const minutes = parseFloat(args[1] ?? "") || 25;
// Enhanced notifications function
function triggerNotifications(type: string, mins: number) {
// Terminal alerts
console.log(chalk.bgRed.white.bold(" šØ TIMER COMPLETE! šØ "));
console.log(chalk.bgYellow.black.bold(" š GREAT JOB! š "));
console.log(chalk.bgGreen.white.bold(" ⨠TIME FOR A BREAK! ⨠"));
// Terminal bells
for (let i = 0; i < 5; i++) {
setTimeout(() => process.stdout.write("\x07"), i * 300);
}
// Try desktop notification
import("node-notifier").then(notifier => {
notifier.default.notify({
title: `š ${type.toUpperCase()} SESSION COMPLETE!`,
message: `š Amazing! You completed ${mins} minutes of ${type}!`,
timeout: 10,
sound: true
});
}).catch(() => console.log(chalk.yellow("Desktop notifications unavailable")));
// Try to open browser alarm
import("child_process").then(cp => {
cp.exec("xdg-open alerts/alarm.html", (error) => {
if (error) console.log(chalk.yellow("Browser alarm unavailable"));
});
}).catch(() => {});
// Final celebration
setTimeout(() => {
console.log(chalk.bgMagenta.white.bold("š š š SESSION COMPLETE! š š š"));
}, 1000);
}
// Timer function
function startTimer(mins: number, type: "focus" | "break") {
const emoji = type === "focus" ? "ā³" : "šµ";
console.log(chalk.green(`šÆ Starting ${mins}-minute ${type} session...`));
const spinner = ora(`${emoji} ${type.toUpperCase()} for ${mins} min`).start();
let seconds = Math.floor(mins * 60);
const interval = setInterval(() => {
seconds--;
const m = Math.floor(seconds / 60);
const s = seconds % 60;
spinner.text = `${emoji} ${chalk.green(m)}:${chalk.yellow(s < 10 ? '0' + s : s)}`;
if (seconds <= 0) {
clearInterval(interval);
spinner.succeed(`ā
${type} session complete! (${mins} min)`);
triggerNotifications(type, mins);
// Exit after notifications
setTimeout(() => process.exit(0), 3000);
}
}, 1000);
}
// Handle commands
if (command === "focus") {
startTimer(minutes, "focus");
} else if (command === "break") {
startTimer(minutes, "break");
} else if (command === "log") {
console.log("š
Session logging coming soon!");
} else if (command === "report") {
console.log("š Reports coming soon!");
} else {
console.log(`
š§ DevPulse ā Enhanced Terminal Focus Tracker
Usage:
bun run src/index.ts focus [minutes] Start a focus session
bun run src/index.ts break [minutes] Start a break session
bun run src/index.ts log Show today's sessions
bun run src/index.ts report Weekly summary
Examples:
bun run src/index.ts focus 1 # 1-minute test session
bun run src/index.ts focus 25 # 25-minute Pomodoro
bun run src/index.ts break 5 # 5-minute break
⨠Features:
š Multiple sound alerts
šØ Terminal visual notifications
š± Desktop notifications
š Browser alarm popup
`);
}