11import { block , getColumns , settings } from '@clack/core' ;
22import { wrapAnsi } from 'fast-wrap-ansi' ;
3- import color from 'picocolors' ;
3+ import colors from 'picocolors' ;
4+ import type { Colors } from 'picocolors/types' ;
45import { cursor , erase } from 'sisteransi' ;
56import {
67 type CommonOptions ,
@@ -19,6 +20,7 @@ export interface SpinnerOptions extends CommonOptions {
1920 errorMessage ?: string ;
2021 frames ?: string [ ] ;
2122 delay ?: number ;
23+ color ?: keyof Omit < Colors , 'isColorSupported' > ;
2224}
2325
2426export interface SpinnerResult {
@@ -37,6 +39,7 @@ export const spinner = ({
3739 frames = unicode ? [ '◒' , '◐' , '◓' , '◑' ] : [ '•' , 'o' , 'O' , '0' ] ,
3840 delay = unicode ? 80 : 120 ,
3941 signal,
42+ color = 'magenta' ,
4043} : SpinnerOptions = { } ) : SpinnerResult => {
4144 const isCI = isCIFn ( ) ;
4245
@@ -124,7 +127,7 @@ export const spinner = ({
124127 unblock = block ( { output } ) ;
125128 _message = removeTrailingDots ( msg ) ;
126129 _origin = performance . now ( ) ;
127- output . write ( `${ color . gray ( S_BAR ) } \n` ) ;
130+ output . write ( `${ colors . gray ( S_BAR ) } \n` ) ;
128131 let frameIndex = 0 ;
129132 let indicatorTimer = 0 ;
130133 registerHooks ( ) ;
@@ -134,7 +137,7 @@ export const spinner = ({
134137 }
135138 clearPrevMessage ( ) ;
136139 _prevMessage = _message ;
137- const frame = color . magenta ( frames [ frameIndex ] ) ;
140+ const frame = colors [ color ] ( frames [ frameIndex ] ) ;
138141 let outputMessage : string ;
139142
140143 if ( isCI ) {
@@ -165,10 +168,10 @@ export const spinner = ({
165168 clearPrevMessage ( ) ;
166169 const step =
167170 code === 0
168- ? color . green ( S_STEP_SUBMIT )
171+ ? colors . green ( S_STEP_SUBMIT )
169172 : code === 1
170- ? color . red ( S_STEP_CANCEL )
171- : color . red ( S_STEP_ERROR ) ;
173+ ? colors . red ( S_STEP_CANCEL )
174+ : colors . red ( S_STEP_ERROR ) ;
172175 _message = msg ?? _message ;
173176 if ( indicator === 'timer' ) {
174177 output . write ( `${ step } ${ _message } ${ formatTimer ( _origin ) } \n` ) ;
0 commit comments