From b16c105514245eab526fb13b29e89c11912861fd Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Thu, 26 Jan 2017 01:50:01 +0100 Subject: [PATCH] feat(modules): Move default format values to the config Fallback values for all module formats can now be set in the configuration. For example: [settings] format-padding = 2 format-underline = #00f --- src/modules/meta/base.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/modules/meta/base.cpp b/src/modules/meta/base.cpp index 4b499c24..62a6a82e 100644 --- a/src/modules/meta/base.cpp +++ b/src/modules/meta/base.cpp @@ -69,18 +69,21 @@ namespace modules { // module_formatter {{{ void module_formatter::add(string name, string fallback, vector&& tags, vector&& whitelist) { + const auto formatdef = [&]( + const string& param, const auto& fallback) { return m_conf.get("settings", "format-" + param, fallback); }; + auto format = make_unique(); format->value = m_conf.get(m_modname, name, move(fallback)); - format->fg = m_conf.get(m_modname, name + "-foreground", format->fg); - format->bg = m_conf.get(m_modname, name + "-background", format->bg); - format->ul = m_conf.get(m_modname, name + "-underline", format->ul); - format->ol = m_conf.get(m_modname, name + "-overline", format->ol); - format->ulsize = m_conf.get(m_modname, name + "-underline-size", format->ulsize); - format->olsize = m_conf.get(m_modname, name + "-overline-size", format->olsize); - format->spacing = m_conf.get(m_modname, name + "-spacing", format->spacing); - format->padding = m_conf.get(m_modname, name + "-padding", format->padding); - format->margin = m_conf.get(m_modname, name + "-margin", format->margin); - format->offset = m_conf.get(m_modname, name + "-offset", format->offset); + format->fg = m_conf.get(m_modname, name + "-foreground", formatdef("foreground", format->fg)); + format->bg = m_conf.get(m_modname, name + "-background", formatdef("background", format->bg)); + format->ul = m_conf.get(m_modname, name + "-underline", formatdef("underline", format->ul)); + format->ol = m_conf.get(m_modname, name + "-overline", formatdef("overline", format->ol)); + format->ulsize = m_conf.get(m_modname, name + "-underline-size", formatdef("underline-size", format->ulsize)); + format->olsize = m_conf.get(m_modname, name + "-overline-size", formatdef("overline-size", format->olsize)); + format->spacing = m_conf.get(m_modname, name + "-spacing", formatdef("spacing", format->spacing)); + format->padding = m_conf.get(m_modname, name + "-padding", formatdef("padding", format->padding)); + format->margin = m_conf.get(m_modname, name + "-margin", formatdef("margin", format->margin)); + format->offset = m_conf.get(m_modname, name + "-offset", formatdef("offset", format->offset)); format->tags.swap(tags); try {