11import { block , getColumns , settings } from '@clack/core' ;
22import { wrapAnsi } from 'fast-wrap-ansi' ;
3- import colors from 'picocolors' ;
4- import type { Colors } from 'picocolors/types.d.ts' ;
3+ import color from 'picocolors' ;
54import { cursor , erase } from 'sisteransi' ;
65import {
76 type CommonOptions ,
@@ -20,7 +19,7 @@ export interface SpinnerOptions extends CommonOptions {
2019 errorMessage ?: string ;
2120 frames ?: string [ ] ;
2221 delay ?: number ;
23- color ?: keyof Omit < Colors , 'isColorSupported' > ;
22+ style ?: ( frame : string ) => string ;
2423}
2524
2625export interface SpinnerResult {
@@ -30,6 +29,8 @@ export interface SpinnerResult {
3029 readonly isCancelled : boolean ;
3130}
3231
32+ const defaultStyleFn : SpinnerOptions [ 'style' ] = color . magenta ;
33+
3334export const spinner = ( {
3435 indicator = 'dots' ,
3536 onCancel,
@@ -39,7 +40,7 @@ export const spinner = ({
3940 frames = unicode ? [ '◒' , '◐' , '◓' , '◑' ] : [ '•' , 'o' , 'O' , '0' ] ,
4041 delay = unicode ? 80 : 120 ,
4142 signal,
42- color = 'magenta' ,
43+ style ,
4344} : SpinnerOptions = { } ) : SpinnerResult => {
4445 const isCI = isCIFn ( ) ;
4546
@@ -51,6 +52,7 @@ export const spinner = ({
5152 let _prevMessage : string | undefined ;
5253 let _origin : number = performance . now ( ) ;
5354 const columns = getColumns ( output ) ;
55+ const styleFn = style ?? defaultStyleFn ;
5456
5557 const handleExit = ( code : number ) => {
5658 const msg =
@@ -127,7 +129,7 @@ export const spinner = ({
127129 unblock = block ( { output } ) ;
128130 _message = removeTrailingDots ( msg ) ;
129131 _origin = performance . now ( ) ;
130- output . write ( `${ colors . gray ( S_BAR ) } \n` ) ;
132+ output . write ( `${ color . gray ( S_BAR ) } \n` ) ;
131133 let frameIndex = 0 ;
132134 let indicatorTimer = 0 ;
133135 registerHooks ( ) ;
@@ -137,7 +139,7 @@ export const spinner = ({
137139 }
138140 clearPrevMessage ( ) ;
139141 _prevMessage = _message ;
140- const frame = colors [ color ] ( frames [ frameIndex ] ) ;
142+ const frame = styleFn ( frames [ frameIndex ] ) ;
141143 let outputMessage : string ;
142144
143145 if ( isCI ) {
@@ -168,10 +170,10 @@ export const spinner = ({
168170 clearPrevMessage ( ) ;
169171 const step =
170172 code === 0
171- ? colors . green ( S_STEP_SUBMIT )
173+ ? color . green ( S_STEP_SUBMIT )
172174 : code === 1
173- ? colors . red ( S_STEP_CANCEL )
174- : colors . red ( S_STEP_ERROR ) ;
175+ ? color . red ( S_STEP_CANCEL )
176+ : color . red ( S_STEP_ERROR ) ;
175177 _message = msg ?? _message ;
176178 if ( indicator === 'timer' ) {
177179 output . write ( `${ step } ${ _message } ${ formatTimer ( _origin ) } \n` ) ;
0 commit comments