Use button mouse mode not any for copy mode, fixes issues with
[tmux-openbsd.git] / cmd-list-panes.c
blob60324e648cd3d935a5bad8138ddbf0c3798c1709
1 /* $OpenBSD$ */
3 /*
4 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
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.
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.
19 #include <sys/types.h>
21 #include <unistd.h>
23 #include "tmux.h"
26 * List panes on given window.
29 int cmd_list_panes_exec(struct cmd *, struct cmd_ctx *);
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 *);
35 const struct cmd_entry cmd_list_panes_entry = {
36 "list-panes", "lsp",
37 "ast:", 0, 0,
38 "[-as] [-t target]",
40 NULL,
41 NULL,
42 cmd_list_panes_exec
45 int
46 cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
48 struct args *args = self->args;
49 struct session *s;
50 struct winlink *wl;
52 if (args_has(args, 'a'))
53 cmd_list_panes_server(ctx);
54 else if (args_has(args, 's')) {
55 s = cmd_find_session(ctx, args_get(args, 't'), 0);
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);
66 return (0);
69 void
70 cmd_list_panes_server(struct cmd_ctx *ctx)
72 struct session *s;
74 RB_FOREACH(s, sessions, &sessions)
75 cmd_list_panes_session(s, ctx);
78 void
79 cmd_list_panes_session(struct session *s, struct cmd_ctx *ctx)
81 struct winlink *wl;
83 RB_FOREACH(wl, winlinks, &s->windows)
84 cmd_list_panes_window(wl, ctx);
87 void
88 cmd_list_panes_window(struct winlink *wl, struct cmd_ctx *ctx)
90 struct window_pane *wp;
91 struct grid *gd;
92 struct grid_line *gl;
93 u_int i, n;
94 unsigned long long size;
96 n = 0;
97 TAILQ_FOREACH(wp, &wl->window->panes, entry) {
98 gd = wp->base.grid;
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;
106 size += gd->hsize * sizeof *gd->linedata;
108 ctx->print(ctx,
109 "%u: [%ux%u] [history %u/%u, %llu bytes] %%%u%s%s",
110 n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size, wp->id,
111 wp == wp->window->active ? " (active)" : "",
112 wp->fd == -1 ? " (dead)" : "");
113 n++;