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};
1818use weechat::config::{
1919 BooleanOptionSettings, Conf, ConfigOption, ConfigSection,
2020 ConfigSectionSettings, IntegerOptionSettings, OptionChanged, SectionHandle,
21 SectionHandleMut, SectionReadCallback, StringOptionSettings,
21 SectionHandleMut, SectionReadCallback, StringOptionSettings, ColorOptionSettings,
2222};
2323use weechat::Weechat;
2424
@@ -74,6 +74,22 @@ macro_rules! string_create {
7474 };
7575}
7676
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
7793macro_rules! bool_create {
7894 ($option_name:ident, $description:literal, $default:literal) => {
7995 paste::item! {
@@ -166,6 +182,11 @@ macro_rules! option {
166182 option_getter!(String, $option_name, String);
167183 };
168184
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
169190 (bool, $option_name:ident, $description:literal, $default:literal $(,)?) => {
170191 bool_create!($option_name, $description, $default);
171192 option_getter!(Boolean, $option_name, bool);
@@ -317,6 +338,11 @@ config!(
317338 "description",
318339 false,
319340 },
341
342 color_test: Color {
343 "color",
344 "darkgray",
345 },
320346 },
321347);
322348