Commit 39877c6c5b

39877c6c5b7f0e29860e22aed6eb9f4d3228e633

parent: 4db611b0a3

Unsigned

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

config: Add support to declare color options.

Layout: unified · split

src/config.rs +27 −1
@@ -18,7 +18,7 @@ use crate::{MatrixServer, Servers};
18use weechat::config::{ 18use weechat::config::{
19 BooleanOptionSettings, Conf, ConfigOption, ConfigSection, 19 BooleanOptionSettings, Conf, ConfigOption, ConfigSection,
20 ConfigSectionSettings, IntegerOptionSettings, OptionChanged, SectionHandle, 20 ConfigSectionSettings, IntegerOptionSettings, OptionChanged, SectionHandle,
21 SectionHandleMut, SectionReadCallback, StringOptionSettings, 21 SectionHandleMut, SectionReadCallback, StringOptionSettings, ColorOptionSettings,
22}; 22};
23use weechat::Weechat; 23use weechat::Weechat;
24 24
@@ -74,6 +74,22 @@ macro_rules! string_create {
74 }; 74 };
75} 75}
76 76
77macro_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
77macro_rules! bool_create { 93macro_rules! bool_create {
78 ($option_name:ident, $description:literal, $default:literal) => { 94 ($option_name:ident, $description:literal, $default:literal) => {
79 paste::item! { 95 paste::item! {
@@ -166,6 +182,11 @@ macro_rules! option {
166 option_getter!(String, $option_name, String); 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 (bool, $option_name:ident, $description:literal, $default:literal $(,)?) => { 190 (bool, $option_name:ident, $description:literal, $default:literal $(,)?) => {
170 bool_create!($option_name, $description, $default); 191 bool_create!($option_name, $description, $default);
171 option_getter!(Boolean, $option_name, bool); 192 option_getter!(Boolean, $option_name, bool);
@@ -317,6 +338,11 @@ config!(
317 "description", 338 "description",
318 false, 339 false,
319 }, 340 },
341
342 color_test: Color {
343 "color",
344 "darkgray",
345 },
320 }, 346 },
321); 347);
322 348