diff options
author | memchr <[email protected]> | 2023-09-20 07:26:20 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2023-09-20 08:26:20 +0100 |
commit | 6594b50e57935dd66930ccd35dba7a1b4131399d (patch) | |
tree | 17d4fa7aabf0e447c7171346c5b851c999093149 /hyprctl/main.cpp | |
parent | d8d0cd75c2db16a14086e1d5119ed937a60c701e (diff) | |
download | Hyprland-6594b50e57935dd66930ccd35dba7a1b4131399d.tar.gz Hyprland-6594b50e57935dd66930ccd35dba7a1b4131399d.zip |
logging/format: use std::format_string to catch formatting string errors at compile time (#3377)
* fix(log): use constexpr format string
* deprecate getFormat
Diffstat (limited to 'hyprctl/main.cpp')
-rw-r--r-- | hyprctl/main.cpp | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 6f418c05..aebc1cbb 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -12,6 +12,7 @@ #include <ranges> #include <algorithm> #include <signal.h> +#include <format> #include <iostream> #include <string> @@ -106,20 +107,6 @@ std::vector<SInstanceData> instances() { return result; } -std::string getFormat(const char* fmt, ...) { - char* outputStr = nullptr; - - va_list args; - va_start(args, fmt); - vasprintf(&outputStr, fmt, args); - va_end(args); - - std::string output = std::string(outputStr); - free(outputStr); - - return output; -} - void request(std::string arg, int minArgs = 0) { const auto SERVERSOCKET = socket(AF_UNIX, SOCK_STREAM, 0); @@ -248,19 +235,19 @@ void instancesRequest(bool json) { if (!json) { for (auto& el : inst) { - result += getFormat("instance %s:\n\ttime: %llu\n\tpid: %llu\n\twl socket: %s\n\n", el.id.c_str(), el.time, el.pid, el.wlSocket.c_str()); + result += std::format("instance {}:\n\ttime: {}\n\tpid: {}\n\twl socket: {}\n\n", el.id, el.time, el.pid, el.wlSocket); } } else { result += '['; for (auto& el : inst) { - result += getFormat(R"#( -{ - "instance": "%s", - "time": %llu, - "pid": %llu, - "wl_socket": "%s" -},)#", - el.id.c_str(), el.time, el.pid, el.wlSocket.c_str()); + result += std::format(R"#( +{{ + "instance": "{}", + "time": {}, + "pid": {}, + "wl_socket": "{}" +}},)#", + el.id, el.time, el.pid, el.wlSocket); } result.pop_back(); |