[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Christian Preston and committed by
GitHub
(Aug 9, 2023, 9:46 AM EDT) 1c61e1a6 9d9828b0

+37 -3
+5
.changeset/loud-bugs-move.md
··· 1 + --- 2 + '@clack/prompts': minor 3 + --- 4 + 5 + added a new method called `spinner.message(msg: string)`
+2 -1
examples/basic/package.json
··· 9 9 "picocolors": "^1.0.0" 10 10 }, 11 11 "scripts": { 12 - "start": "jiti ./index.ts" 12 + "start": "jiti ./index.ts", 13 + "spinner": "jiti ./spinner.ts" 13 14 }, 14 15 "devDependencies": { 15 16 "jiti": "^1.17.0"
+22
examples/basic/spinner.ts
··· 1 + import * as p from '@clack/prompts'; 2 + 3 + p.intro('spinner start...'); 4 + 5 + const spin = p.spinner(); 6 + const total = 10000; 7 + let progress = 0; 8 + spin.start(); 9 + 10 + new Promise((resolve) => { 11 + const timer = setInterval(() => { 12 + progress = Math.min(total, progress + 100); 13 + if (progress >= total) { 14 + clearInterval(timer); 15 + resolve(true); 16 + } 17 + spin.message(`Loading packages [${progress}/${total}]`); // <=== 18 + }, 100); 19 + }).then(() => { 20 + spin.stop(`Done`); 21 + p.outro('spinner stop...'); 22 + });
+8 -2
packages/prompts/src/index.ts
··· 640 640 export const spinner = () => { 641 641 let unblock: () => void; 642 642 let loop: NodeJS.Timer; 643 + let message = ''; 643 644 const delay = unicode ? 80 : 120; 644 645 return { 645 - start(message = '') { 646 + start(msg = '') { 647 + this.message(msg); 646 648 message = message.replace(/\.?\.?\.$/, ''); 647 649 unblock = block(); 648 650 process.stdout.write(`${color.gray(S_BAR)}\n${color.magenta('○')} ${message}\n`); ··· 660 662 dot = dot === frames.length ? 0 : dot + 0.125; 661 663 }, delay); 662 664 }, 663 - stop(message = '') { 665 + message(msg = '') { 666 + message = msg ?? message; 667 + }, 668 + stop(msg = '') { 669 + this.message(msg); 664 670 process.stdout.write(cursor.move(-999, -2)); 665 671 process.stdout.write(erase.down(2)); 666 672 clearInterval(loop);