use promkit_core::crossterm::style::ContentStyle;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(default))]
#[derive(Clone)]
pub struct Config {
pub cursor: String,
#[cfg_attr(
feature = "serde",
serde(with = "termcfg::crossterm_config::option_content_style_serde")
)]
pub active_item_style: Option<ContentStyle>,
#[cfg_attr(
feature = "serde",
serde(with = "termcfg::crossterm_config::option_content_style_serde")
)]
pub inactive_item_style: Option<ContentStyle>,
pub lines: Option<usize>,
}
impl Default for Config {
fn default() -> Self {
Self {
cursor: String::from("❯ "),
active_item_style: None,
inactive_item_style: None,
lines: None,
}
}
}
#[cfg(test)]
mod tests {
#[cfg(feature = "serde")]
mod deserialize {
use promkit_core::crossterm::style::{Attribute, Color};
use super::super::Config;
#[test]
fn loads_all_fields_from_toml() {
let input = r#"
cursor = "> "
active_item_style = "fg=cyan,attr=bold"
inactive_item_style = "fg=grey"
lines = 8
"#;
let config: Config = toml::from_str(input).unwrap();
assert_eq!(config.cursor, "> ");
let active = config.active_item_style.unwrap();
assert_eq!(active.foreground_color, Some(Color::Cyan));
assert!(active.attributes.has(Attribute::Bold));
let inactive = config.inactive_item_style.unwrap();
assert_eq!(inactive.foreground_color, Some(Color::Grey));
assert_eq!(config.lines, Some(8));
}
}
}