diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-07-23 16:54:58 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-07-23 16:54:58 +0000 |
| commit | bf4847d3e028516b0de446e8455d43833983c17b (patch) | |
| tree | 0b3dfa5627bffec22e87db85928aef7c6a59c14e /config.c | |
| parent | csi: ignore CSI ?1036h/l (metaSendsEscape) (diff) | |
conf: allow the user to configure a fixed cursor color
The default is to reverse the foreground/background colors in the cell
with the cursor.
But, if the user configures a specific set of cursor colors, those
will always be used, regardless of other cell attributes (dim, reverse
etc).
The cursor color is specified as two color values, 'text' and
'cursor'.
The block cursor uses the 'cursor' color as background, and the 'text'
color for the glyph.
All other cursor styles uses the 'cursor' color for the cursor, but
uses the cell's foreground color for the glyph (meaning,
dim/reverse/etc applies).
Diffstat (limited to 'config.c')
| -rw-r--r-- | config.c | 64 |
1 files changed, 51 insertions, 13 deletions
@@ -107,6 +107,30 @@ get_config_path(void) } static bool +str_to_color(const char *s, uint32_t *color, const char *path, int lineno) +{ + if (s == NULL) + return false; + + errno = 0; + char *end = NULL; + unsigned long res = strtoul(s, &end, 16); + + if (errno != 0) { + LOG_ERRNO("%s:%d: invalid color: %s", path, lineno, s); + return false; + } + + if (*end != '\0') { + LOG_ERR("%s:%d: invalid color: %s", path, lineno, s); + return false; + } + + *color = res & 0xffffff; + return true; +} + +static bool parse_section_main(const char *key, const char *value, struct config *conf, const char *path, unsigned lineno) { @@ -163,21 +187,11 @@ parse_section_colors(const char *key, const char *value, struct config *conf, return false; } - errno = 0; - char *end = NULL; - unsigned long res = strtoul(value, &end, 16); - - if (errno != 0) { - LOG_ERRNO("%s:%d: invalid color: %s", path, lineno, value); + uint32_t color_value; + if (!str_to_color(value, &color_value, path, lineno)) return false; - } - - if (*end != '\0') { - LOG_ERR("%s:%d: invalid color: %s", path, lineno, value); - return false; - } - *color = res & 0xffffff; + *color = color_value; return true; } @@ -199,6 +213,26 @@ parse_section_cursor(const char *key, const char *value, struct config *conf, } } + else if (strcmp(key, "color") == 0) { + char *value_copy = strdup(value); + const char *text = strtok(value_copy, " "); + const char *cursor = strtok(NULL, " "); + + uint32_t text_color, cursor_color; + if (text == NULL || cursor == NULL || + !str_to_color(text, &text_color, path, lineno) || + !str_to_color(cursor, &cursor_color, path, lineno)) + { + LOG_ERR("%s:%d: invalid cursor colors: %s", path, lineno, value); + free(value_copy); + return false; + } + + conf->cursor.color.text = 1 << 31 | text_color; + conf->cursor.color.cursor = 1 << 31 | cursor_color; + free(value_copy); + } + else { LOG_ERR("%s:%d: invalid key: %s", path, lineno, key); return false; @@ -388,6 +422,10 @@ config_load(struct config *conf) .cursor = { .style = CURSOR_BLOCK, + .color = { + .text = 0, + .cursor = 0, + }, }, }; |
