Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] WaveProgressBar #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xoesae
Copy link

@xoesae xoesae commented Feb 21, 2024

Several large CLI libraries include an easy way to create progress bars, with this in mind I brought a new class to Wave, the WaveProgressBar.

To instantiate a new WaveProgressBar, we have a 3 params:

  • max: the number max of progress, default is 100;
  • step: amount that will advance with each step;
  • char: the char will be rendered in progress bar;

The WaveProgressBar has 3 main methods:

  • init: display the progress bar in the stdout;
  • advance: increment the progress bar based on the step defined in the constructor;
  • finish: set the progress to max and render the final progress;

Example of usage:

import { WaveCommand, WaveProgressBar } from "wave-shell";

function wait(ms: number) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

export default {
    description: 'Running a progress bar',
    async run() {
        let progressBar = new WaveProgressBar(100, 5, '#');

        progressBar.init();

        for (let i = 0; i < 10; i++) {
            progressBar.advance();
            await wait(100);
        }

        progressBar.finish();
    },
} as WaveCommand

I am available for any necessary changes 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant