fix(format): Ignore empty contents
This commit is contained in:
parent
4bc203dd1f
commit
db7aa7c490
@ -137,13 +137,13 @@ namespace modules {
|
|||||||
if (tag_built)
|
if (tag_built)
|
||||||
i++;
|
i++;
|
||||||
} else if (is_blankspace && tag_built) {
|
} else if (is_blankspace && tag_built) {
|
||||||
m_builder->node(" ");
|
m_builder->space(1_z);
|
||||||
} else if (!is_blankspace) {
|
} else if (!is_blankspace) {
|
||||||
m_builder->node(tag);
|
m_builder->node(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return format->decorate(m_builder.get(), m_builder->flush());
|
return format->decorate(&*m_builder, m_builder->flush());
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -13,12 +13,12 @@ POLYBAR_NS
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
builder::builder(const bar_settings bar) : m_bar(bar) {
|
builder::builder(const bar_settings bar) : m_bar(bar) {
|
||||||
m_tags[syntaxtag::A] = 1;
|
m_tags[syntaxtag::A] = 0;
|
||||||
m_tags[syntaxtag::B] = 2;
|
m_tags[syntaxtag::B] = 0;
|
||||||
m_tags[syntaxtag::F] = 3;
|
m_tags[syntaxtag::F] = 0;
|
||||||
m_tags[syntaxtag::T] = 9;
|
m_tags[syntaxtag::T] = 0;
|
||||||
m_tags[syntaxtag::o] = 7;
|
m_tags[syntaxtag::o] = 0;
|
||||||
m_tags[syntaxtag::u] = 8;
|
m_tags[syntaxtag::u] = 0;
|
||||||
|
|
||||||
m_colors[syntaxtag::B] = string();
|
m_colors[syntaxtag::B] = string();
|
||||||
m_colors[syntaxtag::F] = string();
|
m_colors[syntaxtag::F] = string();
|
||||||
@ -58,7 +58,7 @@ string builder::flush() {
|
|||||||
cmd_close();
|
cmd_close();
|
||||||
}
|
}
|
||||||
|
|
||||||
string output = m_output.data();
|
string output{m_output};
|
||||||
|
|
||||||
// reset values
|
// reset values
|
||||||
m_tags.clear();
|
m_tags.clear();
|
||||||
@ -66,7 +66,7 @@ string builder::flush() {
|
|||||||
m_output.clear();
|
m_output.clear();
|
||||||
m_fontindex = 1;
|
m_fontindex = 1;
|
||||||
|
|
||||||
return string_util::replace_all(output, string{BUILDER_SPACE_TOKEN}, " ");
|
return string_util::replace_all(output, BUILDER_SPACE_TOKEN, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +10,11 @@ namespace modules {
|
|||||||
// module_format {{{
|
// module_format {{{
|
||||||
|
|
||||||
string module_format::decorate(builder* builder, string output) {
|
string module_format::decorate(builder* builder, string output) {
|
||||||
|
if (output.empty()) {
|
||||||
|
builder->flush();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
if (offset != 0) {
|
if (offset != 0) {
|
||||||
builder->offset(offset);
|
builder->offset(offset);
|
||||||
}
|
}
|
||||||
@ -64,17 +69,19 @@ namespace modules {
|
|||||||
// module_formatter {{{
|
// module_formatter {{{
|
||||||
|
|
||||||
void module_formatter::add(string name, string fallback, vector<string>&& tags, vector<string>&& whitelist) {
|
void module_formatter::add(string name, string fallback, vector<string>&& tags, vector<string>&& whitelist) {
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
auto format = make_unique<module_format>();
|
auto format = make_unique<module_format>();
|
||||||
|
|
||||||
format->value = m_conf.get<string>(m_modname, name, move(fallback));
|
format->value = m_conf.get<string>(m_modname, name, move(fallback));
|
||||||
format->fg = m_conf.get<string>(m_modname, name + "-foreground", "");
|
format->fg = m_conf.get(m_modname, name + "-foreground", ""s);
|
||||||
format->bg = m_conf.get<string>(m_modname, name + "-background", "");
|
format->bg = m_conf.get(m_modname, name + "-background", ""s);
|
||||||
format->ul = m_conf.get<string>(m_modname, name + "-underline", "");
|
format->ul = m_conf.get(m_modname, name + "-underline", ""s);
|
||||||
format->ol = m_conf.get<string>(m_modname, name + "-overline", "");
|
format->ol = m_conf.get(m_modname, name + "-overline", ""s);
|
||||||
format->spacing = m_conf.get<int>(m_modname, name + "-spacing", DEFAULT_SPACING);
|
format->spacing = m_conf.get(m_modname, name + "-spacing", 0_z);
|
||||||
format->padding = m_conf.get<int>(m_modname, name + "-padding", 0);
|
format->padding = m_conf.get(m_modname, name + "-padding", 0_z);
|
||||||
format->margin = m_conf.get<int>(m_modname, name + "-margin", 0);
|
format->margin = m_conf.get(m_modname, name + "-margin", 0_z);
|
||||||
format->offset = m_conf.get<int>(m_modname, name + "-offset", 0);
|
format->offset = m_conf.get(m_modname, name + "-offset", 0_z);
|
||||||
format->tags.swap(tags);
|
format->tags.swap(tags);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -92,17 +99,16 @@ namespace modules {
|
|||||||
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;
|
||||||
}
|
} else if (find(format->tags.begin(), format->tags.end(), tag) != format->tags.end()) {
|
||||||
if (find(format->tags.begin(), format->tags.end(), tag) != format->tags.end()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
} else if (find(whitelist.begin(), whitelist.end(), tag) != whitelist.end()) {
|
||||||
if (find(whitelist.begin(), whitelist.end(), tag) != whitelist.end()) {
|
|
||||||
continue;
|
continue;
|
||||||
|
} else {
|
||||||
|
throw undefined_format_tag(tag + " is not a valid format tag for \""+ name +"\"");
|
||||||
}
|
}
|
||||||
throw undefined_format_tag("[" + m_modname + "] Undefined \"" + name + "\" tag: " + tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_formats.insert(make_pair(name, move(format)));
|
m_formats.insert(make_pair(move(name), move(format)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool module_formatter::has(const string& tag, const string& format_name) {
|
bool module_formatter::has(const string& tag, const string& format_name) {
|
||||||
|
@ -125,14 +125,12 @@ namespace modules {
|
|||||||
* Output content as defined in the config
|
* Output content as defined in the config
|
||||||
*/
|
*/
|
||||||
bool xwindow_module::build(builder* builder, const string& tag) const {
|
bool xwindow_module::build(builder* builder, const string& tag) const {
|
||||||
if (tag == TAG_LABEL) {
|
if (tag == TAG_LABEL && m_label && m_label.get()) {
|
||||||
builder->node(m_label);
|
builder->node(m_label);
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
Loading…
Reference in New Issue
Block a user