bombshell-dev / clack

Effortlessly build beautiful command-line apps
https://clack.cc
5.53k stars 90 forks source link

feat(@clack/prompts): new method `spinner.message(msg: string)` #112

Closed luozhihua closed 1 year ago

luozhihua commented 1 year ago

Add method spinner.message(msg: string) that can update message of spinner in progress.

use case:

import * as p from "@clack/prompts";

p.intro("spinner start...");

const spin = p.spinner();
const total = 10000;
let progress = 0;
spin.start();

await new Promise((resolve) => {
  const timer = setInterval(() => {
    progress = Math.min(total, progress + 100);
    if (progress >= total) {
      clearInterval(timer);
      resolve(true);
    }
    spin.message(`Loading packages [${progress}/${total}]`);     // <===
  }, 100);
});

spin.stop(`Done`);

p.outro("spinner stop...");
changeset-bot[bot] commented 1 year ago

🦋 Changeset detected

Latest commit: 4adaad9ac5101f2cf0f917e48b235970ffca2da7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | -------------- | ----- | | @clack/prompts | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

jescalan commented 1 year ago

This is awesome, would love to see this land 😍