diff options
author | nicm <nicm> | 2020-03-28 09:39:44 +0000 |
---|---|---|
committer | nicm <nicm> | 2020-03-28 09:39:44 +0000 |
commit | 4346098e977d8fb3bde0783e9858f3def7bc01a5 (patch) | |
tree | b5164226ed816a4a1870a06ea09c6f597d22771f | |
parent | e0b17e796b52bfad7d867bc876a9826bf5761be4 (diff) | |
download | rtmux-4346098e977d8fb3bde0783e9858f3def7bc01a5.tar.gz rtmux-4346098e977d8fb3bde0783e9858f3def7bc01a5.tar.bz2 rtmux-4346098e977d8fb3bde0783e9858f3def7bc01a5.zip |
Fix how popup height is calculated to take embedded newlines into account.
-rw-r--r-- | cmd-display-menu.c | 6 | ||||
-rw-r--r-- | popup.c | 20 | ||||
-rw-r--r-- | 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'); @@ -350,6 +350,22 @@ popup_job_complete_cb(struct job *job) } 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; @@ -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 *); |