[BACK]Return to cmd-choose-session.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-choose-session.c, Revision 1.15

1.15    ! nicm        1: /* $OpenBSD: cmd-choose-session.c,v 1.14 2012/06/25 14:08:55 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
                      5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
                     15:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                     16:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18:
                     19: #include <sys/types.h>
1.6       nicm       20:
                     21: #include <ctype.h>
1.1       nicm       22:
                     23: #include "tmux.h"
                     24:
                     25: /*
                     26:  * Enter choice mode to choose a session.
                     27:  */
                     28:
                     29: int    cmd_choose_session_exec(struct cmd *, struct cmd_ctx *);
                     30:
1.14      nicm       31: void   cmd_choose_session_callback(struct window_choose_data *);
                     32: void   cmd_choose_session_free(struct window_choose_data *);
1.1       nicm       33:
                     34: const struct cmd_entry cmd_choose_session_entry = {
                     35:        "choose-session", NULL,
1.13      nicm       36:        "F:t:", 0, 1,
                     37:        CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
1.12      nicm       38:        0,
                     39:        NULL,
                     40:        NULL,
                     41:        cmd_choose_session_exec
1.1       nicm       42: };
                     43:
                     44: int
                     45: cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
                     46: {
1.12      nicm       47:        struct args                     *args = self->args;
1.1       nicm       48:        struct winlink                  *wl;
                     49:        struct session                  *s;
1.15    ! nicm       50:        char                            *action;
1.13      nicm       51:        const char                      *template;
                     52:        u_int                            idx, cur;
1.1       nicm       53:
                     54:        if (ctx->curclient == NULL) {
                     55:                ctx->error(ctx, "must be run interactively");
                     56:                return (-1);
                     57:        }
                     58:
1.12      nicm       59:        if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
1.1       nicm       60:                return (-1);
                     61:
                     62:        if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
                     63:                return (0);
                     64:
1.13      nicm       65:        if ((template = args_get(args, 'F')) == NULL)
                     66:                template = DEFAULT_SESSION_TEMPLATE;
                     67:
1.15    ! nicm       68:        if (args->argc != 0)
        !            69:                action = xstrdup(args->argv[0]);
        !            70:        else
        !            71:                action = xstrdup("switch-client -t '%%'");
        !            72:
1.1       nicm       73:        cur = idx = 0;
1.11      nicm       74:        RB_FOREACH(s, sessions, &sessions) {
1.1       nicm       75:                if (s == ctx->curclient->session)
                     76:                        cur = idx;
                     77:                idx++;
                     78:
1.15    ! nicm       79:                window_choose_add_session(wl->window->active,
        !            80:                    ctx, s, template, action, idx);
1.1       nicm       81:        }
1.15    ! nicm       82:        xfree(action);
1.1       nicm       83:
1.5       nicm       84:        window_choose_ready(wl->window->active,
1.14      nicm       85:            cur, cmd_choose_session_callback, cmd_choose_session_free);
1.1       nicm       86:
                     87:        return (0);
                     88: }
                     89:
                     90: void
1.14      nicm       91: cmd_choose_session_callback(struct window_choose_data *cdata)
1.1       nicm       92: {
1.14      nicm       93:        if (cdata == NULL)
1.5       nicm       94:                return;
1.7       nicm       95:        if (cdata->client->flags & CLIENT_DEAD)
1.5       nicm       96:                return;
                     97:
1.14      nicm       98:        window_choose_ctx(cdata);
1.5       nicm       99: }
                    100:
                    101: void
1.14      nicm      102: cmd_choose_session_free(struct window_choose_data *cdata)
1.5       nicm      103: {
1.14      nicm      104:        if (cdata == NULL)
                    105:                return;
1.5       nicm      106:
1.7       nicm      107:        cdata->client->references--;
1.14      nicm      108:        cdata->session->references--;
                    109:
1.15    ! nicm      110:        xfree(cdata->command);
1.14      nicm      111:        xfree(cdata->ft_template);
                    112:        format_free(cdata->ft);
1.5       nicm      113:        xfree(cdata);
1.1       nicm      114: }