config: Config error limit/hyprctl (#5165)

* Add error_limit to limit the number of config error messages shown in notification

* Add configerrors hyprctl command

* Formatting

* Formatting for not my code

* Use CVarList, add escapeJSONStrings

* Add indication there are more undisplayed errors

* Restore suppress_errors; move getErrors() to ConfigManager

* Formatting, wtf

* Format
This commit is contained in:
zakk4223
2024-03-20 21:55:13 -04:00
committed by GitHub
parent 214ec82ba7
commit 4c796683c0
4 changed files with 54 additions and 3 deletions

View File

@@ -17,6 +17,7 @@
#include "../config/ConfigValue.hpp"
#include "../managers/CursorManager.hpp"
#include "../hyprerror/HyprError.hpp"
static void trimTrailingComma(std::string& str) {
if (!str.empty() && str.back() == ',')
@@ -497,6 +498,29 @@ std::string layoutsRequest(eHyprCtlOutputFormat format, std::string request) {
return result;
}
std::string configErrorsRequest(eHyprCtlOutputFormat format, std::string request) {
std::string result = "";
std::string currErrors = g_pConfigManager->getErrors();
CVarList errLines(currErrors, 0, '\n');
if (format == eHyprCtlOutputFormat::FORMAT_JSON) {
result += "[";
for (auto line : errLines) {
result += std::format(
R"#(
"{}",)#",
escapeJSONStrings(line));
}
trimTrailingComma(result);
result += "\n]\n";
} else {
for (auto line : errLines) {
result += std::format("{}\n", line);
}
}
return result;
}
std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) {
std::string result = "";
@@ -1531,6 +1555,7 @@ CHyprCtl::CHyprCtl() {
registerCommand(SHyprCtlCommand{"animations", true, animationsRequest});
registerCommand(SHyprCtlCommand{"rollinglog", true, rollinglogRequest});
registerCommand(SHyprCtlCommand{"layouts", true, layoutsRequest});
registerCommand(SHyprCtlCommand{"configerrors", true, configErrorsRequest});
registerCommand(SHyprCtlCommand{"monitors", false, monitorsRequest});
registerCommand(SHyprCtlCommand{"reload", false, reloadRequest});