feat: Add support for prefix and suffix to formats

This commit is contained in:
NBonaparte 2016-12-02 13:31:45 -08:00 committed by Michael Carlberg
parent fbca73a83b
commit ffbedf4217
3 changed files with 21 additions and 2 deletions

View File

@ -59,6 +59,8 @@ namespace modules {
struct module_format { struct module_format {
string value; string value;
vector<string> tags; vector<string> tags;
label_t prefix;
label_t suffix;
string fg; string fg;
string bg; string bg;
string ul; string ul;

View File

@ -159,7 +159,7 @@ namespace modules {
int i = 0; int i = 0;
bool tag_built = true; 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(); bool is_blankspace = tag.empty();
if (tag[0] == '<' && tag[tag.length() - 1] == '>') { if (tag[0] == '<' && tag[tag.length() - 1] == '>') {

View File

@ -2,6 +2,7 @@
#include "components/builder.hpp" #include "components/builder.hpp"
#include "modules/meta/base.hpp" #include "modules/meta/base.hpp"
#include "drawtypes/label.hpp"
POLYBAR_NS POLYBAR_NS
@ -31,7 +32,11 @@ namespace modules {
builder->space(padding); builder->space(padding);
} }
builder->append(move(output)); if (!output.empty()) {
builder->node(prefix);
builder->append(move(output));
builder->node(suffix);
}
if (padding > 0) { if (padding > 0) {
builder->space(padding); builder->space(padding);
@ -72,6 +77,18 @@ namespace modules {
format->offset = m_conf.get<int>(m_modname, name + "-offset", 0); format->offset = m_conf.get<int>(m_modname, name + "-offset", 0);
format->tags.swap(tags); 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, ' ')) { for (auto&& tag : string_util::split(format->value, ' ')) {
if (tag[0] != '<' || tag[tag.length() - 1] != '>') { if (tag[0] != '<' || tag[tag.length() - 1] != '>') {
continue; continue;