//! Printing and misc utilities use crate::makepdf_structs::{MakeTargets, VerboseLevel}; use phf::phf_map; use std::{collections::HashMap, sync::LazyLock}; /// Convert str to verbosity level static STR_TO_VERBOSITY: phf::Map<&'static str, VerboseLevel> = phf_map! { "misc" =>VerboseLevel::Misc, "box" => VerboseLevel::Box, "context" => VerboseLevel::Context, "info" => VerboseLevel::Info, "warning" => VerboseLevel::Warning, "error" => VerboseLevel::Error, "critical" => VerboseLevel::Critical, }; /// Convert str to build target static STR_TO_BUILD_TARGET: phf::Map<&'static str, MakeTargets> = phf_map! { "all" => MakeTargets::All, "list" => MakeTargets::List, "glossaries" => MakeTargets::Glossaries, "clean" => MakeTargets::Clean, }; /// List all blocktype pub(crate) static HELP_BLOCK_SELECTION: LazyLock = LazyLock::new(|| { let mut targets = BLOCK_PROGRESSION.keys().collect::>(); targets.sort(); format!("{:?}", targets) }); /// List all targets pub(crate) static HELP_VERBOSITY_LEVEL: LazyLock = LazyLock::new(|| { let mut targets = STR_TO_VERBOSITY.values().collect::>(); targets.sort(); format!("{:?}", targets) }); /// List all targets pub(crate) static HELP_BUILD_TARGET_LIST: LazyLock = LazyLock::new(|| { let targets = STR_TO_BUILD_TARGET.values().collect::>(); format!("{:?}", targets) }); impl From<&str> for VerboseLevel { fn from(value: &str) -> Self { if let Some(target) = STR_TO_VERBOSITY.get(&value.to_lowercase()).cloned() { target } else { panic!( "Invalid debug level {}. The debug level available are (from highest verbosity to lowest): {:?}", value, HELP_VERBOSITY_LEVEL ) } } } impl From<&str> for MakeTargets { fn from(value: &str) -> Self { if let Some(target) = STR_TO_BUILD_TARGET.get(&value.to_lowercase()).cloned() { target } else { panic!( "Invalid build target {}. The build target available are {:?}", value, HELP_BUILD_TARGET_LIST ) } } } /// All progress bar styles pub(crate) static BLOCK_PROGRESSION: LazyLock> = LazyLock::new(|| { let mut m = HashMap::new(); m.insert("class".to_string(), "#>-".to_string()); m.insert("cargo".to_string(), "#> ".to_string()); m.insert("rough".to_string(), "█ ".to_string()); m.insert("fine".to_string(), "█▉▊▋▌▍▎▏ ".to_string()); m.insert("vert".to_string(), "█▇▆▅▄▃▂▁ ".to_string()); m.insert("fade".to_string(), "█▓▒░ ".to_string()); m.insert("block".to_string(), "█▛▌▖ ".to_string()); m.insert("curse".to_string(), "▓▙▚▐▔ ▛▘▖▄▟▞▂█".to_string()); m.insert("load".to_string(), " ⱠØ₳Đł₦₲ ".to_string()); m.insert("cool".to_string(), "▰▱".to_string()); m.insert("neo".to_string(), "▰═".to_string()); m }); // Spinners // ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▁ // ▉▊▋▌▍▎▏▎▍▌▋▊▉ // ▖ ▘ ▝ ▗ // ┤ ┘ ┴ └ ├ ┌ ┬ ┐ // ◢ ◣ ◤ ◥ // ◡◡ ⊙⊙ ◠◠ // ⣾⣽⣻⢿⡿⣟⣯⣷ ⠁⠂⠄⡀⢀⠠⠐⠈ // .tick_strings(&[ // "▹▹▹▹▹", // "▸▹▹▹▹", // "▹▸▹▹▹", // "▹▹▸▹▹", // "▹▹▹▸▹", // "▹▹▹▹▸", // "▪▪▪▪▪", // ]),