mirror of
https://github.com/tmux/tmux.git
synced 2025-09-02 21:56:57 +00:00
Sync OpenBSD patchset 200:
Merge pane number into the target specification for pane commands. Instead of using -p index, a target pane is now addressed with the normal -t window form but suffixed with a period and a pane index, for example :0.2 or mysess:mywin.1. An unadorned number such as -t 1 is tried as a pane index in the current window, if that fails the same rules are followed as for a target window and the current pane in that window used. As a side-effect this now means that swap-pane can swap panes between different windows. Note that this changes the syntax of the break-pane, clear-history, kill-pane, resize-pane, select-pane and swap-pane commands.
This commit is contained in:
87
cmd.c
87
cmd.c
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd.c,v 1.110 2009-07-30 20:26:20 tcunha Exp $ */
|
||||
/* $Id: cmd.c,v 1.111 2009-07-30 20:45:20 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -770,3 +770,88 @@ not_found:
|
||||
xfree(sessptr);
|
||||
return (-2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the target session, window and pane number or report an error and
|
||||
* return NULL. The pane number is separated from the session:window by a .,
|
||||
* such as mysession:mywindow.0.
|
||||
*/
|
||||
struct winlink *
|
||||
cmd_find_pane(struct cmd_ctx *ctx,
|
||||
const char *arg, struct session **sp, struct window_pane **wpp)
|
||||
{
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
const char *period;
|
||||
char *winptr, *paneptr;
|
||||
const char *errstr;
|
||||
u_int idx;
|
||||
|
||||
/* Get the current session. */
|
||||
if ((s = cmd_current_session(ctx)) == NULL) {
|
||||
ctx->error(ctx, "can't establish current session");
|
||||
return (NULL);
|
||||
}
|
||||
if (sp != NULL)
|
||||
*sp = s;
|
||||
|
||||
/* A NULL argument means the current session, window and pane. */
|
||||
if (arg == NULL) {
|
||||
*wpp = s->curw->window->active;
|
||||
return (s->curw);
|
||||
}
|
||||
|
||||
/* Look for a separating period. */
|
||||
if ((period = strrchr(arg, '.')) == NULL)
|
||||
goto no_period;
|
||||
|
||||
/* Pull out the window part and parse it. */
|
||||
winptr = xstrdup(arg);
|
||||
winptr[period - arg] = '\0';
|
||||
if (*winptr == '\0')
|
||||
wl = s->curw;
|
||||
else if ((wl = cmd_find_window(ctx, winptr, sp)) == NULL)
|
||||
goto error;
|
||||
|
||||
/* Find the pane section and look it up. */
|
||||
paneptr = winptr + (period - arg) + 1;
|
||||
if (*paneptr == '\0')
|
||||
*wpp = wl->window->active;
|
||||
else {
|
||||
idx = strtonum(paneptr, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
ctx->error(ctx, "pane %s: %s", errstr, paneptr);
|
||||
goto error;
|
||||
}
|
||||
*wpp = window_pane_at_index(wl->window, idx);
|
||||
if (*wpp == NULL) {
|
||||
ctx->error(ctx, "no such pane: %u", idx);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
xfree(winptr);
|
||||
return (wl);
|
||||
|
||||
no_period:
|
||||
/* Try as a pane number alone. */
|
||||
idx = strtonum(arg, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
goto lookup_window;
|
||||
|
||||
/* Try index in the current session and window. */
|
||||
if ((*wpp = window_pane_at_index(s->curw->window, idx)) == NULL)
|
||||
goto lookup_window;
|
||||
|
||||
return (s->curw);
|
||||
|
||||
lookup_window:
|
||||
/* Try as a window and use the active pane. */
|
||||
if ((wl = cmd_find_window(ctx, arg, sp)) != NULL)
|
||||
*wpp = wl->window->active;
|
||||
return (wl);
|
||||
|
||||
error:
|
||||
xfree(winptr);
|
||||
return (NULL);
|
||||
}
|
||||
|
Reference in New Issue
Block a user