use serde_json::{Map, Value};
use std::collections::HashMap;
pub struct LemonbarPowerline;
impl LemonbarPowerline {
#[allow(non_upper_case_globals)]
pub const init_ext: &'static str = "wm";
#[allow(non_upper_case_globals)]
pub const init_renderer_module: &'static str = "lemonbar";
pub fn init() -> crate::ported::Powerline {
crate::ported::Powerline::init(
Self::init_ext,
Some(Self::init_renderer_module),
false,
false,
)
}
pub fn get_encoding() -> &'static str {
"utf-8" }
pub fn get_local_themes(local_themes: Option<&HashMap<String, Value>>) -> Map<String, Value> {
let themes = match local_themes {
None => return Map::new(),
Some(t) if t.is_empty() => return Map::new(),
Some(t) => t,
};
let mut out = Map::new();
for (key, val) in themes {
let mut wrapper = Map::new();
wrapper.insert("config".to_string(), val.clone());
out.insert(key.clone(), Value::Object(wrapper));
}
out
}
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;
#[test]
fn init_ext_is_wm() {
assert_eq!(LemonbarPowerline::init_ext, "wm");
}
#[test]
fn init_renderer_module_is_lemonbar() {
assert_eq!(LemonbarPowerline::init_renderer_module, "lemonbar");
}
#[test]
fn get_encoding_is_utf8() {
assert_eq!(LemonbarPowerline::get_encoding(), "utf-8");
}
#[test]
fn get_local_themes_none_returns_empty() {
let result = LemonbarPowerline::get_local_themes(None);
assert!(result.is_empty());
}
#[test]
fn get_local_themes_wraps_each_value_in_config_key() {
let mut input = HashMap::new();
input.insert("default".to_string(), json!({"theme": "dark"}));
let result = LemonbarPowerline::get_local_themes(Some(&input));
assert_eq!(result.len(), 1);
assert_eq!(result["default"]["config"], json!({"theme": "dark"}));
}
#[test]
fn init_constructs_powerline_with_wm_and_lemonbar() {
let p = LemonbarPowerline::init();
assert_eq!(p.ext, "wm");
assert_eq!(p.renderer_module, "powerline.renderers.lemonbar");
}
}