From 034f33bc41ea5503705843f4ce991e9a0527e9d3 Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Wed, 13 Oct 2021 21:28:49 +0530 Subject: [PATCH] Add TRAILING_DELIMITER option --- README.md | 3 +++ config.h | 3 ++- main.c | 16 +++++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 40b3aac..4c043f2 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,9 @@ Apart from that you can also modify the block delimiters and width of each block #define CMDLENGTH 50 #define DELIMITER " " + +// Adds a trailing delimiter to the statusbar, useful for powerline +#define TRAILING_DELIMITER ``` ### Signalling changes diff --git a/config.h b/config.h index 4153296..c2fbd92 100644 --- a/config.h +++ b/config.h @@ -1,8 +1,9 @@ #define CMDLENGTH 50 #define DELIMITER "<" +#define TRAILING_DELIMITER const Block blocks[] = { - BLOCK("sb-mail", 1800, 17) + BLOCK("sb-mail", 1800, 17) BLOCK("sb-music", 0, 18) BLOCK("sb-disk", 1800, 19) BLOCK("sb-memory", 1800, 20) diff --git a/main.c b/main.c index bc2dae5..62cfb12 100644 --- a/main.c +++ b/main.c @@ -45,14 +45,13 @@ void replace(char *str, char old, char new) { } void getCommand(int i, const char *button) { - const Block *block = blocks + i; if (fork() == 0) { dup2(pipeFD[1], STDOUT_FILENO); close(pipeFD[0]); if (button) setenv("BLOCK_BUTTON", button, 1); - execl("/bin/sh", "sh", "-c", block->command); + execl("/bin/sh", "sh", "-c", blocks[i].command); } } @@ -71,9 +70,13 @@ void getSignalCommand(int signal) { int getStatus(char *new, char *old) { strcpy(old, new); new[0] = 0; + for (int i = 0; i < LEN(blocks); i++) { - const Block *block = blocks + i; - if (strlen(outputs[i]) > (block->signal > 0)) + #ifdef TRAILING_DELIMITER + if (strlen(outputs[i]) > (blocks[i].signal > 0)) + #else + if (strlen(new) && strlen(outputs[i]) > (blocks[i].signal > 0)) + #endif strcat(new, DELIMITER); strcat(new, outputs[i]); } @@ -133,10 +136,9 @@ void childHandler() { // Clear the pipe until newline while (ch != '\n' && read(pipeFD[0], &ch, 1) == 1); - const Block *block = blocks + i; char *output = outputs[i]; - if (block->signal > 0) { - output[0] = block->signal; + if (blocks[i].signal > 0) { + output[0] = blocks[i].signal; output++; } strcpy(output, buffer);