mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Make window_pane_index work the same as window_index, from Ben Boeckel.
This commit is contained in:
		@@ -50,14 +50,17 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
			
		||||
	struct environ		 env;
 | 
			
		||||
	const char		*cmd;
 | 
			
		||||
	char			*cause;
 | 
			
		||||
	u_int			 idx;
 | 
			
		||||
 | 
			
		||||
	if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
 | 
			
		||||
		return (-1);
 | 
			
		||||
	w = wl->window;
 | 
			
		||||
 | 
			
		||||
	if (!args_has(self->args, 'k') && wp->fd != -1) {
 | 
			
		||||
		if (window_pane_index(wp, &idx) != 0)
 | 
			
		||||
			fatalx("index not found");
 | 
			
		||||
		ctx->error(ctx, "pane still active: %s:%u.%u",
 | 
			
		||||
		    s->name, wl->idx, window_pane_index(w, wp));
 | 
			
		||||
		    s->name, wl->idx, idx);
 | 
			
		||||
		return (-1);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -140,7 +140,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
			
		||||
	environ_free(&env);
 | 
			
		||||
 | 
			
		||||
	if (args_has(args, 'P')) {
 | 
			
		||||
		paneidx = window_pane_index(wl->window, new_wp);
 | 
			
		||||
		if (window_pane_index(new_wp, &paneidx) != 0)
 | 
			
		||||
			fatalx("index not found");
 | 
			
		||||
		ctx->print(ctx, "%s:%u.%u", s->name, wl->idx, paneidx);
 | 
			
		||||
	}
 | 
			
		||||
	return (0);
 | 
			
		||||
 
 | 
			
		||||
@@ -272,7 +272,8 @@ screen_redraw_draw_number(struct client *c, struct window_pane *wp)
 | 
			
		||||
	char			 buf[16], *ptr;
 | 
			
		||||
	size_t			 len;
 | 
			
		||||
 | 
			
		||||
	idx = window_pane_index(w, wp);
 | 
			
		||||
	if (window_pane_index(wp, &idx) != 0)
 | 
			
		||||
		fatalx("index not found");
 | 
			
		||||
	len = xsnprintf(buf, sizeof buf, "%u", idx);
 | 
			
		||||
 | 
			
		||||
	if (wp->sx < len)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								status.c
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								status.c
									
									
									
									
									
								
							@@ -372,6 +372,7 @@ status_replace1(struct client *c, struct session *s, struct winlink *wl,
 | 
			
		||||
	char	ch, tmp[256], *ptr, *endptr, *freeptr;
 | 
			
		||||
	size_t	ptrlen;
 | 
			
		||||
	long	limit;
 | 
			
		||||
	u_int	idx;
 | 
			
		||||
 | 
			
		||||
	if (s == NULL)
 | 
			
		||||
		s = c->session;
 | 
			
		||||
@@ -422,8 +423,10 @@ status_replace1(struct client *c, struct session *s, struct winlink *wl,
 | 
			
		||||
		ptr = tmp;
 | 
			
		||||
		goto do_replace;
 | 
			
		||||
	case 'P':
 | 
			
		||||
		if (window_pane_index(wp, &idx) != 0)
 | 
			
		||||
			fatalx("index not found");
 | 
			
		||||
		xsnprintf(
 | 
			
		||||
		    tmp, sizeof tmp, "%u", window_pane_index(wl->window, wp));
 | 
			
		||||
		    tmp, sizeof tmp, "%u", idx);
 | 
			
		||||
		ptr = tmp;
 | 
			
		||||
		goto do_replace;
 | 
			
		||||
	case 'S':
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1931,7 +1931,7 @@ struct window_pane *window_pane_next_by_number(struct window *,
 | 
			
		||||
		        struct window_pane *, u_int);
 | 
			
		||||
struct window_pane *window_pane_previous_by_number(struct window *,
 | 
			
		||||
		        struct window_pane *, u_int);
 | 
			
		||||
u_int		 window_pane_index(struct window *, struct window_pane *);
 | 
			
		||||
int		 window_pane_index(struct window_pane *, u_int *);
 | 
			
		||||
u_int		 window_count_panes(struct window *);
 | 
			
		||||
void		 window_destroy_panes(struct window *);
 | 
			
		||||
struct window_pane *window_pane_find_by_id(u_int);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								window.c
									
									
									
									
									
								
							@@ -486,19 +486,21 @@ window_pane_previous_by_number(struct window *w, struct window_pane *wp,
 | 
			
		||||
	return (wp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
u_int
 | 
			
		||||
window_pane_index(struct window *w, struct window_pane *wp)
 | 
			
		||||
int
 | 
			
		||||
window_pane_index(struct window_pane *wp, u_int *i)
 | 
			
		||||
{
 | 
			
		||||
	struct window_pane	*wq;
 | 
			
		||||
	u_int			 n;
 | 
			
		||||
	struct window		*w = wp->window;
 | 
			
		||||
 | 
			
		||||
	n = options_get_number(&w->options, "pane-base-index");
 | 
			
		||||
	*i = options_get_number(&w->options, "pane-base-index");
 | 
			
		||||
	TAILQ_FOREACH(wq, &w->panes, entry) {
 | 
			
		||||
		if (wp == wq)
 | 
			
		||||
			break;
 | 
			
		||||
		n++;
 | 
			
		||||
		if (wp == wq) {
 | 
			
		||||
			return (0);
 | 
			
		||||
		}
 | 
			
		||||
	return (n);
 | 
			
		||||
		(*i)++;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return (-1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
u_int
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user