commit 923830ab9a175c2d3ed2f67a4638c86d5f03ccb1
parent e7f47aec2ecc7be6936efce1e6db18d875eb8d73
Author: bit9tream <bit6tream@cock.li>
Date: Tue, 23 Jun 2020 01:36:39 +0300
add ability to output information in json
Diffstat:
3 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -41,6 +41,8 @@ Summary
Body
```
+also tiramisu can output information in json so it can be easily parsed.
+
If any specific setting is disabled in the configuration, the line is omitted
from the output (making all of the output one line shorter).
diff --git a/config.h b/config.h
@@ -2,4 +2,5 @@
// #define RECEIVE_APP_ICON
// #define RECEIVE_REPLACES_ID
// #define RECEIVE_EXPIRE_TIMEOUT
+#define PRINT_JSON
#define OUTPUT_DELIMITER "\n"
diff --git a/format.c b/format.c
@@ -11,6 +11,7 @@ void output_notification(gchar *app_name, guint32 replaces_id, gchar *app_icon,
/* 2048 characters should be significantly long enough*/
char *string = (char *)calloc(2048, sizeof(char));
+#ifndef PRINT_JSON
strcat(string, app_name);
#ifdef RECEIVE_APP_ICON
@@ -26,6 +27,20 @@ void output_notification(gchar *app_name, guint32 replaces_id, gchar *app_icon,
sprintf(string, "%s%s%d%s%s%s%s", string, OUTPUT_DELIMITER,
timeout, OUTPUT_DELIMITER, summary, OUTPUT_DELIMITER, body);
+#else
+ sprintf(string, "{ \"app_name\": \"%s\"", app_name);
+
+#ifdef RECEIVE_APP_ICON
+ sprintf(string, "%s, \"app_icon\": \"%s\"", string, app_icon);
+#endif
+
+#ifdef RECEIVE_REPLACES_ID
+ sprintf(string, "%s, \"replaces_id\": %lu", string, replaces_id);
+#endif
+
+ sprintf(string, "%s, \"timeout\": %d, \"summary\": \"%s\", \"body\": \"%s\" }", string, timeout, summary, body);
+
+#endif
printf("%s\n", string);
fflush(stdout);