summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2020-04-15 16:11:23 +0000
committernicm <nicm>2020-04-15 16:11:23 +0000
commit1e72f5ea4356a102e12c0b5325d4af824899d39c (patch)
tree34420459415756a4ca1127fa9064a8b32df53330
parentc7883d5c872a56c5342092f81e87e0742713b4de (diff)
Use mode-style for selected items, like choose modes. GitHub issue 2166.
-rw-r--r--menu.c6
-rw-r--r--screen-write.c25
-rw-r--r--tmux.h3
3 files changed, 20 insertions, 14 deletions
diff --git a/menu.c b/menu.c
index 78369218..941d4123 100644
--- a/menu.c
+++ b/menu.c
@@ -149,10 +149,14 @@ menu_draw_cb(struct client *c, __unused struct screen_redraw_ctx *ctx0)
struct menu *menu = md->menu;
struct screen_write_ctx ctx;
u_int i, px = md->px, py = md->py;
+ struct grid_cell gc;
+
+ memcpy(&gc, &grid_default_cell, sizeof gc);
+ style_apply(&gc, c->session->curw->window->options, "mode-style");
screen_write_start(&ctx, NULL, s);
screen_write_clearscreen(&ctx, 8);
- screen_write_menu(&ctx, menu, md->choice);
+ screen_write_menu(&ctx, menu, md->choice, &gc);
screen_write_stop(&ctx);
for (i = 0; i < screen_size_y(&md->s); i++)
diff --git a/screen-write.c b/screen-write.c
index 43cb42b4..b2f9e223 100644
--- a/screen-write.c
+++ b/screen-write.c
@@ -409,21 +409,23 @@ screen_write_vline(struct screen_write_ctx *ctx, u_int ny, int top, int bottom)
/* Draw a menu on screen. */
void
-screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice)
+screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu,
+ int choice, const struct grid_cell *choice_gc)
{
struct screen *s = ctx->s;
- struct grid_cell gc;
+ struct grid_cell default_gc;
+ const struct grid_cell *gc = &default_gc;
u_int cx, cy, i, j;
const char *name;
cx = s->cx;
cy = s->cy;
- memcpy(&gc, &grid_default_cell, sizeof gc);
+ memcpy(&default_gc, &grid_default_cell, sizeof default_gc);
screen_write_box(ctx, menu->width + 4, menu->count + 2);
screen_write_cursormove(ctx, cx + 2, cy, 0);
- format_draw(ctx, &gc, menu->width, menu->title, NULL);
+ format_draw(ctx, &default_gc, menu->width, menu->title, NULL);
for (i = 0; i < menu->count; i++) {
name = menu->items[i].name;
@@ -432,20 +434,19 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice)
screen_write_hline(ctx, menu->width + 4, 1, 1);
} else {
if (choice >= 0 && i == (u_int)choice && *name != '-')
- gc.attr |= GRID_ATTR_REVERSE;
+ gc = choice_gc;
screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
for (j = 0; j < menu->width; j++)
- screen_write_putc(ctx, &gc, ' ');
+ screen_write_putc(ctx, gc, ' ');
screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
if (*name == '-') {
name++;
- gc.attr |= GRID_ATTR_DIM;
- format_draw(ctx, &gc, menu->width, name, NULL);
- gc.attr &= ~GRID_ATTR_DIM;
+ default_gc.attr |= GRID_ATTR_DIM;
+ format_draw(ctx, gc, menu->width, name, NULL);
+ default_gc.attr &= ~GRID_ATTR_DIM;
} else
- format_draw(ctx, &gc, menu->width, name, NULL);
- if (choice >= 0 && i == (u_int)choice)
- gc.attr &= ~GRID_ATTR_REVERSE;
+ format_draw(ctx, gc, menu->width, name, NULL);
+ gc = &default_gc;
}
}
diff --git a/tmux.h b/tmux.h
index 278919d6..260891b2 100644
--- a/tmux.h
+++ b/tmux.h
@@ -2382,7 +2382,8 @@ void screen_write_fast_copy(struct screen_write_ctx *, struct screen *,
u_int, u_int, u_int, u_int);
void screen_write_hline(struct screen_write_ctx *, u_int, int, int);
void screen_write_vline(struct screen_write_ctx *, u_int, int, int);
-void screen_write_menu(struct screen_write_ctx *, struct menu *, int);
+void screen_write_menu(struct screen_write_ctx *, struct menu *, int,
+ const struct grid_cell *);
void screen_write_box(struct screen_write_ctx *, u_int, u_int);
void screen_write_preview(struct screen_write_ctx *, struct screen *, u_int,
u_int);