Commit 799862c106
Unsigned
Layout: unified · split
src/config.rs +27 −2
| @@ -18,7 +18,7 @@ use crate::{MatrixServer, Servers}; | ||
| 18 | 18 | use weechat::config::{ |
| 19 | 19 | Conf, ConfigOption, ConfigSection, ConfigSectionSettings, |
| 20 | 20 | IntegerOptionSettings, OptionChanged, SectionHandle, SectionHandleMut, |
| 21 | SectionReadCallback, StringOptionSettings, | |
| 21 | SectionReadCallback, StringOptionSettings, BooleanOptionSettings, | |
| 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! bool_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 = BooleanOptionSettings::new(option_name) | |
| 83 | .description($description) | |
| 84 | .default_value($default); | |
| 85 | ||
| 86 | section.new_boolean_option(option_settings) | |
| 87 | .expect(&format!("Can't create option {}", option_name)); | |
| 88 | } | |
| 89 | } | |
| 90 | }; | |
| 91 | } | |
| 92 | ||
| 77 | 93 | macro_rules! integer_create { |
| 78 | 94 | ($option_name:ident, $description:literal, $default:literal, $min:literal, $max:literal, [$($string_value:literal), *]) => { |
| 79 | 95 | paste::item! { |
| @@ -150,6 +166,11 @@ macro_rules! option { | ||
| 150 | 166 | option_getter!(String, $option_name, String); |
| 151 | 167 | }; |
| 152 | 168 | |
| 169 | (bool, $option_name:ident, $description:literal, $default:literal) => { | |
| 170 | bool_create!($option_name, $description, $default); | |
| 171 | option_getter!(Boolean, $option_name, bool); | |
| 172 | }; | |
| 173 | ||
| 153 | 174 | (Integer, $option_name:ident, $description:literal, $default:literal, $min:literal, $max:literal) => { |
| 154 | 175 | integer_create!($option_name, $description, $default, $min, $max, []); |
| 155 | 176 | option_getter!(Integer, $option_name, i64); |
| @@ -288,8 +309,12 @@ config!( | ||
| 288 | 309 | enum_test: Enum { |
| 289 | 310 | "test", |
| 290 | 311 | Test |
| 291 | } | |
| 312 | }, | |
| 292 | 313 | |
| 314 | bool_test: bool { | |
| 315 | "description", | |
| 316 | false | |
| 317 | } | |
| 293 | 318 | } |
| 294 | 319 | ); |
| 295 | 320 | |