From e9c3d03837bb50ec39b85ee92f2906e2bb40971f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 6 Feb 2021 11:10:40 +0100 Subject: config: add colors.jump_labels and colors.urls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * colors.jump_labels configures the foreground and background colors used when rendering URL jump labels. Defaults to “regular0 regular3” (i.e. black on yellow). * colors.urls configures the color to use when highlighting URLs in URL mode. Note that we aren’t currently doing any highlighting... Defaults to regular3 (i.e. yellow). --- config.c | 68 +++++++++++++++++++++++++++++++++++++++++++----------- config.h | 8 +++++++ doc/foot.ini.5.scd | 9 ++++++++ foot.ini | 2 ++ render.c | 12 ++++++++-- 5 files changed, 84 insertions(+), 15 deletions(-) diff --git a/config.c b/config.c index 285bc889..f7452994 100644 --- a/config.c +++ b/config.c @@ -420,6 +420,30 @@ str_to_color(const char *s, uint32_t *color, bool allow_alpha, return true; } +static bool +str_to_two_colors(const char *s, uint32_t *first, uint32_t *second, + bool allow_alpha, struct config *conf, const char *path, + int lineno, const char *section, const char *key) +{ + /* TODO: do this without strdup() */ + char *value_copy = xstrdup(s); + const char *first_as_str = strtok(value_copy, " "); + const char *second_as_str = strtok(NULL, " "); + + if (first_as_str == NULL || second_as_str == NULL || + !str_to_color(first_as_str, first, allow_alpha, conf, path, lineno, section, key) || + !str_to_color(second_as_str, second, allow_alpha, conf, path, lineno, section, key)) + { + LOG_AND_NOTIFY_ERR("%s:%d: [%s]: %s: invalid colors: %s", + path, lineno, section, key, s); + free(value_copy); + return false; + } + + free(value_copy); + return true; +} + static bool str_to_pt_or_px(const char *s, struct pt_or_px *res, struct config *conf, const char *path, int lineno, const char *section, const char *key) @@ -845,6 +869,30 @@ parse_section_colors(const char *key, const char *value, struct config *conf, else if (strcmp(key, "bright7") == 0) color = &conf->colors.bright[7]; else if (strcmp(key, "selection-foreground") == 0) color = &conf->colors.selection_fg; else if (strcmp(key, "selection-background") == 0) color = &conf->colors.selection_bg; + + else if (strcmp(key, "jump-labels") == 0) { + if (!str_to_two_colors( + value, &conf->colors.jump_label.fg, &conf->colors.jump_label.bg, + false, conf, path, lineno, "colors", "jump-labels")) + { + return false; + } + + conf->colors.use_custom.jump_label = true; + return true; + } + + else if (strcmp(key, "urls") == 0) { + if (!str_to_color(value, &conf->colors.url, false, + conf, path, lineno, "colors", "urls")) + { + return false; + } + + conf->colors.use_custom.url = true; + return true; + } + else if (strcmp(key, "alpha") == 0) { double alpha; if (!str_to_double(value, &alpha) || alpha < 0. || alpha > 1.) { @@ -892,23 +940,15 @@ parse_section_cursor(const char *key, const char *value, struct config *conf, conf->cursor.blink = str_to_bool(value); else if (strcmp(key, "color") == 0) { - char *value_copy = xstrdup(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, false, conf, path, lineno, "cursor", "color") || - !str_to_color(cursor, &cursor_color, false, conf, path, lineno, "cursor", "color")) + if (!str_to_two_colors( + value, &conf->cursor.color.text, &conf->cursor.color.cursor, + false, conf, path, lineno, "cursor", "color")) { - LOG_AND_NOTIFY_ERR("%s:%d: invalid cursor colors: %s", path, lineno, value); - free(value_copy); return false; } - conf->cursor.color.text = 1u << 31 | text_color; - conf->cursor.color.cursor = 1u << 31 | cursor_color; - free(value_copy); + conf->cursor.color.text |= 1u << 31; + conf->cursor.color.cursor |= 1u << 31; } else { @@ -2283,6 +2323,8 @@ config_load(struct config *conf, const char *conf_path, .selection_bg = 0x80000000, /* Use default fg */ .use_custom = { .selection = false, + .jump_label = false, + .url = false, }, }, diff --git a/config.h b/config.h index f8ebb572..94998f28 100644 --- a/config.h +++ b/config.h @@ -139,9 +139,17 @@ struct config { uint16_t alpha; uint32_t selection_fg; uint32_t selection_bg; + uint32_t url; + + struct { + uint32_t fg; + uint32_t bg; + } jump_label; struct { bool selection:1; + bool jump_label:1; + bool url:1; } use_custom; } colors; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 727b81f1..3b913eda 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -351,6 +351,15 @@ _alpha_ option. text. Note that *both* options must be set, or the default will be used. Default: _inverse foreground/background_. +*jump-labels* + To RRGGBB values specifying the foreground (text) and background + colors to use when rendering jump labels in URL mode. Default: + _regular0 regular3_. + +*urls* + Color to use for the underline used to highlight URLs in URL + mode. Default: _regular3_. + # SECTION: csd diff --git a/foot.ini b/foot.ini index d90c0a06..8896eef0 100644 --- a/foot.ini +++ b/foot.ini @@ -66,6 +66,8 @@ # bright7=ffffff # bright white # selection-foreground= # selection-background= +# jump-labels= +# urls= [csd] # preferred=server diff --git a/render.c b/render.c index 8415ac81..040fa34a 100644 --- a/render.c +++ b/render.c @@ -2578,9 +2578,17 @@ render_urls(struct terminal *term) (term->margins.left + x) / term->scale, (term->margins.top + y) / term->scale); + uint32_t fg = term->conf->colors.use_custom.jump_label + ? term->conf->colors.jump_label.fg + : term->colors.table[0]; + uint32_t bg = term->conf->colors.use_custom.jump_label + ? term->conf->colors.jump_label.bg + : term->colors.table[3]; + + uint16_t alpha = 0xffff; + render_osd(term, surf, sub_surf, buf, label, - term->colors.table[0], term->colors.table[3], 0xf000, - width, height, margin, margin); + fg, bg, alpha, width, height, margin, margin); } } -- cgit v1.3