diff --git a/cmd-select-layout.c b/cmd-select-layout.c index 6dfe2b6a..41779747 100644 --- a/cmd-select-layout.c +++ b/cmd-select-layout.c @@ -90,7 +90,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item) previous = 1; oldlayout = w->old_layout; - w->old_layout = layout_dump(w->layout_root); + w->old_layout = layout_dump(w, w->layout_root); if (next || previous) { if (next) diff --git a/format.c b/format.c index fc1a5adb..4c3f1a86 100644 --- a/format.c +++ b/format.c @@ -825,8 +825,8 @@ format_cb_window_layout(struct format_tree *ft) return (NULL); if (w->saved_layout_root != NULL) - return (layout_dump(w->saved_layout_root)); - return (layout_dump(w->layout_root)); + return (layout_dump(w, w->saved_layout_root)); + return (layout_dump(w, w->layout_root)); } /* Callback for window_visible_layout. */ @@ -838,7 +838,7 @@ format_cb_window_visible_layout(struct format_tree *ft) if (w == NULL) return (NULL); - return (layout_dump(w->layout_root)); + return (layout_dump(w, w->layout_root)); } /* Callback for pane_start_command. */ @@ -1004,6 +1004,29 @@ format_cb_pane_fg(struct format_tree *ft) return (xstrdup(colour_tostring(gc.fg))); } +/* Callback for pane_flags. */ +static void * +format_cb_pane_flags(struct format_tree *ft) +{ + if (ft->wp != NULL) + return (xstrdup(window_pane_printable_flags(ft->wp))); + return (NULL); +} + +/* Callback for pane_floating_flag. */ +static void * +format_cb_pane_floating_flag(struct format_tree *ft) +{ + struct window_pane *wp = ft->wp; + + if (wp != NULL) { + if (wp->flags & PANE_FLOATING) + return (xstrdup("1")); + return (xstrdup("0")); + } + return (NULL); +} + /* Callback for pane_bg. */ static void * format_cb_pane_bg(struct format_tree *ft) @@ -1607,9 +1630,13 @@ format_cb_client_user(struct format_tree *ft) struct passwd *pw; if (ft->c != NULL) { + if (ft->c->user != NULL) + return (xstrdup(ft->c->user)); uid = proc_get_peer_uid(ft->c->peer); - if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL) - return (xstrdup(pw->pw_name)); + if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL) { + ft->c->user = xstrdup(pw->pw_name); + return (xstrdup(ft->c->user)); + } } return (NULL); } @@ -2365,6 +2392,20 @@ format_cb_pane_width(struct format_tree *ft) return (NULL); } +/* Callback for pane_zoomed_flag. */ +static void * +format_cb_pane_zoomed_flag(struct format_tree *ft) +{ + struct window_pane *wp = ft->wp; + + if (wp != NULL) { + if (wp->flags & PANE_ZOOMED) + return (xstrdup("1")); + return (xstrdup("0")); + } + return (NULL); +} + /* Callback for scroll_region_lower. */ static void * format_cb_scroll_region_lower(struct format_tree *ft) @@ -3057,10 +3098,13 @@ format_cb_uid(__unused struct format_tree *ft) static void * format_cb_user(__unused struct format_tree *ft) { + static char *cached; struct passwd *pw; - if ((pw = getpwuid(getuid())) != NULL) - return (xstrdup(pw->pw_name)); + if (cached == NULL && (pw = getpwuid(getuid())) != NULL) + cached = xstrdup(pw->pw_name); + if (cached != NULL) + return (xstrdup(cached)); return (NULL); } @@ -3344,6 +3388,12 @@ static const struct format_table_entry format_table[] = { { "pane_fg", FORMAT_TABLE_STRING, format_cb_pane_fg }, + { "pane_flags", FORMAT_TABLE_STRING, + format_cb_pane_flags + }, + { "pane_floating_flag", FORMAT_TABLE_STRING, + format_cb_pane_floating_flag + }, { "pane_format", FORMAT_TABLE_STRING, format_cb_pane_format }, @@ -3431,6 +3481,9 @@ static const struct format_table_entry format_table[] = { { "pane_width", FORMAT_TABLE_STRING, format_cb_pane_width }, + { "pane_zoomed_flag", FORMAT_TABLE_STRING, + format_cb_pane_zoomed_flag + }, { "pid", FORMAT_TABLE_STRING, format_cb_pid }, diff --git a/layout-custom.c b/layout-custom.c index 2bfb6d89..22de0bdd 100644 --- a/layout-custom.c +++ b/layout-custom.c @@ -58,7 +58,7 @@ layout_checksum(const char *layout) /* Dump layout as a string. */ char * -layout_dump(struct layout_cell *root) +layout_dump(__unused struct window *w, struct layout_cell *root) { char layout[8192], *out; diff --git a/options-table.c b/options-table.c index dfe0c9e5..6585484c 100644 --- a/options-table.c +++ b/options-table.c @@ -91,7 +91,7 @@ static const char *options_table_window_size_list[] = { "largest", "smallest", "manual", "latest", NULL }; static const char *options_table_remain_on_exit_list[] = { - "off", "on", "failed", NULL + "off", "on", "failed", "key", NULL }; static const char *options_table_destroy_unattached_list[] = { "off", "on", "keep-last", "keep-group", NULL @@ -1407,8 +1407,9 @@ const struct options_table_entry options_table[] = { .scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE, .choices = options_table_remain_on_exit_list, .default_num = 0, - .text = "Whether panes should remain ('on') or be automatically " - "killed ('off' or 'failed') when the program inside exits." + .text = "Whether panes should remain ('on'), remain until a key is " + "pressed ('key') or be automatically killed ('off' or " + "'failed') when the program inside exits." }, { .name = "remain-on-exit-format", diff --git a/server-client.c b/server-client.c index a0b91eda..27131a89 100644 --- a/server-client.c +++ b/server-client.c @@ -533,6 +533,7 @@ server_client_free(__unused int fd, __unused short events, void *arg) if (c->references == 0) { free((void *)c->name); + free((void *)c->user); free(c); } } @@ -1355,6 +1356,15 @@ try_again: } forward_key: + if (wp != NULL && + (wp->flags & PANE_EXITED) && + !KEYC_IS_MOUSE(key) && + !KEYC_IS_PASTE(key) && + options_get_number(wp->options, "remain-on-exit") == 3) { + options_set_number(wp->options, "remain-on-exit", 0); + server_destroy_pane(wp, 0); + goto out; + } if (c->flags & CLIENT_READONLY) goto out; if (wp != NULL) diff --git a/server-fn.c b/server-fn.c index 25b7e75c..21cd23e1 100644 --- a/server-fn.c +++ b/server-fn.c @@ -344,6 +344,7 @@ server_destroy_pane(struct window_pane *wp, int notify) break; /* FALLTHROUGH */ case 1: + case 3: if (wp->flags & PANE_STATUSDRAWN) return; wp->flags |= PANE_STATUSDRAWN; diff --git a/tmux.1 b/tmux.1 index 2325d362..1dfcf5b6 100644 --- a/tmux.1 +++ b/tmux.1 @@ -5571,13 +5571,16 @@ uses when the colour with that index is requested. The index may be from zero to 255. .Pp .It Xo Ic remain\-on\-exit -.Op Ic on | off | failed +.Op Ic on | off | failed | key .Xc A pane with this flag set is not destroyed when the program running in it exits. If set to .Ic failed , then only when the program exit status is not zero. +If set to +.Ic key , +the pane stays open and closes when a key is pressed. The pane may be reactivated with the .Ic respawn\-pane command. @@ -6371,6 +6374,8 @@ The following variables are available, where appropriate: .It Li "pane_dead_status" Ta "" Ta "Exit status of process in dead pane" .It Li "pane_dead_time" Ta "" Ta "Exit time of process in dead pane" .It Li "pane_fg" Ta "" Ta "Pane foreground colour" +.It Li "pane_flags" Ta "" Ta "Pane flags" +.It Li "pane_floating_flag" Ta "" Ta "1 if pane is floating" .It Li "pane_format" Ta "" Ta "1 if format is for a pane" .It Li "pane_height" Ta "" Ta "Height of pane" .It Li "pane_id" Ta "#D" Ta "Unique pane ID" @@ -6400,6 +6405,7 @@ The following variables are available, where appropriate: .It Li "pane_tty" Ta "" Ta "Pseudo terminal of pane" .It Li "pane_unseen_changes" Ta "" Ta "1 if there were changes in pane while in mode" .It Li "pane_width" Ta "" Ta "Width of pane" +.It Li "pane_floating_flag" Ta "" Ta "1 if pane is floating" .It Li "pid" Ta "" Ta "Server PID" .It Li "prev_window_active" Ta "" Ta "1 if previous window in W: loop is active" .It Li "prev_window_index" Ta "" Ta "Index of previous window in W: loop" diff --git a/tmux.h b/tmux.h index f7eda9d1..3195e592 100644 --- a/tmux.h +++ b/tmux.h @@ -1250,7 +1250,7 @@ struct window_pane { #define PANE_FOCUSED 0x4 #define PANE_VISITED 0x8 #define PANE_ZOOMED 0x10 -/* 0x20 unused */ +#define PANE_FLOATING 0x20 #define PANE_INPUTOFF 0x40 #define PANE_CHANGED 0x80 #define PANE_EXITED 0x100 @@ -1993,6 +1993,7 @@ typedef void (*overlay_resize_cb)(struct client *, void *); struct client { const char *name; struct tmuxpeer *peer; + const char *user; struct cmdq_list *queue; struct client_windows windows; @@ -3421,6 +3422,7 @@ int window_pane_exited(struct window_pane *); u_int window_pane_search(struct window_pane *, const char *, int, int); const char *window_printable_flags(struct winlink *, int); +const char *window_pane_printable_flags(struct window_pane *); struct window_pane *window_pane_find_up(struct window_pane *); struct window_pane *window_pane_find_down(struct window_pane *); struct window_pane *window_pane_find_left(struct window_pane *); @@ -3488,7 +3490,7 @@ int layout_spread_cell(struct window *, struct layout_cell *); void layout_spread_out(struct window_pane *); /* layout-custom.c */ -char *layout_dump(struct layout_cell *); +char *layout_dump(struct window *, struct layout_cell *); int layout_parse(struct window *, const char *, char **); /* layout-set.c */ diff --git a/window.c b/window.c index 0d915aa4..216bf351 100644 --- a/window.c +++ b/window.c @@ -889,9 +889,8 @@ window_printable_flags(struct winlink *wl, int escape) { struct session *s = wl->session; static char flags[32]; - int pos; + u_int pos = 0; - pos = 0; if (wl->flags & WINLINK_ACTIVITY) { flags[pos++] = '#'; if (escape) @@ -913,6 +912,25 @@ window_printable_flags(struct winlink *wl, int escape) return (flags); } +const char * +window_pane_printable_flags(struct window_pane *wp) +{ + struct window *w = wp->window; + static char flags[32]; + u_int pos = 0; + + if (wp == w->active) + flags[pos++] = '*'; + if (wp == TAILQ_FIRST(&w->last_panes)) + flags[pos++] = '-'; + if (wp->flags & PANE_ZOOMED) + flags[pos++] = 'Z'; + if (wp->flags & PANE_FLOATING) + flags[pos++] = 'F'; + flags[pos] = '\0'; + return (flags); +} + struct window_pane * window_pane_find_by_id_str(const char *s) {