pub struct Palette {
pub reset: &'static str,
pub dim: &'static str,
pub label: &'static str,
pub sep: &'static str,
pub spend: &'static str,
pub tokens_normal: &'static str,
pub tokens_alert: &'static str,
#[allow(dead_code)]
pub badge: &'static str,
pub pr: &'static str,
pub trend_up: &'static str,
pub trend_down: &'static str,
}
impl Palette {
pub fn for_theme(theme_name: &str) -> Self {
match theme_name.to_lowercase().as_str() {
"github" | "default" => Self {
reset: "\x1b[0m",
dim: "\x1b[90m",
label: "\x1b[90m",
sep: "\x1b[90m │ \x1b[0m",
spend: "\x1b[92m", tokens_normal: "\x1b[97m", tokens_alert: "\x1b[1;31m", badge: "\x1b[93m", pr: "\x1b[33m", trend_up: "\x1b[92m", trend_down: "\x1b[91m", },
"nord" => Self {
reset: "\x1b[0m",
dim: "\x1b[90m",
label: "\x1b[90m",
sep: "\x1b[90m │ \x1b[0m",
spend: "\x1b[36m", tokens_normal: "\x1b[97m",
tokens_alert: "\x1b[1;31m",
badge: "\x1b[93m",
pr: "\x1b[33m", trend_up: "\x1b[92m",
trend_down: "\x1b[91m",
},
"tokyo-night" => Self {
reset: "\x1b[0m",
dim: "\x1b[90m",
label: "\x1b[90m",
sep: "\x1b[90m │ \x1b[0m",
spend: "\x1b[95m", tokens_normal: "\x1b[97m",
tokens_alert: "\x1b[1;31m",
badge: "\x1b[93m",
pr: "\x1b[93m", trend_up: "\x1b[92m",
trend_down: "\x1b[91m",
},
"plain" => Self {
reset: "",
dim: "",
label: "",
sep: " | ",
spend: "",
tokens_normal: "",
tokens_alert: "",
badge: "",
pr: "",
trend_up: "",
trend_down: "",
},
_ => Self {
reset: "\x1b[0m",
dim: "\x1b[90m",
label: "\x1b[90m",
sep: "\x1b[90m │ \x1b[0m",
spend: "\x1b[94m", tokens_normal: "\x1b[97m", tokens_alert: "\x1b[1;31m", badge: "\x1b[93m", pr: "\x1b[93m", trend_up: "\x1b[94m", trend_down: "\x1b[38;5;208m", },
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_theme_selection() {
let cb = Palette::for_theme("colorblind");
assert_eq!(cb.spend, "\x1b[94m");
let gh = Palette::for_theme("github");
assert_eq!(gh.spend, "\x1b[92m");
let plain = Palette::for_theme("plain");
assert_eq!(plain.reset, "");
assert_eq!(plain.sep, " | ");
assert_eq!(plain.pr, "");
assert_eq!(cb.pr, "\x1b[93m");
}
}