Merge branch 'obsd-master' into master

This commit is contained in:
Thomas Adam 2021-10-20 14:01:15 +01:00
commit 1bf2f811ea
7 changed files with 45 additions and 24 deletions

View File

@ -52,10 +52,10 @@ const struct cmd_entry cmd_display_popup_entry = {
.name = "display-popup", .name = "display-popup",
.alias = "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] " .usage = "[-BCE] [-b border-lines] [-c target-client] "
"[-d start-directory] [-e environment] [-h height] " "[-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]", "[-w width] [-x position] [-y position] [shell-command]",
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@ -354,7 +354,7 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
struct client *tc = cmdq_get_target_client(item); struct client *tc = cmdq_get_target_client(item);
struct tty *tty = &tc->tty; struct tty *tty = &tc->tty;
const char *value, *shell, *shellcmd = NULL; const char *value, *shell, *shellcmd = NULL;
char *cwd, *cause = NULL, **argv = NULL; char *cwd, *cause = NULL, **argv = NULL, *title;
int flags = 0, argc = 0; int flags = 0, argc = 0;
enum box_lines lines = BOX_LINES_DEFAULT; enum box_lines lines = BOX_LINES_DEFAULT;
u_int px, py, w, h, count = args_count(args); u_int px, py, w, h, count = args_count(args);
@ -438,19 +438,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) if (args_has(args, 'E') > 1)
flags |= POPUP_CLOSEEXITZERO; flags |= POPUP_CLOSEEXITZERO;
else if (args_has(args, 'E')) else if (args_has(args, 'E'))
flags |= POPUP_CLOSEEXIT; flags |= POPUP_CLOSEEXIT;
if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc, 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); cmd_free_argv(argc, argv);
if (env != NULL) if (env != NULL)
environ_free(env); environ_free(env);
free(title);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
if (env != NULL) if (env != NULL)
environ_free(env); environ_free(env);
free(title);
cmd_free_argv(argc, argv); cmd_free_argv(argc, argv);
return (CMD_RETURN_WAIT); return (CMD_RETURN_WAIT);
} }

View File

@ -747,7 +747,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
mti = mti->parent; mti = mti->parent;
screen_write_cursormove(&ctx, 0, h, 0); 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) { if (mtd->sort_list != NULL) {
xasprintf(&text, " %s (sort: %s%s)", mti->name, xasprintf(&text, " %s (sort: %s%s)", mti->name,

12
popup.c
View File

@ -31,6 +31,7 @@ struct popup_data {
struct cmdq_item *item; struct cmdq_item *item;
int flags; int flags;
enum box_lines lines; enum box_lines lines;
char *title;
struct screen s; struct screen s;
struct colour_palette palette; struct colour_palette palette;
@ -228,7 +229,8 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx)
screen_write_cursormove(&ctx, 0, 0, 0); screen_write_cursormove(&ctx, 0, 0, 0);
screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx, pd->sy); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx, pd->sy);
} else if (pd->sx > 2 && pd->sy > 2) { } 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_cursormove(&ctx, 1, 1, 0);
screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx - 2, screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx - 2,
pd->sy - 2); pd->sy - 2);
@ -286,6 +288,7 @@ popup_free_cb(struct client *c, void *data)
screen_free(&pd->s); screen_free(&pd->s);
colour_palette_free(&pd->palette); colour_palette_free(&pd->palette);
free(pd->title);
free(pd); free(pd);
} }
@ -631,8 +634,8 @@ popup_job_complete_cb(struct job *job)
int int
popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, 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, 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, int argc, char **argv, const char *cwd, const char *title, struct client *c,
popup_close_cb cb, void *arg) struct session *s, popup_close_cb cb, void *arg)
{ {
struct popup_data *pd; struct popup_data *pd;
u_int jx, jy; u_int jx, jy;
@ -663,6 +666,7 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px,
pd->item = item; pd->item = item;
pd->flags = flags; pd->flags = flags;
pd->lines = lines; pd->lines = lines;
pd->title = xstrdup(title);
pd->c = c; pd->c = c;
pd->c->references++; pd->c->references++;
@ -775,7 +779,7 @@ popup_editor(struct client *c, const char *buf, size_t len,
xasprintf(&cmd, "%s %s", editor, path); xasprintf(&cmd, "%s %s", editor, path);
if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, BOX_LINES_DEFAULT, if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, BOX_LINES_DEFAULT,
NULL, px, py, sx, sy, NULL, cmd, 0, NULL, _PATH_TMP, c, NULL, NULL, px, py, sx, sy, NULL, cmd, 0, NULL, _PATH_TMP, NULL, c, NULL,
popup_editor_close_cb, pe) != 0) { popup_editor_close_cb, pe) != 0) {
popup_editor_free(pe); popup_editor_free(pe);
free(cmd); free(cmd);

View File

@ -646,9 +646,7 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu,
memcpy(&default_gc, &grid_default_cell, sizeof default_gc); memcpy(&default_gc, &grid_default_cell, sizeof default_gc);
screen_write_box(ctx, menu->width + 4, menu->count + 2, screen_write_box(ctx, menu->width + 4, menu->count + 2,
BOX_LINES_DEFAULT, NULL); BOX_LINES_DEFAULT, &default_gc, menu->title);
screen_write_cursormove(ctx, cx + 2, cy, 0);
format_draw(ctx, &default_gc, menu->width, menu->title, NULL);
for (i = 0; i < menu->count; i++) { for (i = 0; i < menu->count; i++) {
name = menu->items[i].name; 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. */ /* Draw a box on screen. */
void void
screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny, 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 screen *s = ctx->s;
struct grid_cell gc; 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); memcpy(&gc, gcp, sizeof gc);
else else
memcpy(&gc, &grid_default_cell, sizeof gc); memcpy(&gc, &grid_default_cell, sizeof gc);
gc.attr |= GRID_ATTR_CHARSET; gc.attr |= GRID_ATTR_CHARSET;
gc.flags |= GRID_FLAG_NOPALETTE; gc.flags |= GRID_FLAG_NOPALETTE;
/* Draw top border */ /* 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_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++) for (i = 1; i < nx - 1; i++)
screen_write_cell(ctx, &gc); 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); screen_write_cell(ctx, &gc);
/* Draw bottom border */ /* Draw bottom border */
screen_write_set_cursor(ctx, cx, cy + ny - 1); 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_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++) for (i = 1; i < nx - 1; i++)
screen_write_cell(ctx, &gc); 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); screen_write_cell(ctx, &gc);
/* Draw sides */ /* 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++) { for (i = 1; i < ny - 1; i++) {
/* left side */ /* left side */
screen_write_set_cursor(ctx, cx, cy + i); 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); 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); screen_write_set_cursor(ctx, cx, cy);
} }

5
tmux.1
View File

@ -5801,6 +5801,7 @@ forwards any input read from stdin to the empty pane given by
.Op Fl e Ar environment .Op Fl e Ar environment
.Op Fl h Ar height .Op Fl h Ar height
.Op Fl t Ar target-pane .Op Fl t Ar target-pane
.Op Fl T Ar title
.Op Fl w Ar width .Op Fl w Ar width
.Op Fl x Ar position .Op Fl x Ar position
.Op Fl y 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 and sets an environment variable for the popup; it may be specified multiple
times. times.
.Pp .Pp
.Fl T
is a format for the popup title (see
.Sx FORMATS ) .
.Pp
The The
.Fl C .Fl C
flag closes any popup on the client. flag closes any popup on the client.

6
tmux.h
View File

@ -2738,7 +2738,7 @@ 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 *); const struct grid_cell *);
void screen_write_box(struct screen_write_ctx *, u_int, u_int, int, 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, void screen_write_preview(struct screen_write_ctx *, struct screen *, u_int,
u_int); u_int);
void screen_write_backspace(struct screen_write_ctx *); void screen_write_backspace(struct screen_write_ctx *);
@ -3156,8 +3156,8 @@ typedef void (*popup_close_cb)(int, void *);
typedef void (*popup_finish_edit_cb)(char *, size_t, void *); typedef void (*popup_finish_edit_cb)(char *, size_t, void *);
int popup_display(int, int, struct cmdq_item *, u_int, u_int, int popup_display(int, int, struct cmdq_item *, u_int, u_int,
u_int, u_int, struct environ *, const char *, int, char **, u_int, u_int, struct environ *, const char *, int, char **,
const char *, struct client *, struct session *, const char *, const char *, struct client *,
popup_close_cb, void *); struct session *, popup_close_cb, void *);
int popup_editor(struct client *, const char *, size_t, int popup_editor(struct client *, const char *, size_t,
popup_finish_edit_cb, void *); popup_finish_edit_cb, void *);

View File

@ -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) { if (ox > 1 && ox + len < sx - 1 && sy >= 3) {
screen_write_cursormove(ctx, px + ox - 1, py + oy - 1, 0); 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_cursormove(ctx, px + ox, py + oy, 0);
screen_write_puts(ctx, gc, "%s", label); screen_write_puts(ctx, gc, "%s", label);