diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-10-20 09:50:41 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-10-20 09:50:41 +0000 |
commit | 3c4dc15ba02eea21465274d59db7b72f0afa7a5c (patch) | |
tree | 20897aba332cefd1a0a639cb56daf1c8b1b3f36f /usr.bin/tmux | |
parent | f3a6455befe016c27b87a003b2c2d449b4ddb170 (diff) |
Add -T to set a popup title, from Alexis Hildebrandt in GitHub issue 2941.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/cmd-display-menu.c | 16 | ||||
-rw-r--r-- | usr.bin/tmux/mode-tree.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/popup.c | 15 | ||||
-rw-r--r-- | usr.bin/tmux/screen-write.c | 29 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 9 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 8 | ||||
-rw-r--r-- | usr.bin/tmux/window-tree.c | 5 |
7 files changed, 54 insertions, 32 deletions
diff --git a/usr.bin/tmux/cmd-display-menu.c b/usr.bin/tmux/cmd-display-menu.c index 480fe4f1ae2..5648256f5d7 100644 --- a/usr.bin/tmux/cmd-display-menu.c +++ b/usr.bin/tmux/cmd-display-menu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-display-menu.c,v 1.35 2021/10/14 13:19:01 nicm Exp $ */ +/* $OpenBSD: cmd-display-menu.c,v 1.36 2021/10/20 09:50:40 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -53,10 +53,10 @@ const struct cmd_entry cmd_display_popup_entry = { .name = "display-popup", .alias = "popup", - .args = { "Bb:Cc:d:e:Eh:t:w:x:y:", 0, -1, NULL }, + .args = { "Bb:Cc:d:e:Eh:t:T:w:x:y:", 0, -1, NULL }, .usage = "[-BCE] [-b border-lines] [-c target-client] " "[-d start-directory] [-e environment] [-h height] " - CMD_TARGET_PANE_USAGE " " + CMD_TARGET_PANE_USAGE " [-T title] " "[-w width] [-x position] [-y position] [shell-command]", .target = { 't', CMD_FIND_PANE, 0 }, @@ -355,7 +355,7 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) struct client *tc = cmdq_get_target_client(item); struct tty *tty = &tc->tty; const char *value, *shell, *shellcmd = NULL; - char *cwd, *cause = NULL, **argv = NULL; + char *cwd, *cause = NULL, **argv = NULL, *title; int flags = 0, argc = 0; enum box_lines lines = BOX_LINES_DEFAULT; u_int px, py, w, h, count = args_count(args); @@ -439,19 +439,25 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) } } + if (args_has(args, 'T')) + title = format_single_from_target(item, args_get(args, 'T')); + else + title = xstrdup(""); if (args_has(args, 'E') > 1) flags |= POPUP_CLOSEEXITZERO; else if (args_has(args, 'E')) flags |= POPUP_CLOSEEXIT; if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc, - argv, cwd, tc, s, NULL, NULL) != 0) { + argv, cwd, title, tc, s, NULL, NULL) != 0) { cmd_free_argv(argc, argv); if (env != NULL) environ_free(env); + free(title); return (CMD_RETURN_NORMAL); } if (env != NULL) environ_free(env); + free(title); cmd_free_argv(argc, argv); return (CMD_RETURN_WAIT); } diff --git a/usr.bin/tmux/mode-tree.c b/usr.bin/tmux/mode-tree.c index 64114f1893a..5c34d5d4f33 100644 --- a/usr.bin/tmux/mode-tree.c +++ b/usr.bin/tmux/mode-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mode-tree.c,v 1.57 2021/10/14 13:19:01 nicm Exp $ */ +/* $OpenBSD: mode-tree.c,v 1.58 2021/10/20 09:50:40 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -747,7 +747,7 @@ mode_tree_draw(struct mode_tree_data *mtd) mti = mti->parent; screen_write_cursormove(&ctx, 0, h, 0); - screen_write_box(&ctx, w, sy - h, BOX_LINES_DEFAULT, NULL); + screen_write_box(&ctx, w, sy - h, BOX_LINES_DEFAULT, NULL, NULL); if (mtd->sort_list != NULL) { xasprintf(&text, " %s (sort: %s%s)", mti->name, diff --git a/usr.bin/tmux/popup.c b/usr.bin/tmux/popup.c index 331b77b14a5..a8c9ee73be8 100644 --- a/usr.bin/tmux/popup.c +++ b/usr.bin/tmux/popup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: popup.c,v 1.38 2021/10/14 13:19:01 nicm Exp $ */ +/* $OpenBSD: popup.c,v 1.39 2021/10/20 09:50:40 nicm Exp $ */ /* * Copyright (c) 2020 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -32,6 +32,7 @@ struct popup_data { struct cmdq_item *item; int flags; enum box_lines lines; + char *title; struct screen s; struct colour_palette palette; @@ -229,7 +230,8 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx) screen_write_cursormove(&ctx, 0, 0, 0); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx, pd->sy); } else if (pd->sx > 2 && pd->sy > 2) { - screen_write_box(&ctx, pd->sx, pd->sy, pd->lines, &bgc); + screen_write_box(&ctx, pd->sx, pd->sy, pd->lines, &bgc, + pd->title); screen_write_cursormove(&ctx, 1, 1, 0); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx - 2, pd->sy - 2); @@ -287,6 +289,7 @@ popup_free_cb(struct client *c, void *data) screen_free(&pd->s); colour_palette_free(&pd->palette); + free(pd->title); free(pd); } @@ -632,8 +635,8 @@ popup_job_complete_cb(struct job *job) int popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, u_int py, u_int sx, u_int sy, struct environ *env, const char *shellcmd, - int argc, char **argv, const char *cwd, struct client *c, struct session *s, - popup_close_cb cb, void *arg) + int argc, char **argv, const char *cwd, const char *title, struct client *c, + struct session *s, popup_close_cb cb, void *arg) { struct popup_data *pd; u_int jx, jy; @@ -664,6 +667,7 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, pd->item = item; pd->flags = flags; pd->lines = lines; + pd->title = xstrdup(title); pd->c = c; pd->c->references++; @@ -776,7 +780,8 @@ popup_editor(struct client *c, const char *buf, size_t len, xasprintf(&cmd, "%s %s", editor, path); if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, BOX_LINES_DEFAULT, - NULL, px, py, sx, sy, NULL, cmd, 0, NULL, _PATH_TMP, c, NULL, + // TODO: Helpful to use path as a title? + NULL, px, py, sx, sy, NULL, cmd, 0, NULL, _PATH_TMP, NULL, c, NULL, popup_editor_close_cb, pe) != 0) { popup_editor_free(pe); free(cmd); diff --git a/usr.bin/tmux/screen-write.c b/usr.bin/tmux/screen-write.c index 9e01b4b8a69..43184034dd6 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.201 2021/10/14 13:19:01 nicm Exp $ */ +/* $OpenBSD: screen-write.c,v 1.202 2021/10/20 09:50:40 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -646,9 +646,7 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, memcpy(&default_gc, &grid_default_cell, sizeof default_gc); screen_write_box(ctx, menu->width + 4, menu->count + 2, - BOX_LINES_DEFAULT, NULL); - screen_write_cursormove(ctx, cx + 2, cy, 0); - format_draw(ctx, &default_gc, menu->width, menu->title, NULL); + BOX_LINES_DEFAULT, &default_gc, menu->title); for (i = 0; i < menu->count; i++) { name = menu->items[i].name; @@ -714,7 +712,7 @@ screen_write_box_border_set(enum box_lines box_lines, int cell_type, /* Draw a box on screen. */ void screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny, - enum box_lines l, const struct grid_cell *gcp) + enum box_lines lines, const struct grid_cell *gcp, const char *title) { struct screen *s = ctx->s; struct grid_cell gc; @@ -727,30 +725,31 @@ screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny, memcpy(&gc, gcp, sizeof gc); else memcpy(&gc, &grid_default_cell, sizeof gc); + gc.attr |= GRID_ATTR_CHARSET; gc.flags |= GRID_FLAG_NOPALETTE; /* Draw top border */ - screen_write_box_border_set(l, CELL_TOPLEFT, &gc); + screen_write_box_border_set(lines, CELL_TOPLEFT, &gc); screen_write_cell(ctx, &gc); - screen_write_box_border_set(l, CELL_LEFTRIGHT, &gc); + screen_write_box_border_set(lines, CELL_LEFTRIGHT, &gc); for (i = 1; i < nx - 1; i++) screen_write_cell(ctx, &gc); - screen_write_box_border_set(l, CELL_TOPRIGHT, &gc); + screen_write_box_border_set(lines, CELL_TOPRIGHT, &gc); screen_write_cell(ctx, &gc); /* Draw bottom border */ screen_write_set_cursor(ctx, cx, cy + ny - 1); - screen_write_box_border_set(l, CELL_BOTTOMLEFT, &gc); + screen_write_box_border_set(lines, CELL_BOTTOMLEFT, &gc); screen_write_cell(ctx, &gc); - screen_write_box_border_set(l, CELL_LEFTRIGHT, &gc); + screen_write_box_border_set(lines, CELL_LEFTRIGHT, &gc); for (i = 1; i < nx - 1; i++) screen_write_cell(ctx, &gc); - screen_write_box_border_set(l, CELL_BOTTOMRIGHT, &gc); + screen_write_box_border_set(lines, CELL_BOTTOMRIGHT, &gc); screen_write_cell(ctx, &gc); /* Draw sides */ - screen_write_box_border_set(l, CELL_TOPBOTTOM, &gc); + screen_write_box_border_set(lines, CELL_TOPBOTTOM, &gc); for (i = 1; i < ny - 1; i++) { /* left side */ screen_write_set_cursor(ctx, cx, cy + i); @@ -760,6 +759,12 @@ screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny, screen_write_cell(ctx, &gc); } + if (title != NULL) { + gc.attr &= ~GRID_ATTR_CHARSET; + screen_write_cursormove(ctx, cx + 2, cy, 0); + format_draw(ctx, &gc, nx - 4, title, NULL); + } + screen_write_set_cursor(ctx, cx, cy); } diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 3ae65e9b85a..831f33000cf 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.863 2021/10/18 09:09:46 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.864 2021/10/20 09:50:40 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: October 18 2021 $ +.Dd $Mdocdate: October 20 2021 $ .Dt TMUX 1 .Os .Sh NAME @@ -5801,6 +5801,7 @@ forwards any input read from stdin to the empty pane given by .Op Fl e Ar environment .Op Fl h Ar height .Op Fl t Ar target-pane +.Op Fl T Ar title .Op Fl w Ar width .Op Fl x Ar position .Op Fl y Ar position @@ -5858,6 +5859,10 @@ takes the form and sets an environment variable for the popup; it may be specified multiple times. .Pp +.Fl T +is a format for the popup title (see +.Sx FORMATS ) . +.Pp The .Fl C flag closes any popup on the client. diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index bb0e4ee7705..51e1aa02091 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1147 2021/10/14 13:19:01 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1148 2021/10/20 09:50:40 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -2737,7 +2737,7 @@ void screen_write_vline(struct screen_write_ctx *, u_int, int, 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, int, - const struct grid_cell *); + const struct grid_cell *, const char *); void screen_write_preview(struct screen_write_ctx *, struct screen *, u_int, u_int); void screen_write_backspace(struct screen_write_ctx *); @@ -3154,8 +3154,8 @@ typedef void (*popup_close_cb)(int, void *); typedef void (*popup_finish_edit_cb)(char *, size_t, void *); int popup_display(int, int, struct cmdq_item *, u_int, u_int, u_int, u_int, struct environ *, const char *, int, char **, - const char *, struct client *, struct session *, - popup_close_cb, void *); + const char *, const char *, struct client *, + struct session *, popup_close_cb, void *); int popup_editor(struct client *, const char *, size_t, popup_finish_edit_cb, void *); diff --git a/usr.bin/tmux/window-tree.c b/usr.bin/tmux/window-tree.c index b100fc113d4..ce349fe4a3c 100644 --- a/usr.bin/tmux/window-tree.c +++ b/usr.bin/tmux/window-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-tree.c,v 1.58 2021/10/14 13:19:01 nicm Exp $ */ +/* $OpenBSD: window-tree.c,v 1.59 2021/10/20 09:50:40 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -519,7 +519,8 @@ window_tree_draw_label(struct screen_write_ctx *ctx, u_int px, u_int py, if (ox > 1 && ox + len < sx - 1 && sy >= 3) { screen_write_cursormove(ctx, px + ox - 1, py + oy - 1, 0); - screen_write_box(ctx, len + 2, 3, BOX_LINES_DEFAULT, NULL); + screen_write_box(ctx, len + 2, 3, BOX_LINES_DEFAULT, NULL, + NULL); } screen_write_cursormove(ctx, px + ox, py + oy, 0); screen_write_puts(ctx, gc, "%s", label); |