tmux  3.2a
About: tmux is a terminal multiplexer that lets you switch easily between several programs in one terminal.
  Fossies Dox: tmux-3.2a.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

cmd-list-panes.c
Go to the documentation of this file.
1 /* $OpenBSD$ */
2 
3 /*
4  * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
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 <stdlib.h>
22 
23 #include "tmux.h"
24 
25 /*
26  * List panes on given window.
27  */
28 
29 static enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmdq_item *);
30 
31 static void cmd_list_panes_server(struct cmd *, struct cmdq_item *);
32 static void cmd_list_panes_session(struct cmd *, struct session *,
33  struct cmdq_item *, int);
34 static void cmd_list_panes_window(struct cmd *, struct session *,
35  struct winlink *, struct cmdq_item *, int);
36 
37 const struct cmd_entry cmd_list_panes_entry = {
38  .name = "list-panes",
39  .alias = "lsp",
40 
41  .args = { "asF:f:t:", 0, 0 },
42  .usage = "[-as] [-F format] [-f filter] " CMD_TARGET_WINDOW_USAGE,
43 
44  .target = { 't', CMD_FIND_WINDOW, 0 },
45 
46  .flags = CMD_AFTERHOOK,
47  .exec = cmd_list_panes_exec
48 };
49 
50 static enum cmd_retval
51 cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
52 {
53  struct args *args = cmd_get_args(self);
54  struct cmd_find_state *target = cmdq_get_target(item);
55  struct session *s = target->s;
56  struct winlink *wl = target->wl;
57 
58  if (args_has(args, 'a'))
59  cmd_list_panes_server(self, item);
60  else if (args_has(args, 's'))
61  cmd_list_panes_session(self, s, item, 1);
62  else
63  cmd_list_panes_window(self, s, wl, item, 0);
64 
65  return (CMD_RETURN_NORMAL);
66 }
67 
68 static void
69 cmd_list_panes_server(struct cmd *self, struct cmdq_item *item)
70 {
71  struct session *s;
72 
73  RB_FOREACH(s, sessions, &sessions)
74  cmd_list_panes_session(self, s, item, 2);
75 }
76 
77 static void
78 cmd_list_panes_session(struct cmd *self, struct session *s,
79  struct cmdq_item *item, int type)
80 {
81  struct winlink *wl;
82 
83  RB_FOREACH(wl, winlinks, &s->windows)
84  cmd_list_panes_window(self, s, wl, item, type);
85 }
86 
87 static void
88 cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
89  struct cmdq_item *item, int type)
90 {
91  struct args *args = cmd_get_args(self);
92  struct window_pane *wp;
93  u_int n;
94  struct format_tree *ft;
95  const char *template, *filter;
96  char *line, *expanded;
97  int flag;
98 
99  template = args_get(args, 'F');
100  if (template == NULL) {
101  switch (type) {
102  case 0:
103  template = "#{pane_index}: "
104  "[#{pane_width}x#{pane_height}] [history "
105  "#{history_size}/#{history_limit}, "
106  "#{history_bytes} bytes] #{pane_id}"
107  "#{?pane_active, (active),}#{?pane_dead, (dead),}";
108  break;
109  case 1:
110  template = "#{window_index}.#{pane_index}: "
111  "[#{pane_width}x#{pane_height}] [history "
112  "#{history_size}/#{history_limit}, "
113  "#{history_bytes} bytes] #{pane_id}"
114  "#{?pane_active, (active),}#{?pane_dead, (dead),}";
115  break;
116  case 2:
117  template = "#{session_name}:#{window_index}."
118  "#{pane_index}: [#{pane_width}x#{pane_height}] "
119  "[history #{history_size}/#{history_limit}, "
120  "#{history_bytes} bytes] #{pane_id}"
121  "#{?pane_active, (active),}#{?pane_dead, (dead),}";
122  break;
123  }
124  }
125  filter = args_get(args, 'f');
126 
127  n = 0;
128  TAILQ_FOREACH(wp, &wl->window->panes, entry) {
130  format_add(ft, "line", "%u", n);
131  format_defaults(ft, NULL, s, wl, wp);
132 
133  if (filter != NULL) {
134  expanded = format_expand(ft, filter);
135  flag = format_true(expanded);
136  free(expanded);
137  } else
138  flag = 1;
139  if (flag) {
140  line = format_expand(ft, template);
141  cmdq_print(item, "%s", line);
142  free(line);
143  }
144 
145  format_free(ft);
146  n++;
147  }
148 }
int args_has(struct args *args, u_char flag)
Definition: arguments.c:259
const char * args_get(struct args *args, u_char flag)
Definition: arguments.c:295
const struct cmd_entry cmd_list_panes_entry
static void cmd_list_panes_session(struct cmd *, struct session *, struct cmdq_item *, int)
static void cmd_list_panes_window(struct cmd *, struct session *, struct winlink *, struct cmdq_item *, int)
static void cmd_list_panes_server(struct cmd *, struct cmdq_item *)
static enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmdq_item *)
void cmdq_print(struct cmdq_item *item, const char *fmt,...)
Definition: cmd-queue.c:792
struct client * cmdq_get_client(struct cmdq_item *item)
Definition: cmd-queue.c:150
struct cmd_find_state * cmdq_get_target(struct cmdq_item *item)
Definition: cmd-queue.c:171
struct args * cmd_get_args(struct cmd *cmd)
Definition: cmd.c:393
void format_defaults(struct format_tree *ft, struct client *c, struct session *s, struct winlink *wl, struct window_pane *wp)
Definition: format.c:4684
void format_add(struct format_tree *ft, const char *key, const char *fmt,...)
Definition: format.c:3126
struct format_tree * format_create(struct client *c, struct cmdq_item *item, int tag, int flags)
Definition: format.c:3042
char * format_expand(struct format_tree *ft, const char *fmt)
Definition: format.c:4609
void format_free(struct format_tree *ft)
Definition: format.c:3066
int format_true(const char *s)
Definition: format.c:3471
struct sessions sessions
Definition: session.c:29
Definition: tmux.h:1435
Definition: tmux.h:1525
const char * name
Definition: tmux.h:1526
struct session * s
Definition: tmux.h:1451
struct winlink * wl
Definition: tmux.h:1452
Definition: cmd.c:212
struct window_pane * wp
Definition: format.c:136
struct session * s
Definition: format.c:133
struct winlink * wl
Definition: format.c:134
enum format_type type
Definition: format.c:130
struct cmdq_item * item
Definition: format.c:139
Definition: tmux.h:1179
struct winlinks windows
Definition: tmux.h:1194
struct window_panes panes
Definition: tmux.h:1056
cmd_retval
Definition: tmux.h:1475
@ CMD_RETURN_NORMAL
Definition: tmux.h:1477
#define CMD_AFTERHOOK
Definition: tmux.h:1541
#define CMD_TARGET_WINDOW_USAGE
Definition: tmux.h:1859
#define FORMAT_NONE
Definition: tmux.h:1973
@ CMD_FIND_WINDOW
Definition: tmux.h:1444