mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 01:25:58 +01:00
hyprctl: output json with --batch
if requested (#5277)
This commit is contained in:
parent
1a0b8d1263
commit
9b7ae25ae8
1 changed files with 9 additions and 3 deletions
|
@ -22,6 +22,7 @@
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
const std::string USAGE = R"#(usage: hyprctl [(opt)flags] [command] [(opt)args]
|
const std::string USAGE = R"#(usage: hyprctl [(opt)flags] [command] [(opt)args]
|
||||||
|
|
||||||
|
@ -234,9 +235,14 @@ void requestHyprpaper(std::string arg) {
|
||||||
std::cout << std::string(buffer);
|
std::cout << std::string(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void batchRequest(std::string arg) {
|
void batchRequest(std::string arg, bool json) {
|
||||||
std::string rq = "[[BATCH]]" + arg.substr(arg.find_first_of(" ") + 1);
|
std::string commands = arg.substr(arg.find_first_of(" ") + 1);
|
||||||
|
|
||||||
|
if (json) {
|
||||||
|
commands = "j/" + std::regex_replace(commands, std::regex(";\\s*"), ";j/");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string rq = "[[BATCH]]" + commands;
|
||||||
request(rq);
|
request(rq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +389,7 @@ int main(int argc, char** argv) {
|
||||||
int exitStatus = 0;
|
int exitStatus = 0;
|
||||||
|
|
||||||
if (fullRequest.contains("/--batch"))
|
if (fullRequest.contains("/--batch"))
|
||||||
batchRequest(fullRequest);
|
batchRequest(fullRequest, json);
|
||||||
else if (fullRequest.contains("/hyprpaper"))
|
else if (fullRequest.contains("/hyprpaper"))
|
||||||
requestHyprpaper(fullRequest);
|
requestHyprpaper(fullRequest);
|
||||||
else if (fullRequest.contains("/switchxkblayout"))
|
else if (fullRequest.contains("/switchxkblayout"))
|
||||||
|
|
Loading…
Reference in a new issue