Commit 799862c106

799862c106a9a839c18fb9b09edd22a6bb9dac25

parent: 4026269346

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-06-27 12:55 UTC

config: Add support to declare boolean options.

Layout: unified · split

src/config.rs +27 −2
@@ -18,7 +18,7 @@ use crate::{MatrixServer, Servers};
1818use weechat::config::{
1919 Conf, ConfigOption, ConfigSection, ConfigSectionSettings,
2020 IntegerOptionSettings, OptionChanged, SectionHandle, SectionHandleMut,
21 SectionReadCallback, StringOptionSettings,
21 SectionReadCallback, StringOptionSettings, BooleanOptionSettings,
2222};
2323use weechat::Weechat;
2424
@@ -74,6 +74,22 @@ macro_rules! string_create {
7474 };
7575}
7676
77macro_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
7793macro_rules! integer_create {
7894 ($option_name:ident, $description:literal, $default:literal, $min:literal, $max:literal, [$($string_value:literal), *]) => {
7995 paste::item! {
@@ -150,6 +166,11 @@ macro_rules! option {
150166 option_getter!(String, $option_name, String);
151167 };
152168
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
153174 (Integer, $option_name:ident, $description:literal, $default:literal, $min:literal, $max:literal) => {
154175 integer_create!($option_name, $description, $default, $min, $max, []);
155176 option_getter!(Integer, $option_name, i64);
@@ -288,8 +309,12 @@ config!(
288309 enum_test: Enum {
289310 "test",
290311 Test
291 }
312 },
292313
314 bool_test: bool {
315 "description",
316 false
317 }
293318 }
294319);
295320