ProgressEvents
The ProgressEvents interface defines the event map for a progress bar in ts-better-console. It describes all the events that can be emitted during the lifecycle of a progress bar, allowing you to respond to updates, completion, cancellation, and errors.
Type Definition
The ProgressEvents interface includes the following events:
update: Emitted when the progress bar is updated. Provides thecurrentvalue (number) and thepercentage(number) of completion.complete: Emitted when the progress bar reaches 100%. Provides thetotalvalue (number).cancel: Emitted when the progress bar is cancelled. No arguments are passed.error: Emitted when an error occurs. Accepts any number of arguments.
interface ProgressEvents {
update: [current: number, percentage: number];
complete: [total: number];
cancel: [];
error: [...args: any[]];
}
Usage
You can listen to ProgressEvents to track progress bar lifecycle:
import { Progress } from "ts-better-console";
const bar = new Progress("Downloading", 100);
bar.on("update", (current, percentage) => {console.log(`Progress: ${percentage}%`);});
bar.on("complete", (total) => {console.log(`Done! Total: ${total}`);});
bar.on("cancel", () => {console.log("Progress cancelled");});
bar.on("error", (...args) => {console.error("Error:", ...args);});
Want to support this project?
If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.
Want to contribute to this project?
Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!