Merge pull request #2068 from TheRealLorenz/master
commit
a6084ea7e6
|
@ -4,5 +4,5 @@
|
|||
#include <string>
|
||||
|
||||
namespace waybar::util {
|
||||
std::string rewriteTitle(const std::string&, const Json::Value&);
|
||||
std::string rewriteString(const std::string&, const Json::Value&);
|
||||
}
|
|
@ -87,7 +87,7 @@ Addressed by *sway/window*
|
|||
|
||||
*rewrite*: ++
|
||||
typeof: object ++
|
||||
Rules to rewrite window title. See *rewrite rules*.
|
||||
Rules to rewrite the module format output. See *rewrite rules*.
|
||||
|
||||
*icon*: ++
|
||||
typeof: bool ++
|
||||
|
@ -116,7 +116,7 @@ captures of the expression.
|
|||
|
||||
Regular expression and replacement follow ECMA-script rules.
|
||||
|
||||
If no expression matches, the title is left unchanged.
|
||||
If no expression matches, the format output is left unchanged.
|
||||
|
||||
Invalid expressions (e.g., mismatched parentheses) are skipped.
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ src_files = files(
|
|||
'src/group.cpp',
|
||||
'src/util/ustring_clen.cpp',
|
||||
'src/util/sanitize_str.cpp',
|
||||
'src/util/rewrite_title.cpp'
|
||||
'src/util/rewrite_string.cpp'
|
||||
)
|
||||
|
||||
if is_linux
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "modules/hyprland/backend.hpp"
|
||||
#include "util/command.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "util/rewrite_title.hpp"
|
||||
#include "util/rewrite_string.hpp"
|
||||
|
||||
namespace waybar::modules::hyprland {
|
||||
|
||||
|
@ -41,7 +41,7 @@ auto Window::update() -> void {
|
|||
if (!format_.empty()) {
|
||||
label_.show();
|
||||
label_.set_markup(fmt::format(fmt::runtime(format_),
|
||||
waybar::util::rewriteTitle(lastView, config_["rewrite"])));
|
||||
waybar::util::rewriteString(lastView, config_["rewrite"])));
|
||||
} else {
|
||||
label_.hide();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
#include "util/rewrite_title.hpp"
|
||||
#include "util/rewrite_string.hpp"
|
||||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
|
@ -204,10 +204,10 @@ auto Window::update() -> void {
|
|||
old_app_id_ = app_id_;
|
||||
}
|
||||
|
||||
label_.set_markup(
|
||||
fmt::format(fmt::runtime(format_),
|
||||
fmt::arg("title", waybar::util::rewriteTitle(window_, config_["rewrite"])),
|
||||
fmt::arg("app_id", app_id_), fmt::arg("shell", shell_)));
|
||||
label_.set_markup(waybar::util::rewriteString(
|
||||
fmt::format(fmt::runtime(format_), fmt::arg("title", window_), fmt::arg("app_id", app_id_),
|
||||
fmt::arg("shell", shell_)),
|
||||
config_["rewrite"]));
|
||||
if (tooltipEnabled()) {
|
||||
label_.set_tooltip_text(window_);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#include "util/rewrite_title.hpp"
|
||||
#include "util/rewrite_string.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <regex>
|
||||
|
||||
namespace waybar::util {
|
||||
std::string rewriteTitle(const std::string& title, const Json::Value& rules) {
|
||||
std::string rewriteString(const std::string& value, const Json::Value& rules) {
|
||||
if (!rules.isObject()) {
|
||||
return title;
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string res = title;
|
||||
std::string res = value;
|
||||
|
||||
for (auto it = rules.begin(); it != rules.end(); ++it) {
|
||||
if (it.key().isString() && it->isString()) {
|
||||
|
@ -18,7 +18,7 @@ std::string rewriteTitle(const std::string& title, const Json::Value& rules) {
|
|||
// malformated regexes will cause an exception.
|
||||
// in this case, log error and try the next rule.
|
||||
const std::regex rule{it.key().asString()};
|
||||
if (std::regex_match(title, rule)) {
|
||||
if (std::regex_match(value, rule)) {
|
||||
res = std::regex_replace(res, rule, it->asString());
|
||||
}
|
||||
} catch (const std::regex_error& e) {
|
Loading…
Reference in New Issue