From ffbedf421739ab2a85855db7903613516e38a752 Mon Sep 17 00:00:00 2001 From: NBonaparte <98007b33@opayq.com> Date: Fri, 2 Dec 2016 13:31:45 -0800 Subject: [PATCH] feat: Add support for prefix and suffix to formats --- include/modules/meta/base.hpp | 2 ++ include/modules/meta/base.inl | 2 +- src/modules/meta/base.cpp | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/modules/meta/base.hpp b/include/modules/meta/base.hpp index 76e80fd6..0b9fbd46 100644 --- a/include/modules/meta/base.hpp +++ b/include/modules/meta/base.hpp @@ -59,6 +59,8 @@ namespace modules { struct module_format { string value; vector tags; + label_t prefix; + label_t suffix; string fg; string bg; string ul; diff --git a/include/modules/meta/base.inl b/include/modules/meta/base.inl index 9f241e3a..98a27d55 100644 --- a/include/modules/meta/base.inl +++ b/include/modules/meta/base.inl @@ -159,7 +159,7 @@ namespace modules { int i = 0; bool tag_built = true; - for (auto tag : string_util::split(format->value, ' ')) { + for (auto&& tag : string_util::split(format->value, ' ')) { bool is_blankspace = tag.empty(); if (tag[0] == '<' && tag[tag.length() - 1] == '>') { diff --git a/src/modules/meta/base.cpp b/src/modules/meta/base.cpp index 3dce5238..6b14aad9 100644 --- a/src/modules/meta/base.cpp +++ b/src/modules/meta/base.cpp @@ -2,6 +2,7 @@ #include "components/builder.hpp" #include "modules/meta/base.hpp" +#include "drawtypes/label.hpp" POLYBAR_NS @@ -31,7 +32,11 @@ namespace modules { builder->space(padding); } - builder->append(move(output)); + if (!output.empty()) { + builder->node(prefix); + builder->append(move(output)); + builder->node(suffix); + } if (padding > 0) { builder->space(padding); @@ -72,6 +77,18 @@ namespace modules { format->offset = m_conf.get(m_modname, name + "-offset", 0); format->tags.swap(tags); + try { + format->prefix = load_label(m_conf, m_modname, name + "-prefix"); + } catch (const key_error& err) { + // prefix not defined + } + + try { + format->suffix = load_label(m_conf, m_modname, name + "-suffix"); + } catch (const key_error& err) { + // suffix not defined + } + for (auto&& tag : string_util::split(format->value, ' ')) { if (tag[0] != '<' || tag[tag.length() - 1] != '>') { continue;