Timer Command
The somethingzz set-timer command allows you to start a sleek countdown timer directly in your terminal, complete with a visual progress bar.
You can start a timer by passing the time in multiple formats. The CLI is smart enough to understand them all!
# Using standard secondssomethingzz set-timer 45
# Using hours, minutes, and seconds (separated by spaces)somethingzz set-timer 1 30 0 # 1 hour, 30 minutes
# Using minutes and secondssomethingzz set-timer 10 00 # 10 minutes
# Using shorthand suffixessomethingzz set-timer 1h30msomethingzz set-timer 45sOutput
Section titled “Output”When you start the timer, your terminal will beautifully render the remaining time and the custom progress bar:
Starting timer for 10 seconds... Time Remaining: 10s ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■As time counts down, the bar drains from left to right:
Time Remaining: 5s □□□□□□□□□□□□□□□□□□□■■■■■■■■■■■■■■■■■■■■■Advanced Customization: Dual-Color Progress Bars
Section titled “Advanced Customization: Dual-Color Progress Bars”Out of the box, cli-progress applies a single color to the entire bar. If you want the “drained” portion of the bar to be one color (like dim gray) and the “remaining” portion to be another color (like bright cyan), you can use the formatBar function.
Here is a complete, working snippet you can inject into your set-timer configuration to achieve this:
const progressBar = new cliProgress.SingleBar({ format: ` Time Remaining: {timeLeft}s {bar}`, barCompleteChar: '\u25A1', // Drained space (□) barIncompleteChar: '\u25A0', // Remaining time (■) hideCursor: true,
// This function builds the bar block-by-block formatBar: (progress, options) => { const barSize = options.barsize || 40;
// Calculate how many blocks should be "drained" vs "remaining" const completeSize = Math.round(progress * barSize); const incompleteSize = barSize - completeSize;
const completeStr = options.barCompleteChar.repeat(completeSize); const incompleteStr = options.barIncompleteChar.repeat(incompleteSize);
// Customize your colors! // Gray for the drained part, Cyan for the remaining part return chalk.gray.dim(completeStr) + chalk.cyanBright(incompleteStr); }});