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

Annotation of src/usr.bin/tmux/cmd-display-panes.c, Revision 1.20

1.20    ! nicm        1: /* $OpenBSD: cmd-display-panes.c,v 1.19 2017/04/22 10:22:39 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.12      nicm        4:  * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1       nicm        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>
                     20:
1.13      nicm       21: #include <ctype.h>
                     22: #include <stdlib.h>
                     23:
1.1       nicm       24: #include "tmux.h"
                     25:
                     26: /*
                     27:  * Display panes on a client.
                     28:  */
                     29:
1.16      nicm       30: static enum cmd_retval cmd_display_panes_exec(struct cmd *,
                     31:                            struct cmdq_item *);
1.13      nicm       32:
1.16      nicm       33: static void            cmd_display_panes_callback(struct client *,
                     34:                            struct window_pane *);
1.1       nicm       35:
                     36: const struct cmd_entry cmd_display_panes_entry = {
1.10      nicm       37:        .name = "display-panes",
                     38:        .alias = "displayp",
                     39:
1.20    ! nicm       40:        .args = { "d:t:", 0, 1 },
        !            41:        .usage = "[-d duration] " CMD_TARGET_CLIENT_USAGE,
1.10      nicm       42:
1.14      nicm       43:        .flags = CMD_AFTERHOOK,
1.10      nicm       44:        .exec = cmd_display_panes_exec
1.1       nicm       45: };
                     46:
1.13      nicm       47: static enum cmd_retval
1.16      nicm       48: cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       49: {
1.13      nicm       50:        struct args     *args = self->args;
1.19      nicm       51:        struct client   *c;
1.20    ! nicm       52:        struct session  *s;
        !            53:        u_int            delay;
        !            54:        char            *cause;
1.19      nicm       55:
                     56:        if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
                     57:                return (CMD_RETURN_ERROR);
1.13      nicm       58:
                     59:        if (c->identify_callback != NULL)
                     60:                return (CMD_RETURN_NORMAL);
                     61:
                     62:        c->identify_callback = cmd_display_panes_callback;
                     63:        if (args->argc != 0)
                     64:                c->identify_callback_data = xstrdup(args->argv[0]);
                     65:        else
                     66:                c->identify_callback_data = xstrdup("select-pane -t '%%'");
1.20    ! nicm       67:        s = c->session;
1.13      nicm       68:
1.20    ! nicm       69:        if (args_has(args, 'd')) {
        !            70:                delay = args_strtonum(args, 'd', 0, UINT_MAX, &cause);
        !            71:                if (cause != NULL) {
        !            72:                        cmdq_error(item, "delay %s", cause);
        !            73:                        free(cause);
        !            74:                        return (CMD_RETURN_ERROR);
        !            75:                }
        !            76:        } else
        !            77:                delay = options_get_number(s->options, "display-panes-time");
        !            78:        server_client_set_identify(c, delay);
1.1       nicm       79:
1.4       nicm       80:        return (CMD_RETURN_NORMAL);
1.13      nicm       81: }
                     82:
1.15      nicm       83: static enum cmd_retval
1.16      nicm       84: cmd_display_panes_error(struct cmdq_item *item, void *data)
1.15      nicm       85: {
                     86:        char    *error = data;
                     87:
1.16      nicm       88:        cmdq_error(item, "%s", error);
1.15      nicm       89:        free(error);
                     90:
                     91:        return (CMD_RETURN_NORMAL);
                     92: }
                     93:
1.13      nicm       94: static void
                     95: cmd_display_panes_callback(struct client *c, struct window_pane *wp)
                     96: {
1.16      nicm       97:        struct cmd_list         *cmdlist;
                     98:        struct cmdq_item        *new_item;
                     99:        char                    *template, *cmd, *expanded, *cause;
1.13      nicm      100:
                    101:        template = c->identify_callback_data;
1.15      nicm      102:        if (wp == NULL)
                    103:                goto out;
                    104:        xasprintf(&expanded, "%%%u", wp->id);
                    105:        cmd = cmd_template_replace(template, expanded, 1);
                    106:
1.17      nicm      107:        cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
                    108:        if (cmdlist == NULL) {
1.15      nicm      109:                if (cause != NULL) {
1.16      nicm      110:                        new_item = cmdq_get_callback(cmd_display_panes_error,
1.15      nicm      111:                            cause);
                    112:                } else
1.16      nicm      113:                        new_item = NULL;
1.15      nicm      114:        } else {
1.16      nicm      115:                new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
1.15      nicm      116:                cmd_list_free(cmdlist);
                    117:        }
1.13      nicm      118:
1.16      nicm      119:        if (new_item != NULL)
                    120:                cmdq_append(c, new_item);
1.15      nicm      121:
                    122:        free(cmd);
                    123:        free(expanded);
1.13      nicm      124:
1.15      nicm      125: out:
1.13      nicm      126:        free(c->identify_callback_data);
                    127:        c->identify_callback_data = NULL;
                    128:        c->identify_callback = NULL;
1.1       nicm      129: }