promkit_widgets/checkbox/
config.rs1use promkit_core::crossterm::style::{Color, 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 pub active_mark: char,
9 pub inactive_mark: char,
10 #[cfg_attr(
11 feature = "serde",
12 serde(with = "termcfg::crossterm_config::content_style_serde")
13 )]
14 pub active_item_style: ContentStyle,
15 #[cfg_attr(
16 feature = "serde",
17 serde(with = "termcfg::crossterm_config::content_style_serde")
18 )]
19 pub inactive_item_style: ContentStyle,
20 pub lines: Option<usize>,
21}
22
23impl Default for Config {
24 fn default() -> Self {
25 Self {
26 cursor: String::from("❯ "),
27 active_mark: '☒',
28 inactive_mark: '☐',
29 active_item_style: ContentStyle {
30 foreground_color: Some(Color::DarkCyan),
31 ..Default::default()
32 },
33 inactive_item_style: ContentStyle::default(),
34 lines: None,
35 }
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 #[cfg(feature = "serde")]
42 mod serde_compatibility {
43 use promkit_core::crossterm::style::{Attribute, Color};
44
45 use super::super::Config;
46
47 #[test]
48 fn config_fields_are_fully_loaded_from_toml() {
49 let input = r#"
50cursor = "> "
51active_mark = "*"
52inactive_mark = "-"
53active_item_style = "fg=cyan,attr=bold"
54inactive_item_style = "fg=grey"
55lines = 5
56"#;
57
58 let formatter: Config = toml::from_str(input).unwrap();
59
60 assert_eq!(formatter.cursor, "> ");
61 assert_eq!(formatter.active_mark, '*');
62 assert_eq!(formatter.inactive_mark, '-');
63 assert_eq!(
64 formatter.active_item_style.foreground_color,
65 Some(Color::Cyan)
66 );
67 assert!(formatter.active_item_style.attributes.has(Attribute::Bold));
68 assert_eq!(
69 formatter.inactive_item_style.foreground_color,
70 Some(Color::Grey)
71 );
72 assert_eq!(formatter.lines, Some(5));
73 }
74 }
75}