mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:44:18 +00:00 
			
		
		
		
	find-window command.
This commit is contained in:
		
							
								
								
									
										6
									
								
								CHANGES
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								CHANGES
									
									
									
									
									
								
							@@ -1,5 +1,9 @@
 | 
				
			|||||||
18 January 2009
 | 
					18 January 2009
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* find-window command to search window names, titles and visible content (but
 | 
				
			||||||
 | 
					  not history) for a string. If only one is found, the window is selected
 | 
				
			||||||
 | 
					  otherwise a choice list is shown. This (as with the other choice commands)
 | 
				
			||||||
 | 
					  only works from a key. Bound to "f" by default.
 | 
				
			||||||
* Cleaned up command printing code, also enclose arguments with spaces in "s.
 | 
					* Cleaned up command printing code, also enclose arguments with spaces in "s.
 | 
				
			||||||
* Added command sequences. These are entered by separating each argument by a ;
 | 
					* Added command sequences. These are entered by separating each argument by a ;
 | 
				
			||||||
  argument (spaces on both sides), for example:
 | 
					  argument (spaces on both sides), for example:
 | 
				
			||||||
@@ -951,7 +955,7 @@
 | 
				
			|||||||
  (including mutt, emacs). No status bar yet and no key remapping or other
 | 
					  (including mutt, emacs). No status bar yet and no key remapping or other
 | 
				
			||||||
  customisation.
 | 
					  customisation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$Id: CHANGES,v 1.217 2009-01-18 14:40:48 nicm Exp $
 | 
					$Id: CHANGES,v 1.218 2009-01-18 17:20:52 nicm Exp $
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 LocalWords:  showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
 | 
					 LocalWords:  showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
 | 
				
			||||||
 LocalWords:  rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
 | 
					 LocalWords:  rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
# $Id: GNUmakefile,v 1.61 2009-01-18 15:57:28 tcunha Exp $
 | 
					# $Id: GNUmakefile,v 1.62 2009-01-18 17:20:52 nicm Exp $
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean
 | 
					.PHONY: clean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -36,11 +36,11 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
 | 
				
			|||||||
      cmd-save-buffer.c cmd-select-pane.c cmd-split-window.c \
 | 
					      cmd-save-buffer.c cmd-select-pane.c cmd-split-window.c \
 | 
				
			||||||
      cmd-resize-pane-up.c cmd-resize-pane-down.c cmd-kill-pane.c \
 | 
					      cmd-resize-pane-up.c cmd-resize-pane-down.c cmd-kill-pane.c \
 | 
				
			||||||
      cmd-up-pane.c cmd-down-pane.c cmd-choose-window.c cmd-choose-session.c \
 | 
					      cmd-up-pane.c cmd-down-pane.c cmd-choose-window.c cmd-choose-session.c \
 | 
				
			||||||
      cmd-suspend-client.c \
 | 
					      cmd-suspend-client.c cmd-find-window.c \
 | 
				
			||||||
      window-clock.c window-scroll.c window-more.c window-copy.c \
 | 
					      window-clock.c window-scroll.c window-more.c window-copy.c \
 | 
				
			||||||
      window-choose.c \
 | 
					      window-choose.c \
 | 
				
			||||||
      options.c options-cmd.c paste.c colour.c utf8.c clock.c \
 | 
					      options.c options-cmd.c paste.c colour.c utf8.c clock.c \
 | 
				
			||||||
      tty.c tty-term.c tty-keys.c tty-write.c
 | 
					      tty.c tty-term.c tty-keys.c tty-write.c util.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CC?= gcc
 | 
					CC?= gcc
 | 
				
			||||||
INCDIRS+= -I. -I-
 | 
					INCDIRS+= -I. -I-
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								Makefile
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
# $Id: Makefile,v 1.101 2009-01-18 15:57:28 tcunha Exp $
 | 
					# $Id: Makefile,v 1.102 2009-01-18 17:20:52 nicm Exp $
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.SUFFIXES: .c .o .y .h
 | 
					.SUFFIXES: .c .o .y .h
 | 
				
			||||||
.PHONY: clean update-index.html upload-index.html
 | 
					.PHONY: clean update-index.html upload-index.html
 | 
				
			||||||
@@ -40,11 +40,11 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
 | 
				
			|||||||
      cmd-save-buffer.c cmd-select-pane.c cmd-split-window.c \
 | 
					      cmd-save-buffer.c cmd-select-pane.c cmd-split-window.c \
 | 
				
			||||||
      cmd-resize-pane-up.c cmd-resize-pane-down.c cmd-kill-pane.c \
 | 
					      cmd-resize-pane-up.c cmd-resize-pane-down.c cmd-kill-pane.c \
 | 
				
			||||||
      cmd-up-pane.c cmd-down-pane.c cmd-choose-window.c cmd-choose-session.c \
 | 
					      cmd-up-pane.c cmd-down-pane.c cmd-choose-window.c cmd-choose-session.c \
 | 
				
			||||||
      cmd-suspend-client.c \
 | 
					      cmd-suspend-client.c cmd-find-window.c \
 | 
				
			||||||
      window-clock.c window-scroll.c window-more.c window-copy.c \
 | 
					      window-clock.c window-scroll.c window-more.c window-copy.c \
 | 
				
			||||||
      window-choose.c \
 | 
					      window-choose.c \
 | 
				
			||||||
      options.c options-cmd.c paste.c colour.c utf8.c clock.c \
 | 
					      options.c options-cmd.c paste.c colour.c utf8.c clock.c \
 | 
				
			||||||
      tty.c tty-term.c tty-keys.c tty-write.c
 | 
					      tty.c tty-term.c tty-keys.c tty-write.c util.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CC?= cc
 | 
					CC?= cc
 | 
				
			||||||
INCDIRS+= -I. -I- -I/usr/local/include
 | 
					INCDIRS+= -I. -I- -I/usr/local/include
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								NOTES
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								NOTES
									
									
									
									
									
								
							@@ -99,4 +99,4 @@ welcome. Please email:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
-- Nicholas Marriott <nicm@users.sf.net>
 | 
					-- Nicholas Marriott <nicm@users.sf.net>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$Id: NOTES,v 1.41 2009-01-18 15:55:33 tcunha Exp $
 | 
					$Id: NOTES,v 1.42 2009-01-18 17:20:52 nicm Exp $
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								TODO
									
									
									
									
									
								
							@@ -79,3 +79,7 @@
 | 
				
			|||||||
- document command sequences
 | 
					- document command sequences
 | 
				
			||||||
- make command sequences more usable: don't require space around ;, handle
 | 
					- make command sequences more usable: don't require space around ;, handle
 | 
				
			||||||
  errors better
 | 
					  errors better
 | 
				
			||||||
 | 
					- -a and -b flags to next/previous window to jump to next window with activity 
 | 
				
			||||||
 | 
					  or bell
 | 
				
			||||||
 | 
					- document find-window
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: cmd-choose-session.c,v 1.3 2009-01-18 12:13:21 nicm Exp $ */
 | 
					/* $Id: cmd-choose-session.c,v 1.4 2009-01-18 17:20:52 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -61,7 +61,7 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
		return;
 | 
							return;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
 | 
						if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
 | 
				
			||||||
		return;
 | 
							goto out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cur = idx = 0;
 | 
						cur = idx = 0;
 | 
				
			||||||
	for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
 | 
						for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
 | 
				
			||||||
@@ -84,6 +84,7 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	window_choose_ready(
 | 
						window_choose_ready(
 | 
				
			||||||
	    wl->window->active, cur, cmd_choose_session_callback, cdata);
 | 
						    wl->window->active, cur, cmd_choose_session_callback, cdata);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
	if (ctx->cmdclient != NULL)
 | 
						if (ctx->cmdclient != NULL)
 | 
				
			||||||
		server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
 | 
							server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: cmd-choose-window.c,v 1.4 2009-01-17 18:47:36 nicm Exp $ */
 | 
					/* $Id: cmd-choose-window.c,v 1.5 2009-01-18 17:20:52 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -21,7 +21,7 @@
 | 
				
			|||||||
#include "tmux.h"
 | 
					#include "tmux.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Enter choice mode to chosoe a window.
 | 
					 * Enter choice mode to choose a window.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void	cmd_choose_window_exec(struct cmd *, struct cmd_ctx *);
 | 
					void	cmd_choose_window_exec(struct cmd *, struct cmd_ctx *);
 | 
				
			||||||
@@ -62,7 +62,7 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
		return;
 | 
							return;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
 | 
						if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
 | 
				
			||||||
		return;
 | 
							goto out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cur = idx = 0;
 | 
						cur = idx = 0;
 | 
				
			||||||
	RB_FOREACH(wm, winlinks, &s->windows) {
 | 
						RB_FOREACH(wm, winlinks, &s->windows) {
 | 
				
			||||||
@@ -73,8 +73,8 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
		idx++;
 | 
							idx++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		window_choose_add(wl->window->active,
 | 
							window_choose_add(wl->window->active,
 | 
				
			||||||
		    wm->idx, "%3d: %s [%ux%u] (%u panes)", wm->idx, w->name, w->sx, w->sy,
 | 
							    wm->idx, "%3d: %s [%ux%u] (%u panes)", wm->idx, w->name,
 | 
				
			||||||
		    window_count_panes(w));
 | 
							    w->sx, w->sy, window_count_panes(w));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cdata = xmalloc(sizeof *cdata);
 | 
						cdata = xmalloc(sizeof *cdata);
 | 
				
			||||||
@@ -84,6 +84,7 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	window_choose_ready(
 | 
						window_choose_ready(
 | 
				
			||||||
	    wl->window->active, cur, cmd_choose_window_callback, cdata);
 | 
						    wl->window->active, cur, cmd_choose_window_callback, cdata);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
	if (ctx->cmdclient != NULL)
 | 
						if (ctx->cmdclient != NULL)
 | 
				
			||||||
		server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
 | 
							server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: cmd-command-prompt.c,v 1.10 2009-01-18 14:40:48 nicm Exp $ */
 | 
					/* $Id: cmd-command-prompt.c,v 1.11 2009-01-18 17:20:52 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -62,6 +62,9 @@ cmd_command_prompt_init(struct cmd *self, int key)
 | 
				
			|||||||
	case ',':
 | 
						case ',':
 | 
				
			||||||
		data->arg = xstrdup("rename-window '%%'");
 | 
							data->arg = xstrdup("rename-window '%%'");
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
						case 'f':
 | 
				
			||||||
 | 
							data->arg = xstrdup("find-window '%%'");
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										198
									
								
								cmd-find-window.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										198
									
								
								cmd-find-window.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,198 @@
 | 
				
			|||||||
 | 
					/* $Id: cmd-find-window.c,v 1.1 2009-01-18 17:20:52 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Permission to use, copy, modify, and distribute this software for any
 | 
				
			||||||
 | 
					 * purpose with or without fee is hereby granted, provided that the above
 | 
				
			||||||
 | 
					 * copyright notice and this permission notice appear in all copies.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 | 
				
			||||||
 | 
					 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 | 
				
			||||||
 | 
					 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 | 
				
			||||||
 | 
					 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 | 
				
			||||||
 | 
					 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
 | 
				
			||||||
 | 
					 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 | 
				
			||||||
 | 
					 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sys/types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "tmux.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Find window containing text.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void	cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void	cmd_find_window_callback(void *, int);
 | 
				
			||||||
 | 
					char   *cmd_find_window_search(struct window_pane *, const char *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const struct cmd_entry cmd_find_window_entry = {
 | 
				
			||||||
 | 
						"find-window", NULL,
 | 
				
			||||||
 | 
						CMD_TARGET_WINDOW_USAGE,
 | 
				
			||||||
 | 
						CMD_ARG1,
 | 
				
			||||||
 | 
						cmd_target_init,
 | 
				
			||||||
 | 
						cmd_target_parse,
 | 
				
			||||||
 | 
						cmd_find_window_exec,
 | 
				
			||||||
 | 
						cmd_target_send,
 | 
				
			||||||
 | 
						cmd_target_recv,
 | 
				
			||||||
 | 
						cmd_target_free,
 | 
				
			||||||
 | 
						cmd_target_print
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct cmd_find_window_data {
 | 
				
			||||||
 | 
						u_int	session;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct cmd_target_data		*data = self->data;
 | 
				
			||||||
 | 
						struct cmd_find_window_data	*cdata;
 | 
				
			||||||
 | 
						struct session			*s = ctx->curclient->session;
 | 
				
			||||||
 | 
						struct winlink			*wl, *wm;
 | 
				
			||||||
 | 
						struct window			*w;
 | 
				
			||||||
 | 
						struct window_pane		*wp;
 | 
				
			||||||
 | 
						ARRAY_DECL(, u_int)	 	 list_idx;
 | 
				
			||||||
 | 
						ARRAY_DECL(, char *)	 	 list_ctx;
 | 
				
			||||||
 | 
						char				*sres, *sctx;
 | 
				
			||||||
 | 
						u_int				 i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (ctx->curclient == NULL)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						ARRAY_INIT(&list_idx);
 | 
				
			||||||
 | 
						ARRAY_INIT(&list_ctx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						RB_FOREACH(wm, winlinks, &s->windows) {
 | 
				
			||||||
 | 
							i = 0;
 | 
				
			||||||
 | 
							TAILQ_FOREACH(wp, &wm->window->panes, entry) {
 | 
				
			||||||
 | 
								i++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (strstr(wm->window->name, data->arg) != NULL)
 | 
				
			||||||
 | 
									sctx = xstrdup("");
 | 
				
			||||||
 | 
								else {
 | 
				
			||||||
 | 
									sres = cmd_find_window_search(wp, data->arg);
 | 
				
			||||||
 | 
									if (sres == NULL &&
 | 
				
			||||||
 | 
									    strstr(wp->base.title, data->arg) == NULL)
 | 
				
			||||||
 | 
										continue;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (sres == NULL) {
 | 
				
			||||||
 | 
										xasprintf(&sctx,
 | 
				
			||||||
 | 
										    "pane %u title: \"%s\"", i - 1,
 | 
				
			||||||
 | 
										    wp->base.title);
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										xasprintf(&sctx, "\"%s\"", sres);
 | 
				
			||||||
 | 
										xfree(sres);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
								ARRAY_ADD(&list_idx, wm->idx);
 | 
				
			||||||
 | 
								ARRAY_ADD(&list_ctx, sctx);			
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (ARRAY_LENGTH(&list_idx) == 0) {
 | 
				
			||||||
 | 
							ctx->error(ctx, "no windows matching: %s", data->arg);
 | 
				
			||||||
 | 
							ARRAY_FREE(&list_idx);
 | 
				
			||||||
 | 
							ARRAY_FREE(&list_ctx);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (ARRAY_LENGTH(&list_idx) == 1) {
 | 
				
			||||||
 | 
							if (session_select(s, ARRAY_FIRST(&list_idx)) == 0)
 | 
				
			||||||
 | 
								server_redraw_session(s);
 | 
				
			||||||
 | 
							recalculate_sizes();
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < ARRAY_LENGTH(&list_idx); i++) {
 | 
				
			||||||
 | 
							wm = winlink_find_by_index(
 | 
				
			||||||
 | 
							    &s->windows, ARRAY_ITEM(&list_idx, i));
 | 
				
			||||||
 | 
							w = wm->window;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							sctx = ARRAY_ITEM(&list_ctx, i);
 | 
				
			||||||
 | 
							window_choose_add(wl->window->active,
 | 
				
			||||||
 | 
							    wm->idx, "%3d: %s [%ux%u] (%u panes) %s", wm->idx, w->name,
 | 
				
			||||||
 | 
							    w->sx, w->sy, window_count_panes(w), sctx);
 | 
				
			||||||
 | 
							xfree(sctx);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cdata = xmalloc(sizeof *cdata);
 | 
				
			||||||
 | 
						if (session_index(s, &cdata->session) != 0)
 | 
				
			||||||
 | 
							fatalx("session not found");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						window_choose_ready(
 | 
				
			||||||
 | 
						    wl->window->active, 0, cmd_find_window_callback, cdata);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
 | 
						ARRAY_FREE(&list_idx);
 | 
				
			||||||
 | 
						ARRAY_FREE(&list_ctx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (ctx->cmdclient != NULL)
 | 
				
			||||||
 | 
							server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					cmd_find_window_callback(void *data, int idx)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct cmd_find_window_data	*cdata = data;
 | 
				
			||||||
 | 
						struct session			*s;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (idx != -1 && cdata->session <= ARRAY_LENGTH(&sessions) - 1) {
 | 
				
			||||||
 | 
							s = ARRAY_ITEM(&sessions, cdata->session);
 | 
				
			||||||
 | 
							if (s != NULL && session_select(s, idx) == 0)
 | 
				
			||||||
 | 
								server_redraw_session(s);
 | 
				
			||||||
 | 
							recalculate_sizes();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						xfree(cdata);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *
 | 
				
			||||||
 | 
					cmd_find_window_search(struct window_pane *wp, const char *searchstr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char			*buf, *s;
 | 
				
			||||||
 | 
						size_t			 off;
 | 
				
			||||||
 | 
						const struct grid_cell	*gc;
 | 
				
			||||||
 | 
						u_int			 i, j, k;
 | 
				
			||||||
 | 
						u_char			 data[4];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						buf = xmalloc(1);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
						for (j = 0; j < screen_size_y(&wp->base); j++) {
 | 
				
			||||||
 | 
							off = 0;
 | 
				
			||||||
 | 
							for (i = 0; i < screen_size_x(&wp->base); i++) {
 | 
				
			||||||
 | 
								gc = grid_view_peek_cell(wp->base.grid, i, j);
 | 
				
			||||||
 | 
								utf8_split(gc->data, data);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								buf = xrealloc(buf, 1, off + 4);
 | 
				
			||||||
 | 
								for (k = 0; k < sizeof data; k++) {
 | 
				
			||||||
 | 
									if (data[k] == 0xff)
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									buf[off++] = data[k];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							while (off > 0 && buf[off - 1] == ' ')
 | 
				
			||||||
 | 
								off--;
 | 
				
			||||||
 | 
							buf[off] = '\0';
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if ((s = strstr(buf, searchstr)) != NULL) {
 | 
				
			||||||
 | 
								s = section_string(buf, off, s - buf, 40);
 | 
				
			||||||
 | 
								xfree(buf);
 | 
				
			||||||
 | 
								return (s);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						xfree(buf);
 | 
				
			||||||
 | 
						return (NULL);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: cmd-list-buffers.c,v 1.5 2009-01-07 19:52:36 nicm Exp $ */
 | 
					/* $Id: cmd-list-buffers.c,v 1.6 2009-01-18 17:20:52 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -78,8 +78,8 @@ cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
				tmp[out - 3] = '.';
 | 
									tmp[out - 3] = '.';
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			ctx->print(ctx, "%d: "
 | 
								ctx->print(ctx, "%d: %zu bytes: \"%s\"",
 | 
				
			||||||
			    "%zu bytes: \"%s\"", idx - 1, strlen(pb->data), tmp);
 | 
								    idx - 1, strlen(pb->data), tmp);
 | 
				
			||||||
		} else
 | 
							} else
 | 
				
			||||||
			ctx->print(ctx, "%d: %zu bytes", idx, strlen(pb->data));
 | 
								ctx->print(ctx, "%d: %zu bytes", idx, strlen(pb->data));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								cmd.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								cmd.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: cmd.c,v 1.81 2009-01-18 14:40:48 nicm Exp $ */
 | 
					/* $Id: cmd.c,v 1.82 2009-01-18 17:20:52 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -36,6 +36,7 @@ const struct cmd_entry *cmd_table[] = {
 | 
				
			|||||||
	&cmd_delete_buffer_entry,
 | 
						&cmd_delete_buffer_entry,
 | 
				
			||||||
	&cmd_detach_client_entry,
 | 
						&cmd_detach_client_entry,
 | 
				
			||||||
	&cmd_down_pane_entry,
 | 
						&cmd_down_pane_entry,
 | 
				
			||||||
 | 
						&cmd_find_window_entry,
 | 
				
			||||||
	&cmd_has_session_entry,
 | 
						&cmd_has_session_entry,
 | 
				
			||||||
	&cmd_kill_pane_entry,
 | 
						&cmd_kill_pane_entry,
 | 
				
			||||||
	&cmd_kill_server_entry,
 | 
						&cmd_kill_server_entry,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: key-bindings.c,v 1.55 2009-01-18 14:40:48 nicm Exp $ */
 | 
					/* $Id: key-bindings.c,v 1.56 2009-01-18 17:20:52 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -100,6 +100,7 @@ key_bindings_init(void)
 | 
				
			|||||||
		{ ']', &cmd_paste_buffer_entry },
 | 
							{ ']', &cmd_paste_buffer_entry },
 | 
				
			||||||
		{ 'c', &cmd_new_window_entry },
 | 
							{ 'c', &cmd_new_window_entry },
 | 
				
			||||||
		{ 'd', &cmd_detach_client_entry },
 | 
							{ 'd', &cmd_detach_client_entry },
 | 
				
			||||||
 | 
							{ 'f', &cmd_command_prompt_entry },
 | 
				
			||||||
		{ 'l', &cmd_last_window_entry },
 | 
							{ 'l', &cmd_last_window_entry },
 | 
				
			||||||
		{ 'n', &cmd_next_window_entry },
 | 
							{ 'n', &cmd_next_window_entry },
 | 
				
			||||||
		{ 'o', &cmd_down_pane_entry },
 | 
							{ 'o', &cmd_down_pane_entry },
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: tmux.h,v 1.238 2009-01-18 14:40:48 nicm Exp $ */
 | 
					/* $Id: tmux.h,v 1.239 2009-01-18 17:20:52 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -1102,6 +1102,7 @@ extern const struct cmd_entry cmd_copy_mode_entry;
 | 
				
			|||||||
extern const struct cmd_entry cmd_delete_buffer_entry;
 | 
					extern const struct cmd_entry cmd_delete_buffer_entry;
 | 
				
			||||||
extern const struct cmd_entry cmd_detach_client_entry;
 | 
					extern const struct cmd_entry cmd_detach_client_entry;
 | 
				
			||||||
extern const struct cmd_entry cmd_down_pane_entry;
 | 
					extern const struct cmd_entry cmd_down_pane_entry;
 | 
				
			||||||
 | 
					extern const struct cmd_entry cmd_find_window_entry;
 | 
				
			||||||
extern const struct cmd_entry cmd_has_session_entry;
 | 
					extern const struct cmd_entry cmd_has_session_entry;
 | 
				
			||||||
extern const struct cmd_entry cmd_kill_pane_entry;
 | 
					extern const struct cmd_entry cmd_kill_pane_entry;
 | 
				
			||||||
extern const struct cmd_entry cmd_kill_server_entry;
 | 
					extern const struct cmd_entry cmd_kill_server_entry;
 | 
				
			||||||
@@ -1488,6 +1489,9 @@ u_int	utf8_combine(const u_char *);
 | 
				
			|||||||
void	utf8_split(u_int, u_char *);
 | 
					void	utf8_split(u_int, u_char *);
 | 
				
			||||||
int	utf8_width(u_int);
 | 
					int	utf8_width(u_int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* util.c */
 | 
				
			||||||
 | 
					char   *section_string(char *, size_t, size_t, size_t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* buffer.c */
 | 
					/* buffer.c */
 | 
				
			||||||
struct buffer 	*buffer_create(size_t);
 | 
					struct buffer 	*buffer_create(size_t);
 | 
				
			||||||
void		 buffer_destroy(struct buffer *);
 | 
					void		 buffer_destroy(struct buffer *);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										52
									
								
								util.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								util.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					/* $Id: util.c,v 1.1 2009-01-18 17:20:52 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Permission to use, copy, modify, and distribute this software for any
 | 
				
			||||||
 | 
					 * purpose with or without fee is hereby granted, provided that the above
 | 
				
			||||||
 | 
					 * copyright notice and this permission notice appear in all copies.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 | 
				
			||||||
 | 
					 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 | 
				
			||||||
 | 
					 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 | 
				
			||||||
 | 
					 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 | 
				
			||||||
 | 
					 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
 | 
				
			||||||
 | 
					 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 | 
				
			||||||
 | 
					 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sys/types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "tmux.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Return a section of a string around a point. */
 | 
				
			||||||
 | 
					char *
 | 
				
			||||||
 | 
					section_string(char *buf, size_t len, size_t sectoff, size_t sectlen)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char	*s;
 | 
				
			||||||
 | 
						size_t	 first, last;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (len <= sectlen) {
 | 
				
			||||||
 | 
							first = 0;
 | 
				
			||||||
 | 
							last = len;
 | 
				
			||||||
 | 
						} else if (sectoff < sectlen / 2) {
 | 
				
			||||||
 | 
							first = 0;
 | 
				
			||||||
 | 
							last = sectlen;
 | 
				
			||||||
 | 
						} else if (sectoff + sectlen / 2 > len) {
 | 
				
			||||||
 | 
							last = len;
 | 
				
			||||||
 | 
							first = last - sectlen;
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							first = sectoff - sectlen / 2;
 | 
				
			||||||
 | 
							last = first + sectlen;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (last - first > 3 && first != 0)
 | 
				
			||||||
 | 
							first += 3;
 | 
				
			||||||
 | 
						if (last - first > 3 && last != len)
 | 
				
			||||||
 | 
							last -= 3;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						xasprintf(&s, "%s%.*s%s", first == 0 ? "" : "...",
 | 
				
			||||||
 | 
						    (int) (last - first), buf + first, last == len ? "" : "...");
 | 
				
			||||||
 | 
						return (s);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: window-choose.c,v 1.2 2009-01-15 19:28:36 nicm Exp $ */
 | 
					/* $Id: window-choose.c,v 1.3 2009-01-18 17:20:52 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -149,6 +149,7 @@ window_choose_key(struct window_pane *wp, unused struct client *c, int key)
 | 
				
			|||||||
	struct window_choose_mode_data	*data = wp->modedata;
 | 
						struct window_choose_mode_data	*data = wp->modedata;
 | 
				
			||||||
	struct screen			*s = &data->screen;
 | 
						struct screen			*s = &data->screen;
 | 
				
			||||||
	struct screen_write_ctx		 ctx;
 | 
						struct screen_write_ctx		 ctx;
 | 
				
			||||||
 | 
						struct window_choose_mode_item	*item;
 | 
				
			||||||
	int				 table;
 | 
						int				 table;
 | 
				
			||||||
	u_int				 items;
 | 
						u_int				 items;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -161,7 +162,8 @@ window_choose_key(struct window_pane *wp, unused struct client *c, int key)
 | 
				
			|||||||
		window_pane_reset_mode(wp);
 | 
							window_pane_reset_mode(wp);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case MODEKEY_ENTER:
 | 
						case MODEKEY_ENTER:
 | 
				
			||||||
		data->callback(data->data, data->selected);
 | 
							item = &ARRAY_ITEM(&data->list, data->selected);
 | 
				
			||||||
 | 
							data->callback(data->data, item->idx);
 | 
				
			||||||
		window_pane_reset_mode(wp);
 | 
							window_pane_reset_mode(wp);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case MODEKEY_UP:
 | 
						case MODEKEY_UP:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user