summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--usr.bin/tmux/screen-write.c40
-rw-r--r--usr.bin/tmux/tmux.h20
2 files changed, 57 insertions, 3 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)
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 05b75f6ecff..74bf710149b 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.893 2019/05/09 14:09:32 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.894 2019/05/10 14:12:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -748,6 +748,21 @@ struct screen_redraw_ctx {
#define screen_hsize(s) ((s)->grid->hsize)
#define screen_hlimit(s) ((s)->grid->hlimit)
+/* Menu item. */
+struct menu_item {
+ char *name;
+ char *command;
+ key_code key;
+};
+
+/* Menu. */
+struct menu {
+ char *title;
+ struct menu_item *items;
+ u_int count;
+ u_int width;
+};
+
/*
* Window mode. Windows can be in several modes and this is used to call the
* right function to handle input and output.
@@ -1687,7 +1702,7 @@ char *paste_make_sample(struct paste_buffer *);
#define FORMAT_PANE 0x80000000U
#define FORMAT_WINDOW 0x40000000U
struct format_tree;
-const char *format_skip(const char *s, const char *end);
+const char *format_skip(const char *, const char *);
int format_true(const char *);
struct format_tree *format_create(struct client *, struct cmdq_item *, int,
int);
@@ -2200,6 +2215,7 @@ 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_box(struct screen_write_ctx *, u_int, u_int);
void screen_write_preview(struct screen_write_ctx *, struct screen *, u_int,
u_int);