Add -status-stdin command

This commit is contained in:
Nikita Ivanov 2023-05-26 20:31:16 +02:00
parent 58bb8ad713
commit 04a218fb4e
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
2 changed files with 15 additions and 2 deletions

View File

@ -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

15
dwlb.c
View File

@ -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");