use std::sync::OnceLock;

use indicatif::MultiProgress;

static MULTI: OnceLock<MultiProgress> = OnceLock::new();

/// Initialise the shared progress display.  Call once from the binary before
/// any index operation.  Subsequent calls are silently ignored.
pub fn init(multi: MultiProgress) {
    let _ = MULTI.set(multi);
}

/// Return the shared `MultiProgress`, creating a plain default one if the
/// binary never called [`init`].
pub fn get() -> &'static MultiProgress {
    MULTI.get_or_init(MultiProgress::new)
}

pub(crate) fn multi() -> &'static MultiProgress {
    get()
}
