add separator and separator_block_width as universal module options

fixes #104
This commit is contained in:
johannes karoff 2016-01-31 19:16:42 +01:00
parent 85329802b2
commit 6f4819f7a5
3 changed files with 79 additions and 26 deletions

View File

@ -53,6 +53,12 @@
#define CFG_CUSTOM_MIN_WIDTH_OPT \
CFG_PTR_CB("min_width", NULL, CFGF_NONE, parse_min_width, free)
#define CFG_CUSTOM_SEPARATOR_OPT \
CFG_BOOL("separator", 0, CFGF_NODEFAULT)
#define CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT \
CFG_INT("separator_block_width", 0, CFGF_NODEFAULT)
/* socket file descriptor for general purposes */
int general_socket;
@ -304,6 +310,8 @@ int main(int argc, char *argv[]) {
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_COLOR_OPTS,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t path_exists_opts[] = {
@ -313,6 +321,8 @@ int main(int argc, char *argv[]) {
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_COLOR_OPTS,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t wireless_opts[] = {
@ -321,6 +331,8 @@ int main(int argc, char *argv[]) {
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_COLOR_OPTS,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t ethernet_opts[] = {
@ -329,6 +341,8 @@ int main(int argc, char *argv[]) {
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_COLOR_OPTS,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t ipv6_opts[] = {
@ -337,6 +351,8 @@ int main(int argc, char *argv[]) {
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_COLOR_OPTS,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t battery_opts[] = {
@ -354,12 +370,16 @@ int main(int argc, char *argv[]) {
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_COLOR_OPTS,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t time_opts[] = {
CFG_STR("format", "%Y-%m-%d %H:%M:%S", CFGF_NONE),
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t tztime_opts[] = {
@ -368,12 +388,16 @@ int main(int argc, char *argv[]) {
CFG_STR("format_time", NULL, CFGF_NONE),
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t ddate_opts[] = {
CFG_STR("format", "%{%a, %b %d%}, %Y%N - %H", CFGF_NONE),
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t load_opts[] = {
@ -382,12 +406,16 @@ int main(int argc, char *argv[]) {
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_COLOR_OPTS,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t usage_opts[] = {
CFG_STR("format", "%usage", CFGF_NONE),
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t temp_opts[] = {
@ -397,6 +425,8 @@ int main(int argc, char *argv[]) {
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_COLOR_OPTS,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t disk_opts[] = {
@ -408,6 +438,8 @@ int main(int argc, char *argv[]) {
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_COLOR_OPTS,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t volume_opts[] = {
@ -419,6 +451,8 @@ int main(int argc, char *argv[]) {
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_COLOR_OPTS,
CFG_CUSTOM_MIN_WIDTH_OPT,
CFG_CUSTOM_SEPARATOR_OPT,
CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
CFG_END()};
cfg_opt_t opts[] = {

View File

@ -100,32 +100,40 @@ char *pct_mark;
} \
} while (0)
#define SEC_CLOSE_MAP \
do { \
if (output_format == O_I3BAR) { \
char *_align = cfg_getstr(sec, "align"); \
if (_align) { \
yajl_gen_string(json_gen, (const unsigned char *) "align", strlen("align")); \
yajl_gen_string(json_gen, (const unsigned char *)_align, strlen(_align)); \
} \
struct min_width *_width = cfg_getptr(sec, "min_width"); \
if (_width) { \
/* if the value can be parsed as a number, we use the numerical value */ \
if (_width->num > 0) { \
yajl_gen_string(json_gen, (const unsigned char *) "min_width", strlen("min_width")); \
yajl_gen_integer(json_gen, _width->num); \
} else { \
yajl_gen_string(json_gen, (const unsigned char *) "min_width", strlen("min_width")); \
yajl_gen_string(json_gen, (const unsigned char *)_width->str, strlen(_width->str)); \
} \
} \
const char *_sep = cfg_getstr(cfg_general, "separator"); \
if (strlen(_sep) == 0) { \
yajl_gen_string(json_gen, (const unsigned char *) "separator", strlen("separator")); \
yajl_gen_bool(json_gen, false); \
} \
yajl_gen_map_close(json_gen); \
} \
#define SEC_CLOSE_MAP \
do { \
if (output_format == O_I3BAR) { \
char *_align = cfg_getstr(sec, "align"); \
if (_align) { \
yajl_gen_string(json_gen, (const unsigned char *) "align", strlen("align")); \
yajl_gen_string(json_gen, (const unsigned char *)_align, strlen(_align)); \
} \
struct min_width *_width = cfg_getptr(sec, "min_width"); \
if (_width) { \
/* if the value can be parsed as a number, we use the numerical value */ \
if (_width->num > 0) { \
yajl_gen_string(json_gen, (const unsigned char *) "min_width", strlen("min_width")); \
yajl_gen_integer(json_gen, _width->num); \
} else { \
yajl_gen_string(json_gen, (const unsigned char *) "min_width", strlen("min_width")); \
yajl_gen_string(json_gen, (const unsigned char *)_width->str, strlen(_width->str)); \
} \
} \
if (cfg_size(sec, "separator") > 0) { \
yajl_gen_string(json_gen, (const unsigned char *) "separator", strlen("separator")); \
yajl_gen_bool(json_gen, cfg_getbool(sec, "separator")); \
} \
if (cfg_size(sec, "separator_block_width") > 0) { \
yajl_gen_string(json_gen, (const unsigned char *) "separator_block_width", strlen("separator_block_width")); \
yajl_gen_integer(json_gen, cfg_getint(sec, "separator_block_width")); \
} \
const char *_sep = cfg_getstr(cfg_general, "separator"); \
if (strlen(_sep) == 0) { \
yajl_gen_string(json_gen, (const unsigned char *) "separator", strlen("separator")); \
yajl_gen_bool(json_gen, false); \
} \
yajl_gen_map_close(json_gen); \
} \
} while (0)
#define START_COLOR(colorstr) \

View File

@ -513,6 +513,15 @@ min_width::
set a sensible minimum width regardless of which font you are using, and at
what particular size. Please note that a number enclosed with quotes will
still be treated as a number.
separator::
A boolean value which specifies whether a separator line should be drawn
after this block. The default is true, meaning the separator line will be
drawn. Note that if you disable the separator line, there will still be a
gap after the block, unless you also use separator_block_width.
separator_block_width::
The amount of pixels to leave blank after the block. In the middle of this
gap, a separator symbol will be drawn unless separator is disabled. This is
why the specified width should leave enough space for the separator symbol.
*Example configuration*:
-------------------------------------------------------------
@ -520,6 +529,8 @@ disk "/" {
format = "%avail"
align = "left"
min_width = 100
separator = false
separator_block_width = 1
}
-------------------------------------------------------------