loaders 0.0.0

A fully-featured, customisable progress bar and loading indicator library for Rust CLI and terminal applications
Documentation
//! Built-in spinner frame presets.

/// Braille dots: `⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏`.
pub const DOTS: [&str; 10] = ["", "", "", "", "", "", "", "", "", ""];
/// Heavy braille dots: `⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷`.
pub const DOTS2: [&str; 8] = ["", "", "", "", "", "", "", ""];
/// Smooth braille dots: `⠋ ⠙ ⠚ ⠞ ⠖ ⠦ ⠴ ⠲ ⠳ ⠓`.
pub const DOTS3: [&str; 10] = ["", "", "", "", "", "", "", "", "", ""];
/// ASCII line spinner: `- \ | /`.
pub const LINE: [&str; 4] = ["-", "\\", "|", "/"];
/// Box pipe spinner: `┤ ┘ ┴ └ ├ ┌ ┬ ┐`.
pub const PIPE: [&str; 8] = ["", "", "", "", "", "", "", ""];
/// Star pulse: `✶ ✸ ✹ ✺ ✹ ✷`.
pub const STAR: [&str; 6] = ["", "", "", "", "", ""];
/// Minimal bounce: `⠁ ⠂ ⠄ ⠂`.
pub const BOUNCE: [&str; 4] = ["", "", "", ""];
/// Direction arrows: `← ↖ ↑ ↗ → ↘ ↓ ↙`.
pub const ARROWS: [&str; 8] = ["", "", "", "", "", "", "", ""];
/// Clock faces: `🕛 🕐 🕑 🕒 🕓 🕔 🕕 🕖 🕗 🕘 🕙 🕚`.
pub const CLOCK: [&str; 12] = [
    "🕛", "🕐", "🕑", "🕒", "🕓", "🕔", "🕕", "🕖", "🕗", "🕘", "🕙", "🕚",
];
/// Earth rotation: `🌍 🌎 🌏`.
pub const EARTH: [&str; 3] = ["🌍", "🌎", "🌏"];
/// Moon phases: `🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘`.
pub const MOON: [&str; 8] = ["🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘"];
/// Runner motion: `🚶 🏃`.
pub const RUNNER: [&str; 2] = ["🚶", "🏃"];
/// Pong paddle motion.
pub const PONG: [&str; 8] = [
    "▐⠂       ▌",
    "▐ ⠂      ▌",
    "▐  ⠂     ▌",
    "▐   ⠂    ▌",
    "▐    ⠂   ▌",
    "▐     ⠂  ▌",
    "▐      ⠂ ▌",
    "▐       ⠂▌",
];
/// Swimming shark frames.
pub const SHARK: [&str; 6] = [
    "▐|\\____________▌",
    "▐_|\\___________▌",
    "▐__|\\__________▌",
    "▐___|\\_________▌",
    "▐____|\\________▌",
    "▐_____|\\_______▌",
];
/// Weather cycle: `☀️ ⛅ 🌤 🌧 ⛈ 🌩 🌨`.
pub const WEATHER: [&str; 7] = ["☀️", "", "🌤", "🌧", "", "🌩", "🌨"];
/// Christmas trees: `🌲 🎄`.
pub const CHRISTMAS: [&str; 2] = ["🌲", "🎄"];
/// Toggle squares: `■ □`.
pub const TOGGLE: [&str; 2] = ["", ""];
/// Rotating square corners: `◰ ◳ ◲ ◱`.
pub const SQUARE_CORNERS: [&str; 4] = ["", "", "", ""];
/// Binary pulse: `0 1 10 11`.
pub const BINARY: [&str; 4] = ["0", "1", "10", "11"];
/// Growing meter blocks: `▱▱▱ ▰▱▱ ▰▰▱ ▰▰▰`.
pub const METER: [&str; 4] = ["▱▱▱", "▰▱▱", "▰▰▱", "▰▰▰"];
/// Rotating quadrants: `◐ ◓ ◑ ◒`.
pub const QUADRANTS: [&str; 4] = ["", "", "", ""];
/// Triangle rotation: `◢ ◣ ◤ ◥`.
pub const TRIANGLES: [&str; 4] = ["", "", "", ""];
/// Expanding circle: `○ ◔ ◐ ◕ ●`.
pub const CIRCLE: [&str; 5] = ["", "", "", "", ""];
/// Horizontal block bounce.
pub const BOX_BOUNCE: [&str; 5] = ["", "", "", "", ""];
/// Text pulse: `. .. ... ..`.
pub const PULSE: [&str; 4] = [".", "..", "...", ".."];
/// Heart beat: `♡ ♥`.
pub const HEART: [&str; 2] = ["", ""];
/// Mini progress blocks: `▁ ▂ ▃ ▄ ▅ ▆ ▇ █`.
pub const PROGRESS_BLOCKS: [&str; 8] = ["", "", "", "", "", "", "", ""];

/// All built-in presets by stable lowercase name.
///
/// # Examples
///
/// ```rust
/// assert!(loaders::spinner::frames::ALL_PRESETS.iter().any(|(name, _)| *name == "dots"));
/// ```
pub const ALL_PRESETS: &[(&str, &[&str])] = &[
    ("dots", &DOTS),
    ("dots2", &DOTS2),
    ("dots3", &DOTS3),
    ("line", &LINE),
    ("pipe", &PIPE),
    ("star", &STAR),
    ("bounce", &BOUNCE),
    ("arrows", &ARROWS),
    ("clock", &CLOCK),
    ("earth", &EARTH),
    ("moon", &MOON),
    ("runner", &RUNNER),
    ("pong", &PONG),
    ("shark", &SHARK),
    ("weather", &WEATHER),
    ("christmas", &CHRISTMAS),
    ("toggle", &TOGGLE),
    ("square_corners", &SQUARE_CORNERS),
    ("binary", &BINARY),
    ("meter", &METER),
    ("quadrants", &QUADRANTS),
    ("triangles", &TRIANGLES),
    ("circle", &CIRCLE),
    ("box_bounce", &BOX_BOUNCE),
    ("pulse", &PULSE),
    ("heart", &HEART),
    ("progress_blocks", &PROGRESS_BLOCKS),
];

#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::HashSet;

    #[test]
    fn test_all_presets_nonempty() {
        for (_, frames) in ALL_PRESETS {
            assert!(!frames.is_empty());
        }
    }

    #[test]
    fn test_all_presets_names_unique() {
        let names: HashSet<&str> = ALL_PRESETS.iter().map(|(name, _)| *name).collect();
        assert_eq!(names.len(), ALL_PRESETS.len());
    }

    #[test]
    fn test_dots_frame_count() {
        assert_eq!(DOTS.len(), 10);
    }

    #[test]
    fn test_extended_presets_present() {
        let names: HashSet<&str> = ALL_PRESETS.iter().map(|(name, _)| *name).collect();
        assert!(names.contains("binary"));
        assert!(names.contains("progress_blocks"));
        assert!(ALL_PRESETS.len() >= 27);
    }
}