aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2016-08-02 14:52:41 -0400
committerGitHub <noreply@github.com>2016-08-02 14:52:41 -0400
commit506be24b62a43c03766ec426fae4da58adc2e0e7 (patch)
treecfb0a49aadc67dbe306a349dc6324c8d00bb26e8
parentc7d12faefc6a1f07cb41696e73e74ca87958bcf9 (diff)
parent6535da7bdeb8e4bf36de89bf861d20d22ffe5efa (diff)
Merge pull request #810 from acrisci/feature/swaymsg-pretty
swaymsg: pretty print ipc response
-rw-r--r--swaymsg/CMakeLists.txt3
-rw-r--r--swaymsg/main.c16
2 files changed, 16 insertions, 3 deletions
diff --git a/swaymsg/CMakeLists.txt b/swaymsg/CMakeLists.txt
index 06939991..a4989b9c 100644
--- a/swaymsg/CMakeLists.txt
+++ b/swaymsg/CMakeLists.txt
@@ -4,7 +4,8 @@ add_executable(swaymsg
target_link_libraries(swaymsg
sway-common
- )
+ ${JSONC_LIBRARIES}
+)
install(
TARGETS swaymsg
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 88a8fab0..29e80f02 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -6,6 +6,7 @@
#include <sys/un.h>
#include <sys/socket.h>
#include <unistd.h>
+#include <json-c/json.h>
#include "stringop.h"
#include "ipc-client.h"
#include "readline.h"
@@ -109,16 +110,27 @@ int main(int argc, char **argv) {
command = join_args(argv + optind, argc - optind);
}
+ int ret = 0;
int socketfd = ipc_open_socket(socket_path);
uint32_t len = strlen(command);
char *resp = ipc_single_command(socketfd, type, command, &len);
if (!quiet) {
- printf("%s\n", resp);
+ // pretty print the json
+ json_object *obj = json_tokener_parse(resp);
+
+ if (obj == NULL) {
+ fprintf(stderr, "ERROR: Could not parse json response from ipc. This is a bug in sway.");
+ printf("%s\n", resp);
+ ret = 1;
+ } else {
+ printf("%s\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
+ free(obj);
+ }
}
close(socketfd);
free(command);
free(resp);
free(socket_path);
- return 0;
+ return ret;
}