ravenous-tools/config/src/make.rs

151 lines
4.5 KiB
Rust

// Workspace: config
// File: config/src/make.rs
//! Makepdf generation structs
use phf::phf_map;
use std::{collections::HashMap, fmt::Debug, 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 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 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 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()
});
/// The verbosity level
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum VerboseLevel {
/// Shouldn't be printed no matter what
None,
/// Garbage
Misc,
/// Boxness, barely above Misc
Box,
/// Context info (Debug info)
Context,
/// Usefull info
Info,
/// Important warnings
Warning,
/// Errors encountered requiring user input
Error,
/// Uncatachable errors
Critical,
/// Literrally uncatchable things
Uncatchable,
}
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
)
}
}
}
/// All progress bar styles
pub 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(&[
// "▹▹▹▹▹",
// "▸▹▹▹▹",
// "▹▸▹▹▹",
// "▹▹▸▹▹",
// "▹▹▹▸▹",
// "▹▹▹▹▸",
// "▪▪▪▪▪",
// ]),
//
/// List of all alternative targets
#[derive(Debug, Clone)]
pub enum MakeTargets {
/// Make all targets
All,
/// Make a list of all optionals
List,
/// Make glossaries
Glossaries,
/// Make the working directory clean
Clean,
}
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
)
}
}
}