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

Annotation of src/usr.bin/tmux/cmd-list-panes.c, Revision 1.34

1.34    ! nicm        1: /* $OpenBSD: cmd-list-panes.c,v 1.33 2017/05/01 12:20:55 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.27      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.14      nicm       21: #include <stdlib.h>
1.1       nicm       22:
                     23: #include "tmux.h"
                     24:
                     25: /*
1.4       nicm       26:  * List panes on given window.
1.1       nicm       27:  */
                     28:
1.30      nicm       29: static enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmdq_item *);
1.1       nicm       30:
1.30      nicm       31: static void    cmd_list_panes_server(struct cmd *, struct cmdq_item *);
1.28      nicm       32: static void    cmd_list_panes_session(struct cmd *, struct session *,
1.30      nicm       33:                    struct cmdq_item *, int);
1.28      nicm       34: static void    cmd_list_panes_window(struct cmd *, struct session *,
1.30      nicm       35:                    struct winlink *, struct cmdq_item *, int);
1.9       nicm       36:
1.1       nicm       37: const struct cmd_entry cmd_list_panes_entry = {
1.25      nicm       38:        .name = "list-panes",
                     39:        .alias = "lsp",
                     40:
1.34    ! nicm       41:        .args = { "asF:f:t:", 0, 0 },
        !            42:        .usage = "[-as] [-F format] [-f filter] " CMD_TARGET_WINDOW_USAGE,
1.25      nicm       43:
1.32      nicm       44:        .target = { 't', CMD_FIND_WINDOW, 0 },
1.26      nicm       45:
1.29      nicm       46:        .flags = CMD_AFTERHOOK,
1.25      nicm       47:        .exec = cmd_list_panes_exec
1.1       nicm       48: };
                     49:
1.28      nicm       50: static enum cmd_retval
1.30      nicm       51: cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       52: {
1.9       nicm       53:        struct args     *args = self->args;
1.32      nicm       54:        struct session  *s = item->target.s;
                     55:        struct winlink  *wl = item->target.wl;
1.9       nicm       56:
                     57:        if (args_has(args, 'a'))
1.30      nicm       58:                cmd_list_panes_server(self, item);
1.24      nicm       59:        else if (args_has(args, 's'))
1.30      nicm       60:                cmd_list_panes_session(self, s, item, 1);
1.24      nicm       61:        else
1.30      nicm       62:                cmd_list_panes_window(self, s, wl, item, 0);
1.9       nicm       63:
1.15      nicm       64:        return (CMD_RETURN_NORMAL);
1.9       nicm       65: }
                     66:
1.28      nicm       67: static void
1.30      nicm       68: cmd_list_panes_server(struct cmd *self, struct cmdq_item *item)
1.9       nicm       69: {
                     70:        struct session  *s;
                     71:
                     72:        RB_FOREACH(s, sessions, &sessions)
1.30      nicm       73:                cmd_list_panes_session(self, s, item, 2);
1.9       nicm       74: }
                     75:
1.28      nicm       76: static void
1.30      nicm       77: cmd_list_panes_session(struct cmd *self, struct session *s,
                     78:     struct cmdq_item *item, int type)
1.9       nicm       79: {
                     80:        struct winlink  *wl;
                     81:
                     82:        RB_FOREACH(wl, winlinks, &s->windows)
1.30      nicm       83:                cmd_list_panes_window(self, s, wl, item, type);
1.9       nicm       84: }
                     85:
1.28      nicm       86: static void
1.21      nicm       87: cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
1.30      nicm       88:     struct cmdq_item *item, int type)
1.9       nicm       89: {
1.12      nicm       90:        struct args             *args = self->args;
1.1       nicm       91:        struct window_pane      *wp;
1.12      nicm       92:        u_int                    n;
                     93:        struct format_tree      *ft;
1.34    ! nicm       94:        const char              *template, *filter;
        !            95:        char                    *line, *expanded;
        !            96:        int                      flag;
1.4       nicm       97:
1.12      nicm       98:        template = args_get(args, 'F');
                     99:        if (template == NULL) {
1.11      nicm      100:                switch (type) {
                    101:                case 0:
1.13      nicm      102:                        template = "#{pane_index}: "
1.12      nicm      103:                            "[#{pane_width}x#{pane_height}] [history "
                    104:                            "#{history_size}/#{history_limit}, "
                    105:                            "#{history_bytes} bytes] #{pane_id}"
                    106:                            "#{?pane_active, (active),}#{?pane_dead, (dead),}";
1.11      nicm      107:                        break;
                    108:                case 1:
1.13      nicm      109:                        template = "#{window_index}.#{pane_index}: "
1.12      nicm      110:                            "[#{pane_width}x#{pane_height}] [history "
                    111:                            "#{history_size}/#{history_limit}, "
                    112:                            "#{history_bytes} bytes] #{pane_id}"
                    113:                            "#{?pane_active, (active),}#{?pane_dead, (dead),}";
1.11      nicm      114:                        break;
                    115:                case 2:
1.21      nicm      116:                        template = "#{session_name}:#{window_index}."
                    117:                            "#{pane_index}: [#{pane_width}x#{pane_height}] "
                    118:                            "[history #{history_size}/#{history_limit}, "
1.12      nicm      119:                            "#{history_bytes} bytes] #{pane_id}"
                    120:                            "#{?pane_active, (active),}#{?pane_dead, (dead),}";
1.11      nicm      121:                        break;
                    122:                }
1.12      nicm      123:        }
1.34    ! nicm      124:        filter = args_get(args, 'f');
1.12      nicm      125:
                    126:        n = 0;
                    127:        TAILQ_FOREACH(wp, &wl->window->panes, entry) {
1.33      nicm      128:                ft = format_create(item->client, item, FORMAT_NONE, 0);
1.12      nicm      129:                format_add(ft, "line", "%u", n);
1.20      nicm      130:                format_defaults(ft, NULL, s, wl, wp);
1.12      nicm      131:
1.34    ! nicm      132:                if (filter != NULL) {
        !           133:                        expanded = format_expand(ft, filter);
        !           134:                        flag = format_true(expanded);
        !           135:                        free(expanded);
        !           136:                } else
        !           137:                        flag = 1;
        !           138:                if (flag) {
        !           139:                        line = format_expand(ft, template);
        !           140:                        cmdq_print(item, "%s", line);
        !           141:                        free(line);
        !           142:                }
1.12      nicm      143:
                    144:                format_free(ft);
1.2       nicm      145:                n++;
1.1       nicm      146:        }
                    147: }