@@ -28,6 +28,7 @@ export interface SpinnerResult {
2828 cancel ( msg ?: string ) : void ;
2929 error ( msg ?: string ) : void ;
3030 message ( msg ?: string ) : void ;
31+ clear ( ) : void ;
3132 readonly isCancelled : boolean ;
3233}
3334
@@ -165,7 +166,7 @@ export const spinner = ({
165166 } , delay ) ;
166167 } ;
167168
168- const _stop = ( msg = '' , code = 0 ) : void => {
169+ const _stop = ( msg = '' , code = 0 , silent : boolean = false ) : void => {
169170 if ( ! isSpinnerActive ) return ;
170171 isSpinnerActive = false ;
171172 clearInterval ( loop ) ;
@@ -177,10 +178,12 @@ export const spinner = ({
177178 ? color . red ( S_STEP_CANCEL )
178179 : color . red ( S_STEP_ERROR ) ;
179180 _message = msg ?? _message ;
180- if ( indicator === 'timer' ) {
181- output . write ( `${ step } ${ _message } ${ formatTimer ( _origin ) } \n` ) ;
182- } else {
183- output . write ( `${ step } ${ _message } \n` ) ;
181+ if ( ! silent ) {
182+ if ( indicator === 'timer' ) {
183+ output . write ( `${ step } ${ _message } ${ formatTimer ( _origin ) } \n` ) ;
184+ } else {
185+ output . write ( `${ step } ${ _message } \n` ) ;
186+ }
184187 }
185188 clearHooks ( ) ;
186189 unblock ( ) ;
@@ -189,6 +192,10 @@ export const spinner = ({
189192 const stop = ( msg = '' ) : void => _stop ( msg , 0 ) ;
190193 const cancel = ( msg = '' ) : void => _stop ( msg , 1 ) ;
191194 const error = ( msg = '' ) : void => _stop ( msg , 2 ) ;
195+ // TODO (43081j): this will leave the initial S_BAR since we purposely
196+ // don't erase that in `clearPrevMessage`. In future, we may want to treat
197+ // `clear` as a special case and remove the bar too.
198+ const clear = ( ) : void => _stop ( '' , 0 , true ) ;
192199
193200 const message = ( msg = '' ) : void => {
194201 _message = removeTrailingDots ( msg ?? _message ) ;
@@ -200,6 +207,7 @@ export const spinner = ({
200207 message,
201208 cancel,
202209 error,
210+ clear,
203211 get isCancelled ( ) {
204212 return isCancelled ;
205213 } ,
0 commit comments