[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.14

1.14    ! nicm        1: /* $OpenBSD: cmd-display-panes.c,v 1.13 2016/06/16 10:55:47 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.13      nicm       30: static enum cmd_retval  cmd_display_panes_exec(struct cmd *, struct cmd_q *);
                     31:
                     32: static void             cmd_display_panes_callback(struct client *,
                     33:                             struct window_pane *);
1.1       nicm       34:
                     35: const struct cmd_entry cmd_display_panes_entry = {
1.10      nicm       36:        .name = "display-panes",
                     37:        .alias = "displayp",
                     38:
1.13      nicm       39:        .args = { "t:", 0, 1 },
1.10      nicm       40:        .usage = CMD_TARGET_CLIENT_USAGE,
                     41:
1.11      nicm       42:        .tflag = CMD_CLIENT,
                     43:
1.14    ! nicm       44:        .flags = CMD_AFTERHOOK,
1.10      nicm       45:        .exec = cmd_display_panes_exec
1.1       nicm       46: };
                     47:
1.13      nicm       48: static enum cmd_retval
                     49: cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq)
1.1       nicm       50: {
1.13      nicm       51:        struct args     *args = self->args;
                     52:        struct client   *c = cmdq->state.c;
                     53:
                     54:        if (c->identify_callback != NULL)
                     55:                return (CMD_RETURN_NORMAL);
                     56:
                     57:        c->identify_callback = cmd_display_panes_callback;
                     58:        if (args->argc != 0)
                     59:                c->identify_callback_data = xstrdup(args->argv[0]);
                     60:        else
                     61:                c->identify_callback_data = xstrdup("select-pane -t '%%'");
                     62:
                     63:        server_set_identify(c);
1.1       nicm       64:
1.4       nicm       65:        return (CMD_RETURN_NORMAL);
1.13      nicm       66: }
                     67:
                     68: static void
                     69: cmd_display_panes_callback(struct client *c, struct window_pane *wp)
                     70: {
                     71:        struct cmd_list *cmdlist;
                     72:        char            *template, *cmd, *expanded, *cause;
                     73:
                     74:        template = c->identify_callback_data;
                     75:        if (wp != NULL) {
                     76:                xasprintf(&expanded, "%%%u", wp->id);
                     77:                cmd = cmd_template_replace(template, expanded, 1);
                     78:
                     79:                if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
                     80:                        if (cause != NULL) {
                     81:                                *cause = toupper((u_char) *cause);
                     82:                                status_message_set(c, "%s", cause);
                     83:                                free(cause);
                     84:                        }
                     85:                } else {
                     86:                        cmdq_run(c->cmdq, cmdlist, NULL);
                     87:                        cmd_list_free(cmdlist);
                     88:                }
                     89:
                     90:                free(cmd);
                     91:                free(expanded);
                     92:        }
                     93:
                     94:        free(c->identify_callback_data);
                     95:        c->identify_callback_data = NULL;
                     96:        c->identify_callback = NULL;
1.1       nicm       97: }