summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/screen-write.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2019-05-10 14:12:47 +0000
committernicm <nicm@openbsd.org>2019-05-10 14:12:47 +0000
commit3f2ec672c59fb2e452be58d8aa239f9f220947a6 (patch)
tree56e61d1553982474d457b5efa0176692d680b0b4 /usr.bin/tmux/screen-write.c
parent Implement DNS block lists. If unwind is queried for a domain (diff)
downloadwireguard-openbsd-3f2ec672c59fb2e452be58d8aa239f9f220947a6.tar.xz
wireguard-openbsd-3f2ec672c59fb2e452be58d8aa239f9f220947a6.zip
Add a function to draw a simple menu onto a screen.
Diffstat (limited to 'usr.bin/tmux/screen-write.c')
-rw-r--r--usr.bin/tmux/screen-write.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/usr.bin/tmux/screen-write.c b/usr.bin/tmux/screen-write.c
index 5b0baf05a23..c4daa153703 100644
--- a/usr.bin/tmux/screen-write.c
+++ b/usr.bin/tmux/screen-write.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: screen-write.c,v 1.151 2019/04/18 11:07:28 nicm Exp $ */
+/* $OpenBSD: screen-write.c,v 1.152 2019/05/10 14:12:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -403,6 +403,44 @@ screen_write_vline(struct screen_write_ctx *ctx, u_int ny, int top, int bottom)
screen_write_set_cursor(ctx, cx, cy);
}
+/* Draw a menu on screen. */
+void
+screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice)
+{
+ struct screen *s = ctx->s;
+ struct grid_cell gc;
+ u_int cx, cy, i, j;
+
+ cx = s->cx;
+ cy = s->cy;
+
+ memcpy(&gc, &grid_default_cell, sizeof 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);
+
+ for (i = 0; i < menu->count; i++) {
+ if (menu->items[i].name == NULL) {
+ screen_write_cursormove(ctx, cx, cy + 1 + i, 0);
+ screen_write_hline(ctx, menu->width + 4, 1, 1);
+ } else {
+ if (choice >= 0 && i == (u_int)choice)
+ gc.attr |= GRID_ATTR_REVERSE;
+ screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
+ for (j = 0; j < menu->width; j++)
+ screen_write_putc(ctx, &gc, ' ');
+ screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
+ format_draw(ctx, &gc, menu->width, menu->items[i].name,
+ NULL);
+ if (choice >= 0 && i == (u_int)choice)
+ gc.attr &= ~GRID_ATTR_REVERSE;
+ }
+ }
+
+ screen_write_set_cursor(ctx, cx, cy);
+}
+
/* Draw a box on screen. */
void
screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny)