Skip to content

How to show progress bar in one line when using for loop ? #159

Open
@amrsa1

Description

@amrsa1

I have a function where im looping over an array, to do some process this lead to see progress bar appearing in many line rather than show the progress on the same bar.

Could you provide an example how to do so when im using for loop

const bar = new cliProgress.SingleBar({
      format: 'Processing |' + chalk.cyan('{bar}') + '| {percentage}% || {value}/{total} Pages || Current File: {filename}',
      barCompleteChar: '\u2588',
      barIncompleteChar: '\u2591',
      hideCursor: true
    }, cliProgress.Presets.shades_classic);

    bar.start(pages.length, 0, {
      filename: 'Starting...'
    });

    for (const page of pages) {
      const pageName = page.FileLeafRef;

      // Update the progress bar with the current file name and progress
      bar.increment(1, {
        filename: pageName
      });

      const pageContent = page.CanvasContent1;

      if (pageContent) {
        const cleanedContent = cleanHtml(decodedContent);
        const outputPdfPath = `./${path.parse(pageName).name}.pdf`;
        await convertHtmlToPdf(cleanedContent, outputPdfPath);
      } else {
        console.log(chalk.red(`Failed to retrieve content for page: ${pageName}\n`));
      }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions