diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2022-07-27 17:14:27 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2022-07-28 17:02:56 +0000 |
| commit | d79a3b9350ba864464229a1c188e2f696fac5a26 (patch) | |
| tree | fec4b0cc07164d74ab66b6230f52b522df610057 | |
| parent | test: config: test colors.{jump-labels,scrollback-indicator} (diff) | |
config: add colors.search-box-{no-,}match
Closes #1112
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | config.c | 28 | ||||
| -rw-r--r-- | config.h | 14 | ||||
| -rw-r--r-- | doc/foot.ini.5.scd | 10 | ||||
| -rw-r--r-- | foot.ini | 6 | ||||
| -rw-r--r-- | render.c | 25 | ||||
| -rw-r--r-- | tests/test-config.c | 6 |
7 files changed, 85 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 29eaf084..55961c88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,10 +50,13 @@ * Support for jumping to previous/next prompt (requires shell integration). By default bound to `ctrl`+`shift`+`z` and `ctrl`+`shift`+`x` respectively ([#30][30]). +* `colors.search-box-no-match` and `colors.search-box-match` options + to `foot.ini` ([#1112][1112]). [1058]: https://codeberg.org/dnkl/foot/issues/1058 [1070]: https://codeberg.org/dnkl/foot/issues/1070 [30]: https://codeberg.org/dnkl/foot/issues/30 +[1112]: https://codeberg.org/dnkl/foot/issues/1112 ### Changed @@ -1171,6 +1171,34 @@ parse_section_colors(struct context *ctx) return true; } + else if (strcmp(key, "search-box-no-match") == 0) { + if (!value_to_two_colors( + ctx, + &conf->colors.search_box.no_match.fg, + &conf->colors.search_box.no_match.bg, + false)) + { + return false; + } + + conf->colors.use_custom.search_box_no_match = true; + return true; + } + + else if (strcmp(key, "search-box-match") == 0) { + if (!value_to_two_colors( + ctx, + &conf->colors.search_box.match.fg, + &conf->colors.search_box.match.bg, + false)) + { + return false; + } + + conf->colors.use_custom.search_box_match = true; + return true; + } + else if (strcmp(key, "urls") == 0) { if (!value_to_color(ctx, &conf->colors.url, false)) return false; @@ -218,10 +218,24 @@ struct config { } scrollback_indicator; struct { + struct { + uint32_t fg; + uint32_t bg; + } no_match; + + struct { + uint32_t fg; + uint32_t bg; + } match; + } search_box; + + struct { bool selection:1; bool jump_label:1; bool scrollback_indicator:1; bool url:1; + bool search_box_no_match:1; + bool search_box_match:1; uint8_t dim; } use_custom; } colors; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index bd551442..2e62a41f 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -566,6 +566,16 @@ can configure the background transparency with the _alpha_ option. (indicator itself) colors for the scrollback indicator. Default: _regular0 bright4_. +*search-box-no-match* + Two color values specifying the foreground (text) and background + colors for the scrollback search box, when there are no + matches. Default: _regular0 regular1_. + +*search-box-match* + Two color values specifying the foreground (text) and background + colors for the scrollback search box, when the search box is + either empty, or there are matches. Default: _regular0 regular3_. + *urls* Color to use for the underline used to highlight URLs in URL mode. Default: _regular3_. @@ -104,9 +104,11 @@ ## Misc colors # selection-foreground=<inverse foreground/background> # selection-background=<inverse foreground/background> -# jump-labels=<regular0> <regular3> +# jump-labels=<regular0> <regular3> # black-on-yellow +# scrollback-indicator=<regular0> <bright4> # black-on-bright-blue +# search-box-no-match=<regular0> <regular1> # black-on-red +# search-box-match=<regular0> <regular3> # black-on-yellow # urls=<regular3> -# scrollback-indicator=<regular0> <bright4> [csd] # preferred=server @@ -3046,10 +3046,20 @@ render_search_box(struct terminal *term) #define WINDOW_X(x) (margin + x) #define WINDOW_Y(y) (term->height - margin - height + y) - /* Background - yellow on empty/match, red on mismatch */ - pixman_color_t color = color_hex_to_pixman( - term->search.match_len == text_len - ? term->colors.table[3] : term->colors.table[1]); + const bool is_match = term->search.match_len == text_len; + const bool custom_colors = is_match + ? term->conf->colors.use_custom.search_box_match + : term->conf->colors.use_custom.search_box_no_match; + + /* Background - yellow on empty/match, red on mismatch (default) */ + const pixman_color_t color = color_hex_to_pixman( + is_match + ? (custom_colors + ? term->conf->colors.search_box.match.bg + : term->colors.table[3]) + : (custom_colors + ? term->conf->colors.search_box.no_match.bg + : term->colors.table[1])); pixman_image_fill_rectangles( PIXMAN_OP_SRC, buf->pix[0], &color, @@ -3065,7 +3075,12 @@ render_search_box(struct terminal *term) const int x_ofs = term->font_x_ofs; int x = x_left; int y = margin; - pixman_color_t fg = color_hex_to_pixman(term->colors.table[0]); + pixman_color_t fg = color_hex_to_pixman( + custom_colors + ? (is_match + ? term->conf->colors.search_box.match.fg + : term->conf->colors.search_box.no_match.fg) + : term->colors.table[0]); /* Move offset we start rendering at, to ensure the cursor is visible */ for (size_t i = 0, cell_idx = 0; i <= term->search.cursor; cell_idx += widths[i], i++) { diff --git a/tests/test-config.c b/tests/test-config.c index 5a7cda63..930be6bf 100644 --- a/tests/test-config.c +++ b/tests/test-config.c @@ -668,6 +668,12 @@ test_section_colors(void) test_two_colors(&ctx, &parse_section_colors, "scrollback-indicator", false, &conf.colors.scrollback_indicator.fg, &conf.colors.scrollback_indicator.bg); + test_two_colors(&ctx, &parse_section_colors, "search-box-no-match", false, + &conf.colors.search_box.no_match.fg, + &conf.colors.search_box.no_match.bg); + test_two_colors(&ctx, &parse_section_colors, "search-box-match", false, + &conf.colors.search_box.match.fg, + &conf.colors.search_box.match.bg); for (size_t i = 0; i < 255; i++) { char key_name[4]; |
