[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: adapt spinner to ci environment

Bruno Rocha (Nov 26, 2024, 10:37 AM -0300) ac8e4425 2bbd33ee

+29 -8
+29 -8
packages/prompts/src/index.ts
··· 16 16 17 17 export { isCancel } from '@clack/core'; 18 18 19 + /** 20 + * Control variable used to prevent excessive rewrites in the CI environment 21 + * Issue: https://github.com/natemoo-re/clack/issues/168 22 + */ 23 + const isCI = process.env.GITHUB_ACTIONS === 'true'; 24 + 19 25 const unicode = isUnicodeSupported(); 20 26 const s = (c: string, fallback: string) => (unicode ? c : fallback); 21 27 const S_STEP_ACTIVE = s('◆', '*'); ··· 644 650 let loop: NodeJS.Timeout; 645 651 let isSpinnerActive: boolean = false; 646 652 let _message: string = ''; 653 + let _prevMessage: string | undefined = undefined; 647 654 648 655 const handleExit = (code: number) => { 649 656 const msg = code > 1 ? 'Something went wrong' : 'Canceled'; ··· 672 679 process.removeListener('exit', handleExit); 673 680 }; 674 681 682 + const clearPrevMessage = () => { 683 + if (!_prevMessage) return; 684 + if (isCI) process.stdout.write('\n'); 685 + const prevLines = _prevMessage.split('\n'); 686 + process.stdout.write(cursor.move(-999, prevLines.length - 1)); 687 + process.stdout.write(erase.down(prevLines.length)); 688 + }; 689 + 690 + const parseMessage = (msg: string): string => { 691 + return msg.replace(/\.+$/, ''); 692 + }; 693 + 675 694 const start = (msg: string = ''): void => { 676 695 isSpinnerActive = true; 677 696 unblock = block(); 678 - _message = msg.replace(/\.+$/, ''); 697 + _message = parseMessage(msg); 679 698 process.stdout.write(`${color.gray(S_BAR)}\n`); 680 699 let frameIndex = 0; 681 700 let dotsTimer = 0; 682 701 registerHooks(); 683 702 loop = setInterval(() => { 703 + if (isCI && _message === _prevMessage) { 704 + return; 705 + } 706 + clearPrevMessage(); 707 + _prevMessage = _message; 684 708 const frame = color.magenta(frames[frameIndex]); 685 - const loadingDots = '.'.repeat(Math.floor(dotsTimer)).slice(0, 3); 686 - process.stdout.write(cursor.move(-999, 0)); 687 - process.stdout.write(erase.down(1)); 709 + const loadingDots = isCI ? '...' : '.'.repeat(Math.floor(dotsTimer)).slice(0, 3); 688 710 process.stdout.write(`${frame} ${_message}${loadingDots}`); 689 711 frameIndex = frameIndex + 1 < frames.length ? frameIndex + 1 : 0; 690 712 dotsTimer = dotsTimer < frames.length ? dotsTimer + 0.125 : 0; ··· 692 714 }; 693 715 694 716 const stop = (msg: string = '', code: number = 0): void => { 695 - _message = msg ?? _message; 696 717 isSpinnerActive = false; 697 718 clearInterval(loop); 719 + clearPrevMessage(); 698 720 const step = 699 721 code === 0 700 722 ? color.green(S_STEP_SUBMIT) 701 723 : code === 1 702 724 ? color.red(S_STEP_CANCEL) 703 725 : color.red(S_STEP_ERROR); 704 - process.stdout.write(cursor.move(-999, 0)); 705 - process.stdout.write(erase.down(1)); 726 + _message = parseMessage(msg ?? _message); 706 727 process.stdout.write(`${step} ${_message}\n`); 707 728 clearHooks(); 708 729 unblock(); 709 730 }; 710 731 711 732 const message = (msg: string = ''): void => { 712 - _message = msg ?? _message; 733 + _message = parseMessage(msg ?? _message); 713 734 }; 714 735 715 736 return {