From e0b17e796b52bfad7d867bc876a9826bf5761be4 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 28 Mar 2020 09:39:27 +0000 Subject: [PATCH 1/2] Add formats for top paste buffer by default. Also a tmux.1 fix from jmc. --- format.c | 6 ++++++ tmux.1 | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/format.c b/format.c index da241c48..630e75d6 100644 --- a/format.c +++ b/format.c @@ -2421,6 +2421,8 @@ void format_defaults(struct format_tree *ft, struct client *c, struct session *s, struct winlink *wl, struct window_pane *wp) { + struct paste_buffer *pb; + if (c != NULL && c->name != NULL) log_debug("%s: c=%s", __func__, c->name); else @@ -2460,6 +2462,10 @@ format_defaults(struct format_tree *ft, struct client *c, struct session *s, format_defaults_winlink(ft, wl); if (wp != NULL) format_defaults_pane(ft, wp); + + pb = paste_get_top (NULL); + if (pb != NULL) + format_defaults_paste_buffer(ft, pb); } /* Set default format keys for a session. */ diff --git a/tmux.1 b/tmux.1 index 263bedc1..aec7f79e 100644 --- a/tmux.1 +++ b/tmux.1 @@ -5024,7 +5024,7 @@ It may be empty to discard any key presses. If .Fl K is given together with -.Fl R, +.Fl R , key presses are instead passed to the .Fl R shell command. From 4346098e977d8fb3bde0783e9858f3def7bc01a5 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 28 Mar 2020 09:39:44 +0000 Subject: [PATCH 2/2] Fix how popup height is calculated to take embedded newlines into account. --- cmd-display-menu.c | 6 +++++- popup.c | 20 +++++++++++++++++--- tmux.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cmd-display-menu.c b/cmd-display-menu.c index aafe2447..e12a24ab 100644 --- a/cmd-display-menu.c +++ b/cmd-display-menu.c @@ -237,7 +237,7 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) } if (nlines != 0) - h = nlines + 2; + h = popup_height(nlines, lines) + 2; else h = c->tty.sy / 2; if (args_has(args, 'h')) { @@ -262,6 +262,10 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) } } + if (w > c->tty.sx - 1) + w = c->tty.sx - 1; + if (h > c->tty.sy - 1) + h = c->tty.sy - 1; cmd_display_menu_get_position(c, item, args, &px, &py, w, h); value = args_get(args, 'd'); diff --git a/popup.c b/popup.c index 16b7b260..f4afbd85 100644 --- a/popup.c +++ b/popup.c @@ -349,6 +349,22 @@ popup_job_complete_cb(struct job *job) server_client_clear_overlay(pd->c); } +u_int +popup_height(u_int nlines, const char **lines) +{ + char *copy, *next, *loop; + u_int i, height = 0; + + for (i = 0; i < nlines; i++) { + copy = next = xstrdup(lines[i]); + while ((loop = strsep(&next, "\n")) != NULL) + height++; + free(copy); + } + + return (height); +} + u_int popup_width(struct cmdq_item *item, u_int nlines, const char **lines, struct client *c, struct cmd_find_state *fs) @@ -372,8 +388,8 @@ popup_width(struct cmdq_item *item, u_int nlines, const char **lines, width = tmpwidth; free(tmp); } + free(copy); } - free(copy); format_free(ft); return (width); @@ -394,8 +410,6 @@ popup_display(int flags, struct cmdq_item *item, u_int px, u_int py, u_int sx, return (-1); if (c->tty.sx < sx || c->tty.sy < sy) return (-1); - if (nlines > sy - 2) - nlines = sy - 2; pd = xcalloc(1, sizeof *pd); pd->item = item; diff --git a/tmux.h b/tmux.h index f885287b..bcec0a23 100644 --- a/tmux.h +++ b/tmux.h @@ -2763,6 +2763,7 @@ int menu_display(struct menu *, int, struct cmdq_item *, u_int, #define POPUP_CLOSEEXIT 0x2 u_int popup_width(struct cmdq_item *, u_int, const char **, struct client *, struct cmd_find_state *); +u_int popup_height(u_int, const char **); int popup_display(int, struct cmdq_item *, u_int, u_int, u_int, u_int, u_int, const char **, const char *, const char *, const char *, struct client *, struct cmd_find_state *);