From e8b9569ca7a6261af81ccca237e6f19d3e22a35a Mon Sep 17 00:00:00 2001 From: domsson Date: Thu, 5 Nov 2020 06:00:50 +0900 Subject: [PATCH] Added 'separator' option, which solves issue #49 --- README.md | 9 +++++++++ src/loadini.c | 5 +++++ src/succade.c | 25 ++++++++++++++++++++++--- src/succade.h | 3 ++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 58cead2..1a0b801 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ The config needs to have one section for lemonbar (`bar`) and one per block, plu - [`inih`](https://github.com/benhoyt/inih) (`libinih-dev` in Debian, but also included in this repo, see below) +# Portability + +succade uses [libkita](https://github.com/domsson/libkita) to manage child processes. libkita uses `epoll`, which is Linux only. I've attempted to port libkita to BSD using `kqueue`, but couldn't get it to work reliably (yet). + # Installation Make sure you have `lemonbar` (obviously), `gcc` (for compiling the source code) and all dependencies, as listed above, installed. If `inih` is not available in your distribution, just replace `./build` with `./build-inih` below and you should be good to go. @@ -86,6 +90,7 @@ The special section `bar` configures Lemonbar itself and can define common forma | `affix-font` | string | Font to use for all block's prefixes / suffixes, if any. | | `line-color` | color | Color for all underlines / overlines, if any. | | `line-width` | number | Thickness of all underlines / overlines, if any, in pixels. | +| `separator` | string | String to place in between any two blocks of the same alignment. | ## blocks @@ -146,6 +151,10 @@ Options: Looking for scripts, programs or code that can fetch information to display on your bar? Check out [fetch-all-the-things](https://github.com/domsson/fetch-all-the-things). +# License + +succade is public domain software, do with it whatever you want. However, succade uses [`inih`](https://github.com/benhoyt/inih), which is under the New BSD license. + # Motivation With projects like [polybar](https://github.com/polybar/polybar), the question for the relevance of succade is justified. Personally, I prefer succade - and similar solutions, like [Captain](https://github.com/muse/Captain) - because they enforce the separation of concerns as described by the [UNIX philosophy](https://en.wikipedia.org/wiki/Unix_philosophy). diff --git a/src/loadini.c b/src/loadini.c index e8d5d6d..ed9ec18 100644 --- a/src/loadini.c +++ b/src/loadini.c @@ -40,6 +40,11 @@ int lemon_ini_handler(void *data, const char *section, const char *name, const c cfg_set_int(lc, LEMON_OPT_LW, atoi(value)); return 1; } + if (equals(name, "separator")) + { + cfg_set_str(lc, LEMON_OPT_SEPARATOR, is_quoted(value) ? unquote(value) : strdup(value)); + return 1; + } if (equals(name, "height") || equals(name, "h")) { cfg_set_int(lc, LEMON_OPT_HEIGHT, atoi(value)); diff --git a/src/succade.c b/src/succade.c index 5dd6e7e..759330d 100644 --- a/src/succade.c +++ b/src/succade.c @@ -483,9 +483,13 @@ static char *barstr(const state_s *state) return NULL; } - // For convenience... + // For convenience size_t num_blocks = state->num_blocks; + // String to place in between any two blocks + char *sep = cfg_get_str(&state->lemon.cfg, LEMON_OPT_SEPARATOR); + size_t sep_len = sep ? strlen(sep) : 0; + // Short blocks like temperature, volume or battery, will usually use // something in the range of 130 to 200 byte. So let's go with 256 byte. size_t bar_str_len = BUFFER_BLOCK_RESULT * num_blocks; @@ -507,25 +511,40 @@ static char *barstr(const state_s *state) continue; } + // Figure out the alignment of this block int block_align = cfg_get_int(&block->cfg, BLOCK_OPT_ALIGN); + int same_align = block_align == last_align; + // Build the block string int block_str_len = blockstr(block, block_str, BUFFER_BLOCK_STR); - if (block_align != last_align) + + // Potentially change the alignment + if (!same_align) { last_align = block_align; snprintf(align, 5, "%%{%c}", get_align(last_align)); strcat(bar_str, align); } + // Let's check if this block string can fit in our buffer - size_t free_len = bar_str_len - (strlen(bar_str) + 1); + size_t free_len = bar_str_len - (strlen(bar_str) + sep_len + 1); if (block_str_len > free_len) { // Let's make space for approx. two more blocks bar_str_len += BUFFER_BLOCK_RESULT * 2; bar_str = realloc(bar_str, bar_str_len); } + + // Possibly add the block separator in front of the block + if (sep && same_align && i) + { + strcat(bar_str, sep); + } + + // Add this block's result to the bar string strcat(bar_str, block_str); } + strcat(bar_str, "\n"); bar_str = realloc(bar_str, strlen(bar_str) + 1); return bar_str; diff --git a/src/succade.h b/src/succade.h index 7cd7420..3a60549 100644 --- a/src/succade.h +++ b/src/succade.h @@ -9,7 +9,7 @@ #define SUCCADE_NAME "succade" #define SUCCADE_URL "https://github.com/domsson/succade" #define SUCCADE_VER_MAJOR 2 -#define SUCCADE_VER_MINOR 0 +#define SUCCADE_VER_MINOR 1 #define SUCCADE_VER_PATCH 1 #define BUFFER_NUMERIC 8 @@ -81,6 +81,7 @@ enum succade_lemon_opt LEMON_OPT_BG, // -B: default background color LEMON_OPT_FG, // -F: default foreground color LEMON_OPT_LC, // -U: underline color + LEMON_OPT_SEPARATOR, // string to separate blocks with LEMON_OPT_COUNT };