diff options
-rw-r--r-- | Makefile.am | 7 | ||||
-rw-r--r-- | arguments.c | 3 | ||||
-rw-r--r-- | cfg.c | 2 | ||||
-rw-r--r-- | cmd-choose-buffer.c | 101 | ||||
-rw-r--r-- | cmd-choose-client.c | 135 | ||||
-rw-r--r-- | cmd-choose-tree.c | 219 | ||||
-rw-r--r-- | cmd-copy-mode.c | 6 | ||||
-rw-r--r-- | cmd-find-window.c | 247 | ||||
-rw-r--r-- | cmd-queue.c | 3 | ||||
-rw-r--r-- | cmd-run-shell.c | 2 | ||||
-rw-r--r-- | cmd-split-window.c | 3 | ||||
-rw-r--r-- | cmd.c | 4 | ||||
-rw-r--r-- | format.c | 4 | ||||
-rw-r--r-- | key-bindings.c | 4 | ||||
-rw-r--r-- | mode-tree.c | 705 | ||||
-rw-r--r-- | options-table.c | 6 | ||||
-rw-r--r-- | screen-write.c | 118 | ||||
-rw-r--r-- | server-client.c | 53 | ||||
-rw-r--r-- | tmux.1 | 197 | ||||
-rw-r--r-- | tmux.h | 240 | ||||
-rw-r--r-- | tty-term.c | 20 | ||||
-rw-r--r-- | tty.c | 42 | ||||
-rw-r--r-- | window-buffer.c | 342 | ||||
-rw-r--r-- | window-choose.c | 1078 | ||||
-rw-r--r-- | window-client.c | 335 | ||||
-rw-r--r-- | window-clock.c | 6 | ||||
-rw-r--r-- | window-copy.c | 6 | ||||
-rw-r--r-- | window-tree.c | 713 | ||||
-rw-r--r-- | window.c | 35 |
29 files changed, 2621 insertions, 2015 deletions
diff --git a/Makefile.am b/Makefile.am index b2464030..14afb628 100644 --- a/Makefile.am +++ b/Makefile.am @@ -66,8 +66,6 @@ dist_tmux_SOURCES = \ cmd-bind-key.c \ cmd-break-pane.c \ cmd-capture-pane.c \ - cmd-choose-buffer.c \ - cmd-choose-client.c \ cmd-choose-tree.c \ cmd-command-prompt.c \ cmd-confirm-before.c \ @@ -145,6 +143,7 @@ dist_tmux_SOURCES = \ layout-set.c \ layout.c \ log.c \ + mode-tree.c \ names.c \ notify.c \ options-table.c \ @@ -169,9 +168,11 @@ dist_tmux_SOURCES = \ tty-term.c \ tty.c \ utf8.c \ - window-choose.c \ + window-buffer.c \ + window-client.c \ window-clock.c \ window-copy.c \ + window-tree.c \ window.c \ xmalloc.c \ xmalloc.h \ diff --git a/arguments.c b/arguments.c index e70d24c0..50536a47 100644 --- a/arguments.c +++ b/arguments.c @@ -34,7 +34,6 @@ struct args_entry { RB_ENTRY(args_entry) entry; }; -static void args_set(struct args *, u_char, const char *); static struct args_entry *args_find(struct args *, u_char); static int args_cmp(struct args_entry *, struct args_entry *); @@ -195,7 +194,7 @@ args_has(struct args *args, u_char ch) } /* Set argument value in the arguments tree. */ -static void +void args_set(struct args *args, u_char ch, const char *value) { struct args_entry *entry; @@ -233,7 +233,7 @@ cfg_show_causes(struct session *s) return; wp = s->curw->window->active; - window_pane_set_mode(wp, &window_copy_mode); + window_pane_set_mode(wp, &window_copy_mode, NULL, NULL); window_copy_init_for_output(wp); for (i = 0; i < cfg_ncauses; i++) { window_copy_add(wp, "%s", cfg_causes[i]); diff --git a/cmd-choose-buffer.c b/cmd-choose-buffer.c deleted file mode 100644 index 52ad0ac1..00000000 --- a/cmd-choose-buffer.c +++ /dev/null @@ -1,101 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com> - * - * 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 <ctype.h> -#include <stdlib.h> - -#include "tmux.h" - -/* - * Enter choice mode to choose a buffer. - */ - -#define CHOOSE_BUFFER_TEMPLATE \ - "#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}" - -static enum cmd_retval cmd_choose_buffer_exec(struct cmd *, - struct cmdq_item *); - -const struct cmd_entry cmd_choose_buffer_entry = { - .name = "choose-buffer", - .alias = NULL, - - .args = { "F:t:", 0, 1 }, - .usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]", - - .target = { 't', CMD_FIND_WINDOW, 0 }, - - .flags = 0, - .exec = cmd_choose_buffer_exec -}; - -static enum cmd_retval -cmd_choose_buffer_exec(struct cmd *self, struct cmdq_item *item) -{ - struct args *args = self->args; - struct client *c = cmd_find_client(item, NULL, 1); - struct winlink *wl = item->target.wl; - struct window_choose_data *cdata; - struct paste_buffer *pb; - char *action, *action_data; - const char *template; - u_int idx; - - if (c == NULL) { - cmdq_error(item, "no client available"); - return (CMD_RETURN_ERROR); - } - - if ((template = args_get(args, 'F')) == NULL) - template = CHOOSE_BUFFER_TEMPLATE; - - if (paste_get_top(NULL) == NULL) - return (CMD_RETURN_NORMAL); - - if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0) - return (CMD_RETURN_NORMAL); - - if (args->argc != 0) - action = xstrdup(args->argv[0]); - else - action = xstrdup("paste-buffer -b '%%'"); - - idx = 0; - pb = NULL; - while ((pb = paste_walk(pb)) != NULL) { - cdata = window_choose_data_create(TREE_OTHER, c, c->session); - cdata->idx = idx; - - cdata->ft_template = xstrdup(template); - format_defaults_paste_buffer(cdata->ft, pb); - - xasprintf(&action_data, "%s", paste_buffer_name(pb)); - cdata->command = cmd_template_replace(action, action_data, 1); - free(action_data); - - window_choose_add(wl->window->active, cdata); - idx++; - } - free(action); - - window_choose_ready(wl->window->active, 0, NULL); - - return (CMD_RETURN_NORMAL); -} diff --git a/cmd-choose-client.c b/cmd-choose-client.c deleted file mode 100644 index 88118209..00000000 --- a/cmd-choose-client.c +++ /dev/null @@ -1,135 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> - * - * 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 <ctype.h> -#include <stdlib.h> - -#include "tmux.h" - -/* - * Enter choice mode to choose a client. - */ - -#define CHOOSE_CLIENT_TEMPLATE \ - "#{client_name}: #{session_name} " \ - "[#{client_width}x#{client_height} #{client_termname}]" \ - "#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \ - "(last used #{t:client_activity})" - -static enum cmd_retval cmd_choose_client_exec(struct cmd *, - struct cmdq_item *); - -static void cmd_choose_client_callback(struct window_choose_data *); - -const struct cmd_entry cmd_choose_client_entry = { - .name = "choose-client", - .alias = NULL, - - .args = { "F:t:", 0, 1 }, - .usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]", - - .target = { 't', CMD_FIND_WINDOW, 0 }, - - .flags = 0, - .exec = cmd_choose_client_exec -}; - -struct cmd_choose_client_data { - struct client *client; -}; - -static enum cmd_retval -cmd_choose_client_exec(struct cmd *self, struct cmdq_item *item) -{ - struct args *args = self->args; - struct client *c = cmd_find_client(item, NULL, 1); - struct client *c1; - struct window_choose_data *cdata; - struct winlink *wl = item->target.wl; - const char *template; - char *action; - u_int idx, cur; - - if (c == NULL) { - cmdq_error(item, "no client available"); - return (CMD_RETURN_ERROR); - } - - if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0) - return (CMD_RETURN_NORMAL); - - if ((template = args_get(args, 'F')) == NULL) - template = CHOOSE_CLIENT_TEMPLATE; - - if (args->argc != 0) - action = xstrdup(args->argv[0]); - else - action = xstrdup("detach-client -t '%%'"); - - cur = idx = 0; - TAILQ_FOREACH(c1, &clients, entry) { - if (c1->session == NULL) - continue; - if (c1 == item->client) - cur = idx; - - cdata = window_choose_data_create(TREE_OTHER, c, c->session); - cdata->idx = idx; - - cdata->ft_template = xstrdup(template); - format_add(cdata->ft, "line", "%u", idx); - format_defaults(cdata->ft, c1, NULL, NULL, NULL); - - cdata->command = cmd_template_replace(action, c1->name, 1); - - window_choose_add(wl->window->active, cdata); - - idx++; - } - free(action); - - window_choose_ready(wl->window->active, cur, - cmd_choose_client_callback); - - return (CMD_RETURN_NORMAL); -} - -static void -cmd_choose_client_callback(struct window_choose_data *cdata) -{ - struct client *c; - u_int idx; - - if (cdata == NULL) - return; - if (cdata->start_client->flags & CLIENT_DEAD) - return; - - idx = 0; - TAILQ_FOREACH(c, &clients, entry) { - if (idx == cdata->idx) - break; - idx++; - } - if (c == NULL || c->session == NULL) - return; - - window_choose_data_run(cdata); -} diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c index 28b5013a..f8f24f12 100644 --- a/cmd-choose-tree.c +++ b/cmd-choose-tree.c @@ -18,66 +18,48 @@ #include <sys/types.h> -#include <ctype.h> -#include <stdlib.h> - -#include <string.h> - #include "tmux.h" -#define CMD_CHOOSE_TREE_WINDOW_ACTION "select-window -t '%%'" -#define CMD_CHOOSE_TREE_SESSION_ACTION "switch-client -t '%%'" - /* - * Enter choice mode to choose a session and/or window. + * Enter a mode. */ -#define CHOOSE_TREE_SESSION_TEMPLATE \ - "#{session_name}: #{session_windows} windows" \ - "#{?session_grouped, (group ,}" \ - "#{session_group}#{?session_grouped,),}" \ - "#{?session_attached, (attached),}" -#define CHOOSE_TREE_WINDOW_TEMPLATE \ - "#{window_index}: #{window_name}#{window_flags} " \ - "\"#{pane_title}\"" - static enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_choose_tree_entry = { .name = "choose-tree", .alias = NULL, - .args = { "S:W:swub:c:t:", 0, 1 }, - .usage = "[-suw] [-b session-template] [-c window template] " - "[-S format] [-W format] " CMD_TARGET_WINDOW_USAGE, + .args = { "st:w", 0, 1 }, + .usage = "[-sw] " CMD_TARGET_PANE_USAGE, - .target = { 't', CMD_FIND_WINDOW, 0 }, + .target = { 't', CMD_FIND_PANE, 0 }, .flags = 0, .exec = cmd_choose_tree_exec }; -const struct cmd_entry cmd_choose_session_entry = { - .name = "choose-session", +const struct cmd_entry cmd_choose_client_entry = { + .name = "choose-client", .alias = NULL, - .args = { "F:t:", 0, 1 }, - .usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]", + .args = { "t:", 0, 1 }, + .usage = CMD_TARGET_PANE_USAGE, - .target = { 't', CMD_FIND_WINDOW, 0 }, + .target = { 't', CMD_FIND_PANE, 0 }, .flags = 0, .exec = cmd_choose_tree_exec }; -const struct cmd_entry cmd_choose_window_entry = { - .name = "choose-window", +const struct cmd_entry cmd_choose_buffer_entry = { + .name = "choose-buffer", .alias = NULL, - .args = { "F:t:", 0, 1 }, - .usage = CMD_TARGET_WINDOW_USAGE "[-F format] [template]", + .args = { "t:", 0, 1 }, + .usage = CMD_TARGET_PANE_USAGE, - .target = { 't', CMD_FIND_WINDOW, 0 }, + .target = { 't', CMD_FIND_PANE, 0 }, .flags = 0, .exec = cmd_choose_tree_exec @@ -87,167 +69,20 @@ static enum cmd_retval cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmd_find_client(item, NULL, 1); - struct winlink *wl = item->target.wl, *wm; - struct session *s = item->target.s, *s2; - struct window_choose_data *wcd = NULL; - const char *ses_template, *win_template; - char *final_win_action, *cur_win_template; - char *final_win_template_middle; - char *final_win_template_last; - const char *ses_action, *win_action; - u_int cur_win, idx_ses, win_ses, win_max; - u_int wflag, sflag; - - ses_template = win_template = NULL; - ses_action = win_action = NULL; - - if (c == NULL) { - cmdq_error(item, "no client available"); - return (CMD_RETURN_ERROR); - } - - if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0) - return (CMD_RETURN_NORMAL); - - /* Sort out which command this is. */ - wflag = sflag = 0; - if (self->entry == &cmd_choose_session_entry) { - sflag = 1; - if ((ses_template = args_get(args, 'F')) == NULL) - ses_template = CHOOSE_TREE_SESSION_TEMPLATE; - - if (args->argc != 0) - ses_action = args->argv[0]; - else - ses_action = CMD_CHOOSE_TREE_SESSION_ACTION; - } else if (self->entry == &cmd_choose_window_entry) { - wflag = 1; - if ((win_template = args_get(args, 'F')) == NULL) - win_template = CHOOSE_TREE_WINDOW_TEMPLATE; - - if (args->argc != 0) - win_action = args->argv[0]; - else - win_action = CMD_CHOOSE_TREE_WINDOW_ACTION; - } else { - wflag = args_has(args, 'w'); - sflag = args_has(args, 's'); - - if ((ses_action = args_get(args, 'b')) == NULL) - ses_action = CMD_CHOOSE_TREE_SESSION_ACTION; - - if ((win_action = args_get(args, 'c')) == NULL) - win_action = CMD_CHOOSE_TREE_WINDOW_ACTION; - - if ((ses_template = args_get(args, 'S')) == NULL) - ses_template = CHOOSE_TREE_SESSION_TEMPLATE; - - if ((win_template = args_get(args, 'W')) == NULL) - win_template = CHOOSE_TREE_WINDOW_TEMPLATE; - } - - /* - * If not asking for windows and sessions, assume no "-ws" given and - * hence display the entire tree outright. - */ - if (!wflag && !sflag) - wflag = sflag = 1; - - /* - * If we're drawing in tree mode, including sessions, then pad the - * window template, otherwise just render the windows as a flat list - * without any padding. - */ - if (wflag && sflag) { - xasprintf(&final_win_template_middle, - " \001tq\001> %s", win_template); - xasprintf(&final_win_template_last, - " \001mq\001> %s", win_template); - } else if (wflag) { - final_win_template_middle = xstrdup(win_template); - final_win_template_last = xstrdup(win_template); + struct window_pane *wp = item->target.wp; + const struct window_mode *mode; + + if (self->entry == &cmd_choose_buffer_entry) { + if (paste_get_top(NULL) == NULL) + return (CMD_RETURN_NORMAL); + mode = &window_buffer_mode; + } else if (self->entry == &cmd_choose_client_entry) { + if (server_client_how_many() == 0) + return (CMD_RETURN_NORMAL); + mode = &window_client_mode; } else - final_win_template_middle = final_win_template_last = NULL; - - idx_ses = cur_win = -1; - RB_FOREACH(s2, sessions, &sessions) { - idx_ses++; - - /* - * If we're just choosing windows, jump straight there. Note - * that this implies the current session, so only choose - * windows when the session matches this one. - */ - if (wflag && !sflag) { - if (s != s2) - continue; - goto windows_only; - } - - wcd = window_choose_add_session(wl->window->active, - c, s2, ses_template, ses_action, idx_ses); - - /* If we're just choosing sessions, skip choosing windows. */ - if (sflag && !wflag) { - if (s == s2) - cur_win = idx_ses; - continue; - } -windows_only: - win_ses = win_max = -1; - RB_FOREACH(wm, winlinks, &s2->windows) - win_max++; - RB_FOREACH(wm, winlinks, &s2->windows) { - win_ses++; - if (sflag && wflag) - idx_ses++; - - if (wm == s2->curw && s == s2) { - if (wflag && !sflag) { - /* - * Then we're only counting windows. - * So remember which is the current - * window in the list. - */ - cur_win = win_ses; - } else - cur_win = idx_ses; - } - - xasprintf(&final_win_action, "%s %s %s", - wcd != NULL ? wcd->command : "", - wcd != NULL ? ";" : "", win_action); - - if (win_ses != win_max) - cur_win_template = final_win_template_middle; - else - cur_win_template = final_win_template_last; - - window_choose_add_window(wl->window->active, - c, s2, wm, cur_win_template, - final_win_action, - (wflag && !sflag) ? win_ses : idx_ses); - - free(final_win_action); - } - - /* - * If we're just drawing windows, don't consider moving on to - * other sessions as we only list windows in this session. - */ - if (wflag && !sflag) - break; - } - free(final_win_template_middle); - free(final_win_template_last); - - window_choose_ready(wl->window->active, cur_win, NULL); - - if (args_has(args, 'u')) { - window_choose_expand_all(wl->window->active); - window_choose_set_current(wl->window->active, cur_win); - } + mode = &window_tree_mode; + window_pane_set_mode(wp, mode, &item->target, args); return (CMD_RETURN_NORMAL); } diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c index 5599bb96..699a868d 100644 --- a/cmd-copy-mode.c +++ b/cmd-copy-mode.c @@ -60,6 +60,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item) struct client *c = item->client; struct session *s; struct window_pane *wp = item->target.wp; + int flag; if (args_has(args, 'M')) { if ((wp = cmd_mouse_pane(&shared->mouse, &s, NULL)) == NULL) @@ -69,12 +70,13 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item) } if (self->entry == &cmd_clock_mode_entry) { - window_pane_set_mode(wp, &window_clock_mode); + window_pane_set_mode(wp, &window_clock_mode, NULL, NULL); return (CMD_RETURN_NORMAL); } if (wp->mode != &window_copy_mode) { - if (window_pane_set_mode(wp, &window_copy_mode) != 0) + flag = window_pane_set_mode(wp, &window_copy_mode, NULL, NULL); + if (flag != 0) return (CMD_RETURN_NORMAL); window_copy_init_from_pane(wp, args_has(self->args, 'e')); } diff --git a/cmd-find-window.c b/cmd-find-window.c index 6338e2e1..92714498 100644 --- a/cmd-find-window.c +++ b/cmd-find-window.c @@ -18,9 +18,7 @@ #include <sys/types.h> -#include <fnmatch.h> #include <stdlib.h> -#include <string.h> #include "tmux.h" @@ -28,216 +26,69 @@ * Find window containing text. */ -#define FIND_WINDOW_TEMPLATE \ - "#{window_index}: #{window_name} " \ - "[#{window_width}x#{window_height}] " \ - "(#{window_panes} panes) #{window_find_matches}" - static enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmdq_item *); -static void cmd_find_window_callback(struct window_choose_data *); - -/* Flags for determining matching behavior. */ -#define CMD_FIND_WINDOW_BY_TITLE 0x1 -#define CMD_FIND_WINDOW_BY_CONTENT 0x2 -#define CMD_FIND_WINDOW_BY_NAME 0x4 - -#define CMD_FIND_WINDOW_ALL \ - (CMD_FIND_WINDOW_BY_TITLE | \ - CMD_FIND_WINDOW_BY_CONTENT | \ - CMD_FIND_WINDOW_BY_NAME) - const struct cmd_entry cmd_find_window_entry = { .name = "find-window", .alias = "findw", - .args = { "F:CNt:T", 1, 4 }, - .usage = "[-CNT] [-F format] " CMD_TARGET_WINDOW_USAGE " match-string", + .args = { "CNt:T", 1, 1 }, + .usage = "[-CNT] " CMD_TARGET_PANE_USAGE " match-string", - .target = { 't', CMD_FIND_WINDOW, 0 }, + .target = { 't', CMD_FIND_PANE, 0 }, .flags = 0, .exec = cmd_find_window_exec }; -struct cmd_find_window_data { - struct winlink *wl; - char *list_ctx; - u_int pane_id; - TAILQ_ENTRY(cmd_find_window_data) entry; -}; -TAILQ_HEAD(cmd_find_window_list, cmd_find_window_data); - -static u_int cmd_find_window_match_flags(struct args *); -static void cmd_find_window_match(struct cmd_find_window_list *, int, - struct winlink *, const char *, const char *); - -static u_int -cmd_find_window_match_flags(struct args *args) -{ - u_int match_flags = 0; - - /* Turn on flags based on the options. */ - if (args_has(args, 'T')) - match_flags |= CMD_FIND_WINDOW_BY_TITLE; - if (args_has(args, 'C')) - match_flags |= CMD_FIND_WINDOW_BY_CONTENT; - if (args_has(args, 'N')) - match_flags |= CMD_FIND_WINDOW_BY_NAME; - - /* If none of the flags were set, default to matching anything. */ - if (match_flags == 0) - match_flags = CMD_FIND_WINDOW_ALL; - - return (match_flags); -} - -static void -cmd_find_window_match(struct cmd_find_window_list *find_list, - int match_flags, struct winlink *wl, const char *str, - const char *searchstr) -{ - struct cmd_find_window_data *find_data; - struct window_pane *wp; - u_int i, line; - char *sres; - - find_data = xcalloc(1, sizeof *find_data); - - i = 0; - TAILQ_FOREACH(wp, &wl->window->panes, entry) { - i++; - - if ((match_flags & CMD_FIND_WINDOW_BY_NAME) && - fnmatch(searchstr, wl->window->name, 0) == 0) { - find_data->list_ctx = xstrdup(""); - break; - } - - if ((match_flags & CMD_FIND_WINDOW_BY_TITLE) && - fnmatch(searchstr, wp->base.title, 0) == 0) { - xasprintf(&find_data->list_ctx, - "pane %u title: \"%s\"", i - 1, wp->base.title); - break; - } - - if (match_flags & CMD_FIND_WINDOW_BY_CONTENT && - (sres = window_pane_search_old(wp, str, &line)) != NULL) { - xasprintf(&find_data->list_ctx, - "pane %u line %u: \"%s\"", i - 1, line + 1, sres); - free(sres); - break; - } - } - - if (find_data->list_ctx != NULL) { - find_data->wl = wl; - find_data->pane_id = i - 1; - TAILQ_INSERT_TAIL(find_list, find_data, entry); - } else - free(find_data); -} - static enum cmd_retval cmd_find_window_exec(struct cmd *self, struct cmdq_item *item) { - struct args *args = self->args; - struct cmd_find_state *current = &item->shared->current; - struct client *c = cmd_find_client(item, NULL, 1); - struct window_choose_data *cdata; - struct session *s = item->target.s; - struct winlink *wl = item->target.wl, *wm; - struct cmd_find_window_list find_list; - struct cmd_find_window_data *find_data; - struct cmd_find_window_data *find_data1; - char *str, *searchstr; - const char *template; - u_int i, match_flags; - - if (c == NULL) { - cmdq_error(item, "no client available"); - return (CMD_RETURN_ERROR); - } - - if ((template = args_get(args, 'F')) == NULL) - template = FIND_WINDOW_TEMPLATE; - - match_flags = cmd_find_window_match_flags(args); - str = args->argv[0]; - - TAILQ_INIT(&find_list); - - xasprintf(&searchstr, "*%s*", str); - RB_FOREACH(wm, winlinks, &s->windows) - cmd_find_window_match(&find_list, match_flags, wm, str, searchstr); - free(searchstr); - - if (TAILQ_EMPTY(&find_list)) { - cmdq_error(item, "no windows matching: %s", str); - return (CMD_RETURN_ERROR); - } - - if (TAILQ_NEXT(TAILQ_FIRST(&find_list), entry) == NULL) { - if (session_select(s, TAILQ_FIRST(&find_list)->wl->idx) == 0) { - cmd_find_from_session(current, s); - server_redraw_session(s); - } - recalculate_sizes(); - goto out; - } - - if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0) - goto out; - - i = 0; - TAILQ_FOREACH(find_data, &find_list, entry) { - cdata = window_choose_data_create(TREE_OTHER, c, c->session); - cdata->idx = find_data->wl->idx; - cdata->wl = find_data->wl; - - cdata->ft_template = xstrdup(template); - cdata->pane_id = find_data->pane_id; - - format_add(cdata->ft, "line", "%u", i); - format_add(cdata->ft, "window_find_matches", "%s", - find_data->list_ctx); - format_defaults(cdata->ft, NULL, s, find_data->wl, NULL); - - window_choose_add(wl->window->active, cdata); - - i++; - } - - window_choose_ready(wl->window->active, 0, cmd_find_window_callback); - -out: - TAILQ_FOREACH_SAFE(find_data, &find_list, entry, find_data1) { - free(find_data->list_ctx); - TAILQ_REMOVE(&find_list, find_data, entry); - free(find_data); - } - return (CMD_RETURN_NORMAL); -} - -static void -cmd_find_window_callback(struct window_choose_data *cdata) -{ - struct session *s; - struct window_pane *wp; - - if (cdata == NULL) - return; + struct args *args = self->args, *new_args; + struct window_pane *wp = item->target.wp; + const char *s = args->argv[0]; + char *filter, *argv = { NULL }; + int C, N, T; + + C = args_has(args, 'C'); + N = args_has(args, 'N'); + T = args_has(args, 'T'); + + if (!C && !N && !T) + C = N = T = 1; + + if (C && N && T) { + xasprintf(&filter, + "#{||:" + "#{C:%s},#{||:#{m:*%s*,#{window_name}}," + "#{m:*%s*,#{pane_title}}}}", + s, s, s); + } else if (C && N) { + xasprintf(&filter, + "#{||:#{C:%s},#{m:*%s*,#{window_name}}}", + s, s); + } else if (C && T) { + xasprintf(&filter, + "#{||:#{C:%s},#{m:*%s*,#{pane_title}}}", + s, s); + } else if (N && T) { + xasprintf(&filter, + "#{||:#{m:*%s*,#{window_name}},#{m:*%s*,#{pane_title}}}", + s, s); + } else if (C) + xasprintf(&filter, "#{C:%s}", s); + else if (N) + xasprintf(&filter, "#{m:*%s*,#{window_name}}", s); + else if (T) + xasprintf(&filter, "#{m:*%s*,#{pane_title}}", s); + + new_args = args_parse("", 1, &argv); + args_set(new_args, 'f', filter); + + window_pane_set_mode(wp, &window_tree_mode, &item->target, new_args); + + args_free(new_args); + free(filter); - s = cdata->start_session; - if (!session_alive(s)) - return; - - wp = window_pane_at_index(cdata->wl->window, cdata->pane_id); - if (wp != NULL && window_pane_visible(wp)) - window_set_active_pane(cdata->wl->window, wp); - - if (session_select(s, cdata->idx) == 0) { - server_redraw_session(s); - recalculate_sizes(); - } + return (CMD_RETURN_NORMAL); } diff --git a/cmd-queue.c b/cmd-queue.c index b0885965..8d89e990 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -428,7 +428,8 @@ cmdq_print(struct cmdq_item *item, const char *fmt, ...) w = c->session->curw->window; if (w->active->mode != &window_copy_mode) { window_pane_reset_mode(w->active); - window_pane_set_mode(w->active, &window_copy_mode); + window_pane_set_mode(w->active, &window_copy_mode, NULL, + NULL); window_copy_init_for_output(w->active); } window_copy_vadd(w->active, fmt, ap); diff --git a/cmd-run-shell.c b/cmd-run-shell.c index 2565d6a1..f77fb36a 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -75,7 +75,7 @@ cmd_run_shell_print(struct job *job, const char *msg) return; } - if (window_pane_set_mode(wp, &window_copy_mode) == 0) + if (window_pane_set_mode(wp, &window_copy_mode, NULL, NULL) == 0) window_copy_init_for_output(wp); if (wp->mode == &window_copy_mode) window_copy_add(wp, "%s", msg); diff --git a/cmd-split-window.c b/cmd-split-window.c index dcc4d713..35993bfc 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -133,7 +133,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) goto error; } new_wp = window_add_pane(w, wp, args_has(args, 'b'), hlimit); - layout_assign_pane(lc, new_wp); + layout_make_leaf(lc, new_wp); path = NULL; if (item->client != NULL && item->client->session == NULL) @@ -151,6 +151,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) } environ_free(env); + layout_fix_panes(w, w->sx, w->sy); server_redraw_window(w); if (!args_has(args, 'd')) { @@ -33,9 +33,7 @@ extern const struct cmd_entry cmd_break_pane_entry; extern const struct cmd_entry cmd_capture_pane_entry; extern const struct cmd_entry cmd_choose_buffer_entry; extern const struct cmd_entry cmd_choose_client_entry; -extern const struct cmd_entry cmd_choose_session_entry; extern const struct cmd_entry cmd_choose_tree_entry; -extern const struct cmd_entry cmd_choose_window_entry; extern const struct cmd_entry cmd_clea |