Commit 39877c6c5b
Unsigned
Layout: unified · split
src/config.rs +27 −1
| @@ -18,7 +18,7 @@ use crate::{MatrixServer, Servers}; | ||
| 18 | 18 | use weechat::config::{ |
| 19 | 19 | BooleanOptionSettings, Conf, ConfigOption, ConfigSection, |
| 20 | 20 | ConfigSectionSettings, IntegerOptionSettings, OptionChanged, SectionHandle, |
| 21 | SectionHandleMut, SectionReadCallback, StringOptionSettings, | |
| 21 | SectionHandleMut, SectionReadCallback, StringOptionSettings, ColorOptionSettings, | |
| 22 | 22 | }; |
| 23 | 23 | use weechat::Weechat; |
| 24 | 24 | |
| @@ -74,6 +74,22 @@ macro_rules! string_create { | ||
| 74 | 74 | }; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | macro_rules! color_create { | |
| 78 | ($option_name:ident, $description:literal, $default:literal) => { | |
| 79 | paste::item! { | |
| 80 | fn [<create_option_ $option_name>](section: &mut SectionHandleMut) { | |
| 81 | let option_name = stringify!($option_name); | |
| 82 | let option_settings = ColorOptionSettings::new(option_name) | |
| 83 | .description($description) | |
| 84 | .default_value($default); | |
| 85 | ||
| 86 | section.new_color_option(option_settings) | |
| 87 | .expect(&format!("Can't create option {}", option_name)); | |
| 88 | } | |
| 89 | } | |
| 90 | }; | |
| 91 | } | |
| 92 | ||
| 77 | 93 | macro_rules! bool_create { |
| 78 | 94 | ($option_name:ident, $description:literal, $default:literal) => { |
| 79 | 95 | paste::item! { |
| @@ -166,6 +182,11 @@ macro_rules! option { | ||
| 166 | 182 | option_getter!(String, $option_name, String); |
| 167 | 183 | }; |
| 168 | 184 | |
| 185 | (Color, $option_name:ident, $description:literal, $default:literal $(,)?) => { | |
| 186 | color_create!($option_name, $description, $default); | |
| 187 | option_getter!(Color, $option_name, String); | |
| 188 | }; | |
| 189 | ||
| 169 | 190 | (bool, $option_name:ident, $description:literal, $default:literal $(,)?) => { |
| 170 | 191 | bool_create!($option_name, $description, $default); |
| 171 | 192 | option_getter!(Boolean, $option_name, bool); |
| @@ -317,6 +338,11 @@ config!( | ||
| 317 | 338 | "description", |
| 318 | 339 | false, |
| 319 | 340 | }, |
| 341 | ||
| 342 | color_test: Color { | |
| 343 | "color", | |
| 344 | "darkgray", | |
| 345 | }, | |
| 320 | 346 | }, |
| 321 | 347 | ); |
| 322 | 348 | |