114 lines
3.8 KiB
Rust
114 lines
3.8 KiB
Rust
//! 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(super) static HELP_BLOCK_SELECTION: LazyLock<String> = LazyLock::new(|| {
|
|
let mut targets = BLOCK_PROGRESSION
|
|
.keys()
|
|
.map(|v| v.to_owned())
|
|
.collect::<Vec<String>>();
|
|
targets.sort();
|
|
targets.join(", ").to_string()
|
|
});
|
|
|
|
/// List all targets
|
|
pub(super) static HELP_VERBOSITY_LEVEL: LazyLock<String> = LazyLock::new(|| {
|
|
let mut targets = STR_TO_VERBOSITY
|
|
.values()
|
|
.map(|v| format!("{:?}", v).to_lowercase())
|
|
.collect::<Vec<String>>();
|
|
targets.sort();
|
|
targets.join(", ").to_string()
|
|
});
|
|
|
|
/// List all targets
|
|
pub(super) static HELP_BUILD_TARGET_LIST: LazyLock<String> = LazyLock::new(|| {
|
|
let targets = STR_TO_BUILD_TARGET
|
|
.values()
|
|
.map(|v| format!("{:?}", v).to_lowercase())
|
|
.collect::<Vec<String>>();
|
|
targets.join(", ").to_string()
|
|
});
|
|
|
|
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(super) static BLOCK_PROGRESSION: LazyLock<HashMap<String, String>> = 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(&[
|
|
// "▹▹▹▹▹",
|
|
// "▸▹▹▹▹",
|
|
// "▹▸▹▹▹",
|
|
// "▹▹▸▹▹",
|
|
// "▹▹▹▸▹",
|
|
// "▹▹▹▹▸",
|
|
// "▪▪▪▪▪",
|
|
// ]),
|