aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2019-05-10 17:02:27 +0100
committerThomas Adam <thomas@xteddy.org>2019-05-10 17:02:27 +0100
commitc5f6ea5c0dedfcc8f3245247a0f1298c2fca2fcb (patch)
treecb91b2d81e1488ecec7462f77d9817cdbcfbeaae
parente5f06d2cf62737f5b4453e49951648fe0991905e (diff)
parent004a9b52f0389700194d2789674a1fda90409438 (diff)
downloadrtmux-c5f6ea5c0dedfcc8f3245247a0f1298c2fca2fcb.tar.gz
rtmux-c5f6ea5c0dedfcc8f3245247a0f1298c2fca2fcb.tar.bz2
rtmux-c5f6ea5c0dedfcc8f3245247a0f1298c2fca2fcb.zip
Merge branch 'obsd-master'
-rw-r--r--screen-write.c38
-rw-r--r--tmux.h18
2 files changed, 55 insertions, 1 deletions
diff --git a/screen-write.c b/screen-write.c
index 237b6359..ad3808ae 100644
--- a/screen-write.c
+++ b/screen-write.c
@@ -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/tmux.h b/tmux.h
index d7293ada..84d37735 100644
--- a/tmux.h
+++ b/tmux.h
@@ -750,6 +750,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.
@@ -1689,7 +1704,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);
@@ -2202,6 +2217,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);