Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
term: Use static template in spinner initialization
✓ CI success Fintan Halpenny committed 7 months ago
commit 66adbffd615bcd6a560213f01f3a35c424714c45
parent 8fc37e3316e3861c2a96009f480cc92ff9412f69
3 passed (3 total) View logs
1 file changed +9 -11
modified crates/radicle-term/src/spinner.rs
@@ -1,6 +1,6 @@
use std::io::IsTerminal;
use std::mem::ManuallyDrop;
-
use std::sync::{Arc, Mutex};
+
use std::sync::{Arc, LazyLock, Mutex};
use std::{fmt, io, thread, time};

use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
@@ -16,6 +16,8 @@ pub const DEFAULT_STYLE: [Paint<&'static str>; 4] = [
    Paint::magenta("◤"),
    Paint::blue("◥"),
];
+
static TEMPLATE: LazyLock<ProgressStyle> =
+
    LazyLock::new(|| ProgressStyle::with_template("{spinner:.blue} {msg}").unwrap());

impl From<PaintTarget> for ProgressDrawTarget {
    fn from(value: PaintTarget) -> Self {
@@ -154,16 +156,12 @@ pub fn spinner_to(

            spinner.set_draw_target(progress_target.into());
            spinner.set_message(message.to_string());
-
            spinner.set_style(
-
                ProgressStyle::with_template("{spinner:.blue} {msg}")
-
                    .unwrap()
-
                    .tick_strings(&[
-
                        DEFAULT_STYLE[0].to_string().as_str(),
-
                        DEFAULT_STYLE[1].to_string().as_str(),
-
                        DEFAULT_STYLE[2].to_string().as_str(),
-
                        DEFAULT_STYLE[3].to_string().as_str(),
-
                    ]),
-
            );
+
            spinner.set_style(TEMPLATE.clone().tick_strings(&[
+
                DEFAULT_STYLE[0].to_string().as_str(),
+
                DEFAULT_STYLE[1].to_string().as_str(),
+
                DEFAULT_STYLE[2].to_string().as_str(),
+
                DEFAULT_STYLE[3].to_string().as_str(),
+
            ]));

            move || {
                loop {