mirror of
https://github.com/polybar/polybar.git
synced 2024-11-11 13:50:56 -05:00
fix(format): Ignore empty contents
This commit is contained in:
parent
4bc203dd1f
commit
db7aa7c490
4 changed files with 33 additions and 29 deletions
|
@ -137,13 +137,13 @@ namespace modules {
|
|||
if (tag_built)
|
||||
i++;
|
||||
} else if (is_blankspace && tag_built) {
|
||||
m_builder->node(" ");
|
||||
m_builder->space(1_z);
|
||||
} else if (!is_blankspace) {
|
||||
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
|
||||
|
||||
builder::builder(const bar_settings bar) : m_bar(bar) {
|
||||
m_tags[syntaxtag::A] = 1;
|
||||
m_tags[syntaxtag::B] = 2;
|
||||
m_tags[syntaxtag::F] = 3;
|
||||
m_tags[syntaxtag::T] = 9;
|
||||
m_tags[syntaxtag::o] = 7;
|
||||
m_tags[syntaxtag::u] = 8;
|
||||
m_tags[syntaxtag::A] = 0;
|
||||
m_tags[syntaxtag::B] = 0;
|
||||
m_tags[syntaxtag::F] = 0;
|
||||
m_tags[syntaxtag::T] = 0;
|
||||
m_tags[syntaxtag::o] = 0;
|
||||
m_tags[syntaxtag::u] = 0;
|
||||
|
||||
m_colors[syntaxtag::B] = string();
|
||||
m_colors[syntaxtag::F] = string();
|
||||
|
@ -58,7 +58,7 @@ string builder::flush() {
|
|||
cmd_close();
|
||||
}
|
||||
|
||||
string output = m_output.data();
|
||||
string output{m_output};
|
||||
|
||||
// reset values
|
||||
m_tags.clear();
|
||||
|
@ -66,7 +66,7 @@ string builder::flush() {
|
|||
m_output.clear();
|
||||
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 {{{
|
||||
|
||||
string module_format::decorate(builder* builder, string output) {
|
||||
if (output.empty()) {
|
||||
builder->flush();
|
||||
return "";
|
||||
}
|
||||
|
||||
if (offset != 0) {
|
||||
builder->offset(offset);
|
||||
}
|
||||
|
@ -64,17 +69,19 @@ namespace modules {
|
|||
// module_formatter {{{
|
||||
|
||||
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>();
|
||||
|
||||
format->value = m_conf.get<string>(m_modname, name, move(fallback));
|
||||
format->fg = m_conf.get<string>(m_modname, name + "-foreground", "");
|
||||
format->bg = m_conf.get<string>(m_modname, name + "-background", "");
|
||||
format->ul = m_conf.get<string>(m_modname, name + "-underline", "");
|
||||
format->ol = m_conf.get<string>(m_modname, name + "-overline", "");
|
||||
format->spacing = m_conf.get<int>(m_modname, name + "-spacing", DEFAULT_SPACING);
|
||||
format->padding = m_conf.get<int>(m_modname, name + "-padding", 0);
|
||||
format->margin = m_conf.get<int>(m_modname, name + "-margin", 0);
|
||||
format->offset = m_conf.get<int>(m_modname, name + "-offset", 0);
|
||||
format->fg = m_conf.get(m_modname, name + "-foreground", ""s);
|
||||
format->bg = m_conf.get(m_modname, name + "-background", ""s);
|
||||
format->ul = m_conf.get(m_modname, name + "-underline", ""s);
|
||||
format->ol = m_conf.get(m_modname, name + "-overline", ""s);
|
||||
format->spacing = m_conf.get(m_modname, name + "-spacing", 0_z);
|
||||
format->padding = m_conf.get(m_modname, name + "-padding", 0_z);
|
||||
format->margin = m_conf.get(m_modname, name + "-margin", 0_z);
|
||||
format->offset = m_conf.get(m_modname, name + "-offset", 0_z);
|
||||
format->tags.swap(tags);
|
||||
|
||||
try {
|
||||
|
@ -92,17 +99,16 @@ namespace modules {
|
|||
for (auto&& tag : string_util::split(format->value, ' ')) {
|
||||
if (tag[0] != '<' || tag[tag.length() - 1] != '>') {
|
||||
continue;
|
||||
}
|
||||
if (find(format->tags.begin(), format->tags.end(), tag) != format->tags.end()) {
|
||||
} else if (find(format->tags.begin(), format->tags.end(), tag) != format->tags.end()) {
|
||||
continue;
|
||||
}
|
||||
if (find(whitelist.begin(), whitelist.end(), tag) != whitelist.end()) {
|
||||
} else if (find(whitelist.begin(), whitelist.end(), tag) != whitelist.end()) {
|
||||
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) {
|
||||
|
|
|
@ -125,13 +125,11 @@ namespace modules {
|
|||
* Output content as defined in the config
|
||||
*/
|
||||
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);
|
||||
} else {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue