Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
term: Add configurable output stream for `Spinner`
Alexis Sellier committed 2 years ago
commit cfc386ed0e47c6d8b35455ab5a64674d2d4c7824
parent 45a457872416281f60b1e115b08c4220cd4ec14b
2 files changed +14 -4
modified 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};
modified 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 {