promkit_widgets/listbox/
config.rs1use promkit_core::crossterm::style::ContentStyle;
2
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4#[cfg_attr(feature = "serde", serde(default))]
5#[derive(Clone)]
6pub struct Config {
7 pub cursor: String,
8 #[cfg_attr(
9 feature = "serde",
10 serde(with = "termcfg::crossterm_config::option_content_style_serde")
11 )]
12 pub active_item_style: Option<ContentStyle>,
13 #[cfg_attr(
14 feature = "serde",
15 serde(with = "termcfg::crossterm_config::option_content_style_serde")
16 )]
17 pub inactive_item_style: Option<ContentStyle>,
18 pub lines: Option<usize>,
19}
20
21impl Default for Config {
22 fn default() -> Self {
23 Self {
24 cursor: String::from("❯ "),
25 active_item_style: None,
26 inactive_item_style: None,
27 lines: None,
28 }
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 #[cfg(feature = "serde")]
35 mod serde_compatibility {
36 use promkit_core::crossterm::style::{Attribute, Color};
37
38 use super::super::Config;
39
40 #[test]
41 fn config_fields_are_fully_loaded_from_toml() {
42 let input = r#"
43cursor = "> "
44active_item_style = "fg=cyan,attr=bold"
45inactive_item_style = "fg=grey"
46lines = 8
47"#;
48
49 let formatter: Config = toml::from_str(input).unwrap();
50 assert_eq!(formatter.cursor, "> ");
51 let active = formatter.active_item_style.unwrap();
52 let inactive = formatter.inactive_item_style.unwrap();
53
54 assert_eq!(active.foreground_color, Some(Color::Cyan));
55 assert!(active.attributes.has(Attribute::Bold));
56 assert_eq!(inactive.foreground_color, Some(Color::Grey));
57 assert_eq!(formatter.lines, Some(8));
58 }
59 }
60}