summaryrefslogtreecommitdiff
path: root/src/debug/HyprCtl.cpp
diff options
context:
space:
mode:
authorRuslan <tetrois@ya.ru>2024-11-17 02:18:30 +0300
committerGitHub <noreply@github.com>2024-11-16 23:18:30 +0000
commitaf83c825138386d269d69b3ef755b844a2eacb22 (patch)
tree83e3b171fe95699cb666e362e87e54cc545257b4 /src/debug/HyprCtl.cpp
parent9d37b1b07339b1b222ceab5952cd9b927fbf6d73 (diff)
hyprctl: add json output on hyprctl -j plugins list (#8480)
--------- Co-authored-by: Руслан Новокшонов <r.novokshonov@vk.team>
Diffstat (limited to 'src/debug/HyprCtl.cpp')
-rw-r--r--src/debug/HyprCtl.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp
index c5eba0a7..964a193b 100644
--- a/src/debug/HyprCtl.cpp
+++ b/src/debug/HyprCtl.cpp
@@ -1472,17 +1472,40 @@ std::string dispatchPlugin(eHyprCtlOutputFormat format, std::string request) {
g_pPluginSystem->unloadPlugin(PLUGIN);
} else if (OPERATION == "list") {
- const auto PLUGINS = g_pPluginSystem->getAllPlugins();
+ const auto PLUGINS = g_pPluginSystem->getAllPlugins();
+ std::string result = "";
- if (PLUGINS.size() == 0)
- return "no plugins loaded";
+ if (format == eHyprCtlOutputFormat::FORMAT_JSON) {
+ result += "[";
- std::string list = "";
- for (auto const& p : PLUGINS) {
- list += std::format("\nPlugin {} by {}:\n\tHandle: {:x}\n\tVersion: {}\n\tDescription: {}\n", p->name, p->author, (uintptr_t)p->m_pHandle, p->version, p->description);
+ if (PLUGINS.size() == 0)
+ return "[]";
+
+ for (auto const& p : PLUGINS) {
+ result += std::format(
+ R"#(
+{{
+ "name": "{}",
+ "author": "{}",
+ "handle": "{:x}",
+ "version": "{}",
+ "description": "{}"
+}},)#",
+ escapeJSONStrings(p->name), escapeJSONStrings(p->author), (uintptr_t)p->m_pHandle, escapeJSONStrings(p->version), escapeJSONStrings(p->description));
+ }
+ trimTrailingComma(result);
+ result += "]";
+ } else {
+ if (PLUGINS.size() == 0)
+ return "no plugins loaded";
+
+ for (auto const& p : PLUGINS) {
+ result +=
+ std::format("\nPlugin {} by {}:\n\tHandle: {:x}\n\tVersion: {}\n\tDescription: {}\n", p->name, p->author, (uintptr_t)p->m_pHandle, p->version, p->description);
+ }
}
- return list;
+ return result;
} else {
return "unknown opt";
}