diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-06-25 14:08:56 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-06-25 14:08:56 +0000 |
commit | b992c5e6a1cecafa0cd3133b767bd460f50d0057 (patch) | |
tree | 86880c43aa75ac443c92bc3644d6383e89da4235 /usr.bin/tmux/cmd-find-window.c | |
parent | 11e3bf45896808ed53a39d8b1f4ed87b93959306 (diff) |
Clean up and simplify the choose mode code, from Thomas Adam.
Diffstat (limited to 'usr.bin/tmux/cmd-find-window.c')
-rw-r--r-- | usr.bin/tmux/cmd-find-window.c | 61 |
1 files changed, 28 insertions, 33 deletions
diff --git a/usr.bin/tmux/cmd-find-window.c b/usr.bin/tmux/cmd-find-window.c index 0d8f726a905..76e7456d1d6 100644 --- a/usr.bin/tmux/cmd-find-window.c +++ b/usr.bin/tmux/cmd-find-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-find-window.c,v 1.14 2012/06/25 13:49:16 nicm Exp $ */ +/* $OpenBSD: cmd-find-window.c,v 1.15 2012/06/25 14:08:55 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -30,8 +30,8 @@ int cmd_find_window_exec(struct cmd *, struct cmd_ctx *); u_int cmd_find_window_match_flags(struct args *); -void cmd_find_window_callback(void *, int); -void cmd_find_window_free(void *); +void cmd_find_window_callback(struct window_choose_data *); +void cmd_find_window_free(struct window_choose_data *); /* Flags for determining matching behavior. */ #define CMD_FIND_WINDOW_BY_TITLE 0x1 @@ -53,10 +53,6 @@ const struct cmd_entry cmd_find_window_entry = { cmd_find_window_exec }; -struct cmd_find_window_data { - struct session *session; -}; - u_int cmd_find_window_match_flags(struct args *args) { @@ -81,15 +77,13 @@ int cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; - struct cmd_find_window_data *cdata; + struct window_choose_data *cdata; struct session *s; struct winlink *wl, *wm; struct window_pane *wp; - struct format_tree *ft; ARRAY_DECL(, u_int) list_idx; ARRAY_DECL(, char *) list_ctx; char *str, *sres, *sctx, *searchstr; - char *find_line; const char *template; u_int i, line, match_flags; @@ -172,29 +166,25 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) wm = winlink_find_by_index( &s->windows, ARRAY_ITEM(&list_idx, i)); - ft = format_create(); - format_add(ft, "line", "%u", i); - format_add(ft, "window_find_matches", "%s", - ARRAY_ITEM(&list_ctx, i)); - format_session(ft, s); - format_winlink(ft, s, wm); + cdata = window_choose_data_create(ctx); + cdata->idx = wm->idx; + cdata->client->references++; - find_line = format_expand(ft, template); - - window_choose_add(wl->window->active, wm->idx, "%s", find_line); + cdata->ft_template = xstrdup(template); + format_add(cdata->ft, "line", "%u", i); + format_add(cdata->ft, "window_find_matches", "%s", + ARRAY_ITEM(&list_ctx, i)); + format_session(cdata->ft, s); + format_winlink(cdata->ft, s, wm); - xfree(find_line); - format_free(ft); + window_choose_add(wl->window->active, cdata); } - cdata = xmalloc(sizeof *cdata); - cdata->session = s; - cdata->session->references++; - window_choose_ready(wl->window->active, - 0, cmd_find_window_callback, cmd_find_window_free, cdata); + 0, cmd_find_window_callback, cmd_find_window_free); out: + ARRAY_FREE(&list_idx); ARRAY_FREE(&list_ctx); @@ -202,27 +192,32 @@ out: } void -cmd_find_window_callback(void *data, int idx) +cmd_find_window_callback(struct window_choose_data *cdata) { - struct cmd_find_window_data *cdata = data; - struct session *s = cdata->session; + struct session *s; - if (idx == -1) + if (cdata == NULL) return; + + s = cdata->session; if (!session_alive(s)) return; - if (session_select(s, idx) == 0) { + if (session_select(s, cdata->idx) == 0) { server_redraw_session(s); recalculate_sizes(); } } void -cmd_find_window_free(void *data) +cmd_find_window_free(struct window_choose_data *cdata) { - struct cmd_find_window_data *cdata = data; + if (cdata == NULL) + return; cdata->session->references--; + + xfree(cdata->ft_template); + format_free(cdata->ft); xfree(cdata); } |