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

1.10    ! nicm        1: /* $OpenBSD: cmd-list-panes.c,v 1.9 2011/03/28 23:13:00 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>
                     20:
                     21: #include <unistd.h>
                     22:
                     23: #include "tmux.h"
                     24:
                     25: /*
1.4       nicm       26:  * List panes on given window.
1.1       nicm       27:  */
                     28:
                     29: int    cmd_list_panes_exec(struct cmd *, struct cmd_ctx *);
                     30:
1.9       nicm       31: void   cmd_list_panes_server(struct cmd_ctx *);
                     32: void   cmd_list_panes_session(struct session *, struct cmd_ctx *);
                     33: void   cmd_list_panes_window(struct winlink *, struct cmd_ctx *);
                     34:
1.1       nicm       35: const struct cmd_entry cmd_list_panes_entry = {
                     36:        "list-panes", "lsp",
1.9       nicm       37:        "ast:", 0, 0,
                     38:        "[-as] [-t target]",
1.7       nicm       39:        0,
                     40:        NULL,
                     41:        NULL,
                     42:        cmd_list_panes_exec
1.1       nicm       43: };
                     44:
                     45: int
                     46: cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
                     47: {
1.9       nicm       48:        struct args     *args = self->args;
                     49:        struct session  *s;
                     50:        struct winlink  *wl;
                     51:
                     52:        if (args_has(args, 'a'))
                     53:                cmd_list_panes_server(ctx);
                     54:        else if (args_has(args, 's')) {
1.10    ! nicm       55:                s = cmd_find_session(ctx, args_get(args, 't'), 0);
1.9       nicm       56:                if (s == NULL)
                     57:                        return (-1);
                     58:                cmd_list_panes_session(s, ctx);
                     59:        } else {
                     60:                wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
                     61:                if (wl == NULL)
                     62:                        return (-1);
                     63:                cmd_list_panes_window(wl, ctx);
                     64:        }
                     65:
                     66:        return (0);
                     67: }
                     68:
                     69: void
                     70: cmd_list_panes_server(struct cmd_ctx *ctx)
                     71: {
                     72:        struct session  *s;
                     73:
                     74:        RB_FOREACH(s, sessions, &sessions)
                     75:                cmd_list_panes_session(s, ctx);
                     76: }
                     77:
                     78: void
                     79: cmd_list_panes_session(struct session *s, struct cmd_ctx *ctx)
                     80: {
                     81:        struct winlink  *wl;
                     82:
                     83:        RB_FOREACH(wl, winlinks, &s->windows)
                     84:                cmd_list_panes_window(wl, ctx);
                     85: }
                     86:
                     87: void
                     88: cmd_list_panes_window(struct winlink *wl, struct cmd_ctx *ctx)
                     89: {
1.1       nicm       90:        struct window_pane      *wp;
                     91:        struct grid             *gd;
                     92:        struct grid_line        *gl;
1.2       nicm       93:        u_int                    i, n;
1.1       nicm       94:        unsigned long long       size;
                     95:
1.2       nicm       96:        n = 0;
1.1       nicm       97:        TAILQ_FOREACH(wp, &wl->window->panes, entry) {
                     98:                gd = wp->base.grid;
1.4       nicm       99:
1.1       nicm      100:                size = 0;
                    101:                for (i = 0; i < gd->hsize; i++) {
                    102:                        gl = &gd->linedata[i];
                    103:                        size += gl->cellsize * sizeof *gl->celldata;
                    104:                        size += gl->utf8size * sizeof *gl->utf8data;
                    105:                }
                    106:                size += gd->hsize * sizeof *gd->linedata;
1.4       nicm      107:
1.9       nicm      108:                ctx->print(ctx,
                    109:                    "%u: [%ux%u] [history %u/%u, %llu bytes] %%%u%s%s",
1.8       nicm      110:                    n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size, wp->id,
1.6       nicm      111:                    wp == wp->window->active ? " (active)" : "",
                    112:                    wp->fd == -1 ? " (dead)" : "");
1.2       nicm      113:                n++;
1.1       nicm      114:        }
                    115: }