diff options
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/job.c | 23 | ||||
-rw-r--r-- | usr.bin/tmux/popup.c | 61 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 |
3 files changed, 82 insertions, 6 deletions
diff --git a/usr.bin/tmux/job.c b/usr.bin/tmux/job.c index 1887b2b0942..db67647ef36 100644 --- a/usr.bin/tmux/job.c +++ b/usr.bin/tmux/job.c @@ -1,4 +1,4 @@ -/* $OpenBSD: job.c,v 1.60 2021/03/02 10:56:45 nicm Exp $ */ +/* $OpenBSD: job.c,v 1.61 2021/08/13 19:27:25 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -201,6 +201,27 @@ fail: return (NULL); } +/* Take job's file descriptor and free the job. */ +int +job_transfer(struct job *job) +{ + int fd = job->fd; + + log_debug("transfer job %p: %s", job, job->cmd); + + LIST_REMOVE(job, entry); + free(job->cmd); + + if (job->freecb != NULL && job->data != NULL) + job->freecb(job->data); + + if (job->event != NULL) + bufferevent_free(job->event); + + free(job); + return (fd); +} + /* Kill and free an individual job. */ void job_free(struct job *job) diff --git a/usr.bin/tmux/popup.c b/usr.bin/tmux/popup.c index e536c7476b7..dfe486694eb 100644 --- a/usr.bin/tmux/popup.c +++ b/usr.bin/tmux/popup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: popup.c,v 1.28 2021/08/13 19:25:24 nicm Exp $ */ +/* $OpenBSD: popup.c,v 1.29 2021/08/13 19:27:25 nicm Exp $ */ /* * Copyright (c) 2020 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -77,6 +77,18 @@ static const struct menu_item popup_menu_items[] = { { "", KEYC_NONE, NULL }, { "Fill Space", 'F', NULL }, { "Centre", 'C', NULL }, + { "", KEYC_NONE, NULL }, + { "Make Pane (H)", 'h', NULL }, + { "Make Pane (V)", 'v', NULL }, + + { NULL, KEYC_NONE, NULL } +}; + +static const struct menu_item popup_internal_menu_items[] = { + { "Close", 'q', NULL }, + { "", KEYC_NONE, NULL }, + { "Fill Space", 'F', NULL }, + { "Centre", 'C', NULL }, { NULL, KEYC_NONE, NULL } }; @@ -279,6 +291,37 @@ popup_resize_cb(__unused struct client *c, void *data) } static void +popup_make_pane(struct popup_data *pd, enum layout_type type) +{ + struct client *c = pd->c; + struct session *s = c->session; + struct window *w = s->curw->window; + struct layout_cell *lc; + struct window_pane *wp = w->active, *new_wp; + u_int hlimit; + + window_unzoom(w); + + lc = layout_split_pane(wp, type, -1, 0); + hlimit = options_get_number(s->options, "history-limit"); + new_wp = window_add_pane(wp->window, NULL, hlimit, 0); + layout_assign_pane(lc, new_wp, 0); + + new_wp->fd = job_transfer(pd->job); + pd->job = NULL; + + screen_free(&new_wp->base); + memcpy(&new_wp->base, &pd->s, sizeof wp->base); + screen_resize(&new_wp->base, new_wp->sx, new_wp->sy, 1); + screen_init(&pd->s, 1, 1, 0); + + window_pane_set_event(new_wp); + window_set_active_pane(w, new_wp, 1); + + pd->close = 1; +} + +static void popup_menu_done(__unused struct menu *menu, __unused u_int choice, key_code key, void *data) { @@ -312,6 +355,12 @@ popup_menu_done(__unused struct menu *menu, __unused u_int choice, pd->py = c->tty.sy / 2 - pd->sy / 2; server_redraw_client(c); break; + case 'h': + popup_make_pane(pd, LAYOUT_LEFTRIGHT); + break; + case 'v': + popup_make_pane(pd, LAYOUT_TOPBOTTOM); + break; case 'q': pd->close = 1; break; @@ -460,7 +509,11 @@ popup_key_cb(struct client *c, void *data, struct key_event *event) menu: pd->menu = menu_create(""); - menu_add_items(pd->menu, popup_menu_items, NULL, NULL, NULL); + if (pd->flags & POPUP_INTERNAL) { + menu_add_items(pd->menu, popup_internal_menu_items, NULL, NULL, + NULL); + } else + menu_add_items(pd->menu, popup_menu_items, NULL, NULL, NULL); if (m->x >= (pd->menu->width + 4) / 2) x = m->x - (pd->menu->width + 4) / 2; else @@ -659,8 +712,8 @@ popup_editor(struct client *c, const char *buf, size_t len, py = (c->tty.sy / 2) - (sy / 2); xasprintf(&cmd, "%s %s", editor, path); - if (popup_display(POPUP_CLOSEEXIT, NULL, px, py, sx, sy, cmd, 0, NULL, - _PATH_TMP, c, NULL, popup_editor_close_cb, pe) != 0) { + if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, NULL, px, py, sx, sy, + cmd, 0, NULL, _PATH_TMP, c, NULL, popup_editor_close_cb, pe) != 0) { popup_editor_free(pe); free(cmd); return (-1); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 70992327ccf..865ca1e82c9 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1120 2021/08/13 18:54:54 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1121 2021/08/13 19:27:25 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -2042,6 +2042,7 @@ struct job *job_run(const char *, int, char **, struct session *, const char *, job_update_cb, job_complete_cb, job_free_cb, void *, int, int, int); void job_free(struct job *); +int job_transfer(struct job *); void job_resize(struct job *, u_int, u_int); void job_check_died(pid_t, int); int job_get_status(struct job *); @@ -3038,6 +3039,7 @@ int menu_key_cb(struct client *, void *, struct key_event *); #define POPUP_CLOSEEXIT 0x1 #define POPUP_CLOSEEXITZERO 0x2 #define POPUP_NOBORDER 0x4 +#define POPUP_INTERNAL 0x8 typedef void (*popup_close_cb)(int, void *); typedef void (*popup_finish_edit_cb)(char *, size_t, void *); int popup_display(int, struct cmdq_item *, u_int, u_int, u_int, |