Annotation of src/usr.bin/tmux/cmd-list-panes.c, Revision 1.25
1.25 ! nicm 1: /* $OpenBSD: cmd-list-panes.c,v 1.24 2015/12/13 14:32:38 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:
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.17 nicm 29: enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_q *);
1.1 nicm 30:
1.17 nicm 31: void cmd_list_panes_server(struct cmd *, struct cmd_q *);
1.21 nicm 32: void cmd_list_panes_session(struct cmd *, struct session *, struct cmd_q *,
33: int);
34: void cmd_list_panes_window(struct cmd *, struct session *, struct winlink *,
35: struct cmd_q *, 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:
! 41: .args = { "asF:t:", 0, 0 },
! 42: .usage = "[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
! 43:
! 44: .flags = CMD_WINDOW_T,
! 45: .exec = cmd_list_panes_exec
1.1 nicm 46: };
47:
1.15 nicm 48: enum cmd_retval
1.17 nicm 49: cmd_list_panes_exec(struct cmd *self, struct cmd_q *cmdq)
1.1 nicm 50: {
1.9 nicm 51: struct args *args = self->args;
1.24 nicm 52: struct session *s = cmdq->state.tflag.s;
53: struct winlink *wl = cmdq->state.tflag.wl;
1.9 nicm 54:
55: if (args_has(args, 'a'))
1.17 nicm 56: cmd_list_panes_server(self, cmdq);
1.24 nicm 57: else if (args_has(args, 's'))
1.17 nicm 58: cmd_list_panes_session(self, s, cmdq, 1);
1.24 nicm 59: else
1.17 nicm 60: cmd_list_panes_window(self, s, wl, cmdq, 0);
1.9 nicm 61:
1.15 nicm 62: return (CMD_RETURN_NORMAL);
1.9 nicm 63: }
64:
65: void
1.17 nicm 66: cmd_list_panes_server(struct cmd *self, struct cmd_q *cmdq)
1.9 nicm 67: {
68: struct session *s;
69:
70: RB_FOREACH(s, sessions, &sessions)
1.17 nicm 71: cmd_list_panes_session(self, s, cmdq, 2);
1.9 nicm 72: }
73:
74: void
1.21 nicm 75: cmd_list_panes_session(struct cmd *self, struct session *s, struct cmd_q *cmdq,
76: int type)
1.9 nicm 77: {
78: struct winlink *wl;
79:
80: RB_FOREACH(wl, winlinks, &s->windows)
1.17 nicm 81: cmd_list_panes_window(self, s, wl, cmdq, type);
1.9 nicm 82: }
83:
84: void
1.21 nicm 85: cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
86: struct cmd_q *cmdq, int type)
1.9 nicm 87: {
1.12 nicm 88: struct args *args = self->args;
1.1 nicm 89: struct window_pane *wp;
1.12 nicm 90: u_int n;
91: struct format_tree *ft;
92: const char *template;
93: char *line;
1.4 nicm 94:
1.12 nicm 95: template = args_get(args, 'F');
96: if (template == NULL) {
1.11 nicm 97: switch (type) {
98: case 0:
1.13 nicm 99: template = "#{pane_index}: "
1.12 nicm 100: "[#{pane_width}x#{pane_height}] [history "
101: "#{history_size}/#{history_limit}, "
102: "#{history_bytes} bytes] #{pane_id}"
103: "#{?pane_active, (active),}#{?pane_dead, (dead),}";
1.11 nicm 104: break;
105: case 1:
1.13 nicm 106: template = "#{window_index}.#{pane_index}: "
1.12 nicm 107: "[#{pane_width}x#{pane_height}] [history "
108: "#{history_size}/#{history_limit}, "
109: "#{history_bytes} bytes] #{pane_id}"
110: "#{?pane_active, (active),}#{?pane_dead, (dead),}";
1.11 nicm 111: break;
112: case 2:
1.21 nicm 113: template = "#{session_name}:#{window_index}."
114: "#{pane_index}: [#{pane_width}x#{pane_height}] "
115: "[history #{history_size}/#{history_limit}, "
1.12 nicm 116: "#{history_bytes} bytes] #{pane_id}"
117: "#{?pane_active, (active),}#{?pane_dead, (dead),}";
1.11 nicm 118: break;
119: }
1.12 nicm 120: }
121:
122: n = 0;
123: TAILQ_FOREACH(wp, &wl->window->panes, entry) {
1.23 nicm 124: ft = format_create(cmdq, 0);
1.12 nicm 125: format_add(ft, "line", "%u", n);
1.20 nicm 126: format_defaults(ft, NULL, s, wl, wp);
1.12 nicm 127:
128: line = format_expand(ft, template);
1.17 nicm 129: cmdq_print(cmdq, "%s", line);
1.14 nicm 130: free(line);
1.12 nicm 131:
132: format_free(ft);
1.2 nicm 133: n++;
1.1 nicm 134: }
135: }