Skip to content

Commit 98b92c0

Browse files
nicmnicm
nicm
authored andcommitted
Add remain-on-exit-format to set text shown when pane is dead.
1 parent 57f3314 commit 98b92c0

File tree

5 files changed

+77
-23
lines changed

5 files changed

+77
-23
lines changed

format.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,23 @@ format_cb_pane_dead(struct format_tree *ft)
17561756
return (NULL);
17571757
}
17581758

1759+
/* Callback for pane_dead_signal. */
1760+
static void *
1761+
format_cb_pane_dead_signal(struct format_tree *ft)
1762+
{
1763+
struct window_pane *wp = ft->wp;
1764+
const char *name;
1765+
1766+
if (wp != NULL) {
1767+
if ((wp->flags & PANE_STATUSREADY) && WIFSIGNALED(wp->status)) {
1768+
name = sig2name(WTERMSIG(wp->status));
1769+
return (format_printf("%s", name));
1770+
}
1771+
return (NULL);
1772+
}
1773+
return (NULL);
1774+
}
1775+
17591776
/* Callback for pane_dead_status. */
17601777
static void *
17611778
format_cb_pane_dead_status(struct format_tree *ft)
@@ -1770,6 +1787,20 @@ format_cb_pane_dead_status(struct format_tree *ft)
17701787
return (NULL);
17711788
}
17721789

1790+
/* Callback for pane_dead_time. */
1791+
static void *
1792+
format_cb_pane_dead_time(struct format_tree *ft)
1793+
{
1794+
struct window_pane *wp = ft->wp;
1795+
1796+
if (wp != NULL) {
1797+
if (wp->flags & PANE_STATUSDRAWN)
1798+
return (&wp->dead_time);
1799+
return (NULL);
1800+
}
1801+
return (NULL);
1802+
}
1803+
17731804
/* Callback for pane_format. */
17741805
static void *
17751806
format_cb_pane_format(struct format_tree *ft)
@@ -2804,9 +2835,15 @@ static const struct format_table_entry format_table[] = {
28042835
{ "pane_dead", FORMAT_TABLE_STRING,
28052836
format_cb_pane_dead
28062837
},
2838+
{ "pane_dead_signal", FORMAT_TABLE_STRING,
2839+
format_cb_pane_dead_signal
2840+
},
28072841
{ "pane_dead_status", FORMAT_TABLE_STRING,
28082842
format_cb_pane_dead_status
28092843
},
2844+
{ "pane_dead_time", FORMAT_TABLE_TIME,
2845+
format_cb_pane_dead_time
2846+
},
28102847
{ "pane_fg", FORMAT_TABLE_STRING,
28112848
format_cb_pane_fg
28122849
},

options-table.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,19 @@ const struct options_table_entry options_table[] = {
10601060
"killed ('off' or 'failed') when the program inside exits."
10611061
},
10621062

1063+
{ .name = "remain-on-exit-format",
1064+
.type = OPTIONS_TABLE_STRING,
1065+
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
1066+
.default_str = "Pane is dead ("
1067+
"#{?#{!=:#{pane_dead_status},},"
1068+
"status #{pane_dead_status},}"
1069+
"#{?#{!=:#{pane_dead_signal},},"
1070+
"signal #{pane_dead_signal},}, "
1071+
"#{t:pane_dead_time})",
1072+
.text = "Message shown after the program in a pane has exited, if "
1073+
"remain-on-exit is enabled."
1074+
},
1075+
10631076
{ .name = "synchronize-panes",
10641077
.type = OPTIONS_TABLE_FLAG,
10651078
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,

server-fn.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ server_destroy_pane(struct window_pane *wp, int notify)
310310
struct window *w = wp->window;
311311
struct screen_write_ctx ctx;
312312
struct grid_cell gc;
313-
time_t t;
314-
char tim[26];
315313
int remain_on_exit;
314+
const char *s;
315+
char *expanded;
316+
u_int sx = screen_size_x(&wp->base);
317+
u_int sy = screen_size_y(&wp->base);
316318

317319
if (wp->fd != -1) {
318320
#ifdef HAVE_UTEMPTER
@@ -339,32 +341,26 @@ server_destroy_pane(struct window_pane *wp, int notify)
339341
return;
340342
wp->flags |= PANE_STATUSDRAWN;
341343

344+
gettimeofday(&wp->dead_time, NULL);
342345
if (notify)
343346
notify_pane("pane-died", wp);
344347

345-
screen_write_start_pane(&ctx, wp, &wp->base);
346-
screen_write_scrollregion(&ctx, 0, screen_size_y(ctx.s) - 1);
347-
screen_write_cursormove(&ctx, 0, screen_size_y(ctx.s) - 1, 0);
348-
screen_write_linefeed(&ctx, 1, 8);
349-
memcpy(&gc, &grid_default_cell, sizeof gc);
350-
351-
time(&t);
352-
ctime_r(&t, tim);
353-
tim[strcspn(tim, "\n")] = '\0';
354-
355-
if (WIFEXITED(wp->status)) {
356-
screen_write_nputs(&ctx, -1, &gc,
357-
"Pane is dead (status %d, %s)",
358-
WEXITSTATUS(wp->status),
359-
tim);
360-
} else if (WIFSIGNALED(wp->status)) {
361-
screen_write_nputs(&ctx, -1, &gc,
362-
"Pane is dead (signal %s, %s)",
363-
sig2name(WTERMSIG(wp->status)),
364-
tim);
348+
s = options_get_string(wp->options, "remain-on-exit-format");
349+
if (*s != '\0') {
350+
screen_write_start_pane(&ctx, wp, &wp->base);
351+
screen_write_scrollregion(&ctx, 0, sy - 1);
352+
screen_write_cursormove(&ctx, 0, sy - 1, 0);
353+
screen_write_linefeed(&ctx, 1, 8);
354+
memcpy(&gc, &grid_default_cell, sizeof gc);
355+
356+
expanded = format_single(NULL, s, NULL, NULL, NULL, wp);
357+
format_draw(&ctx, &gc, sx, expanded, NULL, 0);
358+
free(expanded);
359+
360+
screen_write_stop(&ctx);
365361
}
362+
wp->base.mode &= ~MODE_CURSOR;
366363

367-
screen_write_stop(&ctx);
368364
wp->flags |= PANE_REDRAW;
369365
return;
370366
}

tmux.1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4471,6 +4471,11 @@ The pane may be reactivated with the
44714471
.Ic respawn-pane
44724472
command.
44734473
.Pp
4474+
.It Ic remain-on-exit-format Ar string
4475+
Set the text shown at the bottom of exited panes when
4476+
.Ic remain-on-exit
4477+
is enabled.
4478+
.Pp
44744479
.It Xo Ic synchronize-panes
44754480
.Op Ic on | off
44764481
.Xc
@@ -5120,7 +5125,9 @@ The following variables are available, where appropriate:
51205125
.It Li "pane_current_command" Ta "" Ta "Current command if available"
51215126
.It Li "pane_current_path" Ta "" Ta "Current path if available"
51225127
.It Li "pane_dead" Ta "" Ta "1 if pane is dead"
5128+
.It Li "pane_dead_signal" Ta "" Ta "Exit signal of process in dead pane"
51235129
.It Li "pane_dead_status" Ta "" Ta "Exit status of process in dead pane"
5130+
.It Li "pane_dead_time" Ta "" Ta "Exit time of process in dead pane"
51245131
.It Li "pane_fg" Ta "" Ta "Pane foreground colour"
51255132
.It Li "pane_format" Ta "" Ta "1 if format is for a pane"
51265133
.It Li "pane_height" Ta "" Ta "Height of pane"

tmux.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ struct window_pane {
10271027
pid_t pid;
10281028
char tty[TTY_NAME_MAX];
10291029
int status;
1030+
struct timeval dead_time;
10301031

10311032
int fd;
10321033
struct bufferevent *event;

0 commit comments

Comments
 (0)