summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/menu.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2023-08-15 07:01:48 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2023-08-15 07:01:48 +0000
commit37ad523ca35c5f68438e38f7f0cc34cd9d576a94 (patch)
tree867e49f5d5624b6829f14696700246655e22e6a4 /usr.bin/tmux/menu.c
parentc3afb56359011bcb089e92c3ecf863467c31e5fe (diff)
Add an option menu-selected-style to configure the currently selected
menu item, from Alexis Hildebrandt.
Diffstat (limited to 'usr.bin/tmux/menu.c')
-rw-r--r--usr.bin/tmux/menu.c64
1 files changed, 33 insertions, 31 deletions
diff --git a/usr.bin/tmux/menu.c b/usr.bin/tmux/menu.c
index 4b0622020e7..79ad009ffdc 100644
--- a/usr.bin/tmux/menu.c
+++ b/usr.bin/tmux/menu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: menu.c,v 1.51 2023/08/08 08:08:47 nicm Exp $ */
+/* $OpenBSD: menu.c,v 1.52 2023/08/15 07:01:47 nicm Exp $ */
/*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -29,6 +29,7 @@ struct menu_data {
struct grid_cell style;
struct grid_cell border_style;
+ struct grid_cell selected_style;
enum box_lines border_lines;
struct cmd_find_state fs;
@@ -201,7 +202,6 @@ menu_draw_cb(struct client *c, void *data,
struct menu *menu = md->menu;
struct screen_write_ctx ctx;
u_int i, px = md->px, py = md->py;
- struct grid_cell gc;
screen_write_start(&ctx, s);
screen_write_clearscreen(&ctx, 8);
@@ -210,10 +210,9 @@ menu_draw_cb(struct client *c, void *data,
screen_write_box(&ctx, menu->width + 4, menu->count + 2,
md->border_lines, &md->border_style, menu->title);
}
- style_apply(&gc, c->session->curw->window->options, "mode-style", NULL);
screen_write_menu(&ctx, menu, md->choice, md->border_lines,
- &md->style, &md->border_style, &gc);
+ &md->style, &md->border_style, &md->selected_style);
screen_write_stop(&ctx);
for (i = 0; i < screen_size_y(&md->s); i++) {
@@ -438,16 +437,35 @@ chosen:
return (1);
}
+static void
+menu_set_style(struct client *c, struct grid_cell *gc, const char *style,
+ const char *option)
+{
+ struct style sytmp;
+ struct options *o = c->session->curw->window->options;
+
+ memcpy(gc, &grid_default_cell, sizeof *gc);
+ style_apply(gc, o, option, NULL);
+ if (style != NULL) {
+ style_set(&sytmp, &grid_default_cell);
+ if (style_parse(&sytmp, gc, style) == 0) {
+ gc->fg = sytmp.gc.fg;
+ gc->bg = sytmp.gc.bg;
+ }
+ }
+ gc->attr = 0;
+}
+
struct menu_data *
menu_prepare(struct menu *menu, int flags, int starting_choice,
struct cmdq_item *item, u_int px, u_int py, struct client *c,
- enum box_lines lines, const char *style, const char *border_style,
- struct cmd_find_state *fs, menu_choice_cb cb, void *data)
+ enum box_lines lines, const char *style, const char *selected_style,
+ const char *border_style, struct cmd_find_state *fs, menu_choice_cb cb,
+ void *data)
{
struct menu_data *md;
int choice;
const char *name;
- struct style sytmp;
struct options *o = c->session->curw->window->options;
if (c->tty.sx < menu->width + 4 || c->tty.sy < menu->count + 2)
@@ -465,27 +483,10 @@ menu_prepare(struct menu *menu, int flags, int starting_choice,
md->flags = flags;
md->border_lines = lines;
- memcpy(&md->style, &grid_default_cell, sizeof md->style);
- style_apply(&md->style, o, "menu-style", NULL);
- if (style != NULL) {
- style_set(&sytmp, &grid_default_cell);
- if (style_parse(&sytmp, &md->style, style) == 0) {
- md->style.fg = sytmp.gc.fg;
- md->style.bg = sytmp.gc.bg;
- }
- }
- md->style.attr = 0;
-
- memcpy(&md->border_style, &grid_default_cell, sizeof md->border_style);
- style_apply(&md->border_style, o, "menu-border-style", NULL);
- if (border_style != NULL) {
- style_set(&sytmp, &grid_default_cell);
- if (style_parse(&sytmp, &md->border_style, border_style) == 0) {
- md->border_style.fg = sytmp.gc.fg;
- md->border_style.bg = sytmp.gc.bg;
- }
- }
- md->border_style.attr = 0;
+ menu_set_style(c, &md->style, style, "menu-style");
+ menu_set_style(c, &md->selected_style, selected_style,
+ "menu-selected-style");
+ menu_set_style(c, &md->border_style, border_style, "menu-border-style");
if (fs != NULL)
cmd_find_copy_state(&md->fs, fs);
@@ -539,13 +540,14 @@ menu_prepare(struct menu *menu, int flags, int starting_choice,
int
menu_display(struct menu *menu, int flags, int starting_choice,
struct cmdq_item *item, u_int px, u_int py, struct client *c,
- enum box_lines lines, const char *style, const char *border_style,
- struct cmd_find_state *fs, menu_choice_cb cb, void *data)
+ enum box_lines lines, const char *style, const char *selected_style,
+ const char *border_style, struct cmd_find_state *fs, menu_choice_cb cb,
+ void *data)
{
struct menu_data *md;
md = menu_prepare(menu, flags, starting_choice, item, px, py, c, lines,
- style, border_style, fs, cb, data);
+ style, selected_style, border_style, fs, cb, data);
if (md == NULL)
return (-1);
server_client_set_overlay(c, 0, NULL, menu_mode_cb, menu_draw_cb,