Giter VIP home page Giter VIP logo

node-multispinner's Introduction

node-multispinner

Build Status Coverage Status

About | Installation | API | Examples | Attribution | License

About

node-multispinner is a Node.js module for managing multiple progress indicators (spinners) in CLI apps. This module is especially useful for apps that benefit from simultaneous async task execution (e.g. with Promise.all[]), as it enables live updating individual spinners, in any order, while other spinners continue spinning. Node.js 4.0 or newer is required.

demo-gif

Installation

Install and require as a standard Node module.

Install

  $ npm install --save multispinner

Require

  var Multispinner = require('multispinner')

API

Full documentation available here.

Examples

The examples discussed below can be found here. Run them in a terminal with node:

$ node <example>

Example: events.js

Creates four spinners from an array, then completes them in succession with staggered setTimeout functions. Responds to the success and err completion events.

Example: customAnimation.js

Creates a custom spinner animation with the frames option.

Example: randomInfiniteLoop.js

Creates three to seven spinners with random lorem text and completes them randomly in less than five seconds in an infinite loop. Stubs out the logUpdate.done() function to overwrite the previous output with every loop.

It's kind of mesmerising.

Example: cli-with-promises

A CLI application that reads URLs and parses HTML into text to display in a terminal. Uses meow for CLI support, html-to-text for parsing, and axios for Promise-based HTTP requests. Creates spinners for each URL, and uses Promise.all() to execute the GET requests in parallel.

There are certainly edge cases that this example doesn't account for; it is not meant to be a "real" application. Despite that, the code should be illustrative of how node-multispinner could potentially be used in a real application.

This example is unique in that it requires modules not used in node-multispinner. Before running it, cd into its directory and install the additional requirements from its package.json with npm install.

Attribution

Thanks to sindresorhus for his log-update module, which was a major inspiration for and is used extensively in this module. Log-update is MIT licensed.

License

MIT

node-multispinner's People

Contributors

codekirei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-multispinner's Issues

add Paused/or not started

some of my processes need to wait for one to finish. being able to add to the list would be nice, but it would also be nice to pause a task or show a task is not yet active

I might be doing this wrong, But Im getting the spinners overlapping each other and glitching

const processImage = async (path, filename,multispinner) => {
  multispinner.start(filename)
  let dir = join(__dirname, path);
  let files = readdirSync(dir);
  for (let i in files) {
    let file = files[i];
    let imageBuffer = await sharp(join(dir, file)).toBuffer();
    await sharp(imageBuffer)
      .metadata()
      .then(async ({ width, height }) => {
        // width > height
        if (width > height) {
          //console.log(width,height,file)
          let left = await sharp(imageBuffer)
            // divide into 2 parts 0 to width/2 and width/2 to width
            .extract({ width: width / 2, height, left: 0, top: 0 })
            //add these 2 images instead of the original
            .grayscale()
            .png({ quality: 5 })
            .toBuffer();
          await sharp(left)
            .trim()
            .toFile(`./extracted/${filename}/${file}`.replace(".png", "-2.png"))
            .then(async () => {
              //console.log("i run",file)
              let right = await sharp(imageBuffer)
                .extract({ width: width / 2, height, left: width / 2, top: 0 })
               .grayscale()
                .png({ quality: 5 })
                .toBuffer();
              await sharp(right)
                .trim()
                .toFile(
                  `./extracted/${filename}/${file}`.replace(".png", "-1.png")
                )
                .then(async () => {
                  //remove original
                  // console.log("removing",file)
                  files.splice(i, 1);
                  unlink(`./extracted/${filename}/${file}`, (err) => {
                    if (err) throw err;
                  });
                });
            });
        } else {
          sharp(imageBuffer)
            .grayscale()
            .trim()
            .png({ quality: 5 })
            .toFile(`./extracted/${filename}/${file}`);
        }
      })
  }
  multispinner.success(filename)
};


const unziper = async (filePath, filename, index) => {
  const multispinner = new Multispinner(
    [filename],{
      "preText":"Processing...",
      autoStart: false
    })
  createReadStream(filePath)
    .pipe(
      unzipper.Extract({
        path: `./extracted/${filename}`,
      })
    )
    .on("close", async () => {
      await processImage(`./extracted/${filename}`, filename,multispinner);
    })
    .on("error", (err) => {
    });
};


const readDirectory = async () => {
  await metaDataQuestions();
  let dir = join(__dirname, "./testDir");
  let files = readdirSync(dir);
  for (let i in files) {
    let file = files[i];
    unziper(join(dir, file), file, i);
  }
};

await readDirectory();

I basically want the spinners for the processing function, So if its processing 3 folders it should show 3 spinners.
Im sure im doing something wrong, I checked the example but I found it a bit confusing.

Add `stop` method

I'm using async for my async tasks and have 2 scenarios where a stop method would be helpful:

  • I already know when the tasks are done and don't want to listen to multiprocess for done (so I can have 1 function to handle next case)
  • Tasks are cancelled due to an fail fast error
    • I need to be able to log an error without worry of it being overwritten by a pending setTimeout

This should be plausible via a stop method which runs clearTimeout and loop()'s success case (i.e. this.update.done();)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.