File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -8,17 +8,23 @@ use tokio::time::interval;
88pub struct Spinner {
99 is_active : Arc < AtomicBool > ,
1010 message : String ,
11+ disabled : bool ,
1112}
1213
1314impl Spinner {
1415 pub fn new ( message : & str ) -> Self {
16+ let disabled = !atty:: is ( atty:: Stream :: Stdout ) ;
1517 Self {
1618 is_active : Arc :: new ( AtomicBool :: new ( false ) ) ,
1719 message : message. to_string ( ) ,
20+ disabled,
1821 }
1922 }
2023
2124 pub async fn start ( & self ) {
25+ if self . disabled {
26+ return ;
27+ }
2228 self . is_active . store ( true , Ordering :: Relaxed ) ;
2329 let is_active = Arc :: clone ( & self . is_active ) ;
2430 let message = self . message . clone ( ) ;
@@ -50,13 +56,20 @@ impl Spinner {
5056 }
5157
5258 pub fn stop ( & self ) {
59+ if self . disabled {
60+ return ;
61+ }
5362 self . is_active . store ( false , Ordering :: Relaxed ) ;
5463 // Clear the line
5564 print ! ( "\r \x1b [K" ) ;
5665 io:: stdout ( ) . flush ( ) . unwrap_or ( ( ) ) ;
5766 }
5867
5968 pub fn stop_and_replace ( & self , replacement : & str ) {
69+ if self . disabled {
70+ println ! ( "{replacement}" ) ;
71+ return ;
72+ }
6073 self . is_active . store ( false , Ordering :: Relaxed ) ;
6174 // Clear the line and print replacement
6275 print ! ( "\r \x1b [K{replacement}" ) ;
You can’t perform that action at this time.
0 commit comments