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 diff --git a/config.c b/config.c index ce0e27b8..0e509995 100644 --- a/config.c +++ b/config.c @@ -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; diff --git a/config.h b/config.h index de5d8a7b..70e182e3 100644 --- a/config.h +++ b/config.h @@ -217,11 +217,25 @@ struct config { uint32_t bg; } 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_. diff --git a/foot.ini b/foot.ini index 10eb56e8..e8ff1870 100644 --- a/foot.ini +++ b/foot.ini @@ -104,9 +104,11 @@ ## Misc colors # selection-foreground= # selection-background= -# jump-labels= +# jump-labels= # black-on-yellow +# scrollback-indicator= # black-on-bright-blue +# search-box-no-match= # black-on-red +# search-box-match= # black-on-yellow # urls= -# scrollback-indicator= [csd] # preferred=server diff --git a/render.c b/render.c index 0dd251ae..9333deb7 100644 --- a/render.c +++ b/render.c @@ -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];