Skip to content

Commit

Permalink
Added 'separator' option, which solves issue #49
Browse files Browse the repository at this point in the history
  • Loading branch information
domsson committed Nov 4, 2020
1 parent 93b3a15 commit e8b9569
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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).
Expand Down
5 changes: 5 additions & 0 deletions src/loadini.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
25 changes: 22 additions & 3 deletions src/succade.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/succade.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
};

Expand Down

0 comments on commit e8b9569

Please sign in to comment.