aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Ivanov <nikita.vyach.ivanov@gmail.com>2023-05-26 20:31:16 +0200
committerNikita Ivanov <nikita.vyach.ivanov@gmail.com>2023-07-21 18:40:04 +0200
commit04a218fb4ece3cc4d45d9b06e25d4a5847c4a950 (patch)
tree0742b651d3a6a9d692346ceadf0d2713a8cd1c6e
parent58bb8ad713a0d7314198e75de847153ba783c5f7 (diff)
downloaddwlb-04a218fb4ece3cc4d45d9b06e25d4a5847c4a950.tar.gz
Add -status-stdin command
-rw-r--r--README.md2
-rw-r--r--dwlb.c15
2 files changed, 15 insertions, 2 deletions
diff --git a/README.md b/README.md
index 8335cfc..40fabdf 100644
--- a/README.md
+++ b/README.md
@@ -64,7 +64,7 @@ Run `dwlb -h` for a full list of options.
## Someblocks
To use someblocks, or any program that outputs to stdout, with dwlb, use this one-liner:
```bash
-someblocks -p | while read -r line; do dwlb -status all "$line"; done
+someblocks -p | dwlb -status-stdin all
```
## Acknowledgements
diff --git a/dwlb.c b/dwlb.c
index 3d59236..312befe 100644
--- a/dwlb.c
+++ b/dwlb.c
@@ -96,6 +96,7 @@
" -scale [BUFFER_SCALE] specify buffer scale value for integer scaling\n" \
"Commands\n" \
" -status [OUTPUT] [TEXT] set status text\n" \
+ " -status-stdin [OUTPUT] set status text from stdin\n" \
" -title [OUTPUT] [TEXT] set title text, if -custom-title is enabled\n" \
" -show [OUTPUT] show bar\n" \
" -hide [OUTPUT] hide bar\n" \
@@ -107,6 +108,8 @@
" -v get version information\n" \
" -h view this help text\n"
+#define TEXT_MAX 2048
+
typedef struct {
pixman_color_t color;
bool bg;
@@ -121,7 +124,7 @@ typedef struct {
} Button;
typedef struct {
- char text[2048];
+ char text[TEXT_MAX];
Color *colors;
uint32_t colors_l, colors_c;
Button *buttons;
@@ -1578,6 +1581,16 @@ main(int argc, char **argv)
DIE("Option -status requires two arguments");
client_send_command(&sock_address, argv[i], "status", argv[i + 1]);
return 0;
+ } else if (!strcmp(argv[i], "-status-stdin")) {
+ if (++i >= argc)
+ DIE("Option -status-stdin requires an argument");
+ char *status = malloc(TEXT_MAX * sizeof(char));
+ while (fgets(status, TEXT_MAX-1, stdin)) {
+ status[strlen(status)-1] = '\0';
+ client_send_command(&sock_address, argv[i], "status", status);
+ }
+ free(status);
+ return 0;
} else if (!strcmp(argv[i], "-title")) {
if (++i + 1 >= argc)
DIE("Option -title requires two arguments");