mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
rewriteTitle: allow multiple sequential rewrites
This commit is contained in:
parent
ef38061edd
commit
a03283d65f
@ -132,13 +132,14 @@ void Window::getTree() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Window::rewriteTitle(const std::string& title)
|
std::string Window::rewriteTitle(const std::string& title) {
|
||||||
{
|
|
||||||
const auto& rules = config_["rewrite"];
|
const auto& rules = config_["rewrite"];
|
||||||
if (!rules.isObject()) {
|
if (!rules.isObject()) {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string res = title;
|
||||||
|
|
||||||
for (auto it = rules.begin(); it != rules.end(); ++it) {
|
for (auto it = rules.begin(); it != rules.end(); ++it) {
|
||||||
if (it.key().isString() && it->isString()) {
|
if (it.key().isString() && it->isString()) {
|
||||||
try {
|
try {
|
||||||
@ -146,7 +147,7 @@ std::string Window::rewriteTitle(const std::string& title)
|
|||||||
// in this case, log error and try the next rule.
|
// in this case, log error and try the next rule.
|
||||||
const std::regex rule{it.key().asString()};
|
const std::regex rule{it.key().asString()};
|
||||||
if (std::regex_match(title, rule)) {
|
if (std::regex_match(title, rule)) {
|
||||||
return std::regex_replace(title, rule, it->asString());
|
res = std::regex_replace(res, rule, it->asString());
|
||||||
}
|
}
|
||||||
} catch (const std::regex_error& e) {
|
} catch (const std::regex_error& e) {
|
||||||
spdlog::error("Invalid rule {}: {}", it.key().asString(), e.what());
|
spdlog::error("Invalid rule {}: {}", it.key().asString(), e.what());
|
||||||
@ -154,7 +155,7 @@ std::string Window::rewriteTitle(const std::string& title)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return title;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace waybar::modules::sway
|
} // namespace waybar::modules::sway
|
||||||
|
Loading…
Reference in New Issue
Block a user