Skip to content

Commit 11dd146

Browse files
committed
feat(cli): disable spinner when output is piped
1 parent 346624b commit 11dd146

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

crates/rullm-cli/src/spinner.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ use tokio::time::interval;
88
pub struct Spinner {
99
is_active: Arc<AtomicBool>,
1010
message: String,
11+
disabled: bool,
1112
}
1213

1314
impl 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}");

0 commit comments

Comments
 (0)