MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / spinner

Function spinner

cli/src/ui.rs:117–140  ·  view source on GitHub ↗

Start a spinner with `label`. Drop it (or call `done`) to stop.

(label: &str)

Source from the content-addressed store, hash-verified

115
116/// Start a spinner with `label`. Drop it (or call `done`) to stop.
117pub fn spinner(label: &str) -> Spinner {
118 let stop = Arc::new(AtomicBool::new(false));
119 // No animation when colors are off or stderr is redirected; just announce the step.
120 if plain() || !std::io::stderr().is_terminal() {
121 eprintln!(" {label}...");
122 return Spinner { stop, handle: None };
123 }
124 let stop_thread = stop.clone();
125 let label = label.to_string();
126 let handle = thread::spawn(move || {
127 let mut i = 0usize;
128 while !stop_thread.load(Ordering::Relaxed) {
129 let frame = SPIN_FRAMES[i % SPIN_FRAMES.len()];
130 eprint!("\r {} {}", frame, label.dimmed());
131 let _ = std::io::stderr().flush();
132 thread::sleep(Duration::from_millis(120));
133 i += 1;
134 }
135 // ANSI: carriage return + erase-to-end-of-line so the next print starts clean.
136 eprint!("\r\x1b[2K");
137 let _ = std::io::stderr().flush();
138 });
139 Spinner { stop, handle: Some(handle) }
140}
141
142impl Spinner {
143 /// Stop the spinner and print a `(successful) {msg}` line in green.

Callers 2

runFunction · 0.85
openMethod · 0.85

Calls 3

plainFunction · 0.85
loadMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected