diff --git a/radicle-term/src/lib.rs b/radicle-term/src/lib.rs index 272c0f2f..c1798597 100644 --- a/radicle-term/src/lib.rs +++ b/radicle-term/src/lib.rs @@ -22,7 +22,7 @@ pub use inquire::ui::Styled; pub use io::*; pub use is_terminal::is_terminal; pub use label::{label, Label}; -pub use spinner::{spinner, Spinner}; +pub use spinner::{spinner, spinner_to, Spinner}; pub use table::Table; pub use textarea::{textarea, TextArea}; pub use vstack::{VStack, VStackOptions}; diff --git a/radicle-term/src/spinner.rs b/radicle-term/src/spinner.rs index 25e31bbd..4b7148d7 100644 --- a/radicle-term/src/spinner.rs +++ b/radicle-term/src/spinner.rs @@ -102,16 +102,26 @@ impl Spinner { } } -/// Create a new spinner with the given message. +/// Create a new spinner with the given message. Sends animation output to `stderr` and success or +/// failure messages to `stdout`. pub fn spinner(message: impl ToString) -> Spinner { + spinner_to(message, io::stdout(), io::stderr()) +} + +/// Create a new spinner with the given message, and send output to the given writers. +pub fn spinner_to( + message: impl ToString, + completion: impl io::Write + Send + 'static, + animation: impl io::Write + Send + 'static, +) -> Spinner { let message = message.to_string(); let progress = Arc::new(Mutex::new(Progress::new(Paint::new(message)))); let handle = thread::spawn({ let progress = progress.clone(); move || { - let mut stdout = io::stdout(); - let mut stderr = termion::cursor::HideCursor::from(io::stderr()); + let mut stdout = completion; + let mut stderr = termion::cursor::HideCursor::from(animation); loop { let Ok(mut progress) = progress.lock() else {