config: add colors.search-box-{no-,}match

Closes #1112
This commit is contained in:
Daniel Eklöf 2022-07-27 19:14:27 +02:00
parent 4873004c37
commit d79a3b9350
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 85 additions and 7 deletions

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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_.

View file

@ -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

View file

@ -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++) {

View file

@ -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];