aboutsummaryrefslogtreecommitdiff
path: root/cmd-list-windows.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2011-09-21 16:31:15 +0000
committerTiago Cunha <tcunha@gmx.com>2011-09-21 16:31:15 +0000
commit40af1a854c17722e70f9c28882020f2fa65a1959 (patch)
tree1fea7d8f5afb8717986352f29c44c86eafd2af70 /cmd-list-windows.c
parentfb5b95883777c61cae129d4b01abc6776ba9005c (diff)
downloadrtmux-40af1a854c17722e70f9c28882020f2fa65a1959.tar.gz
rtmux-40af1a854c17722e70f9c28882020f2fa65a1959.tar.bz2
rtmux-40af1a854c17722e70f9c28882020f2fa65a1959.zip
Sync OpenBSD patchset 953:
Add initial framework for more powerful formatting of command output and use it for list-{panes,windows,sessions}. This allows more descriptive replacements (such as #{session_name}) and conditionals. Later this will be used for status_replace and list-keys and other places.
Diffstat (limited to 'cmd-list-windows.c')
-rw-r--r--cmd-list-windows.c73
1 files changed, 49 insertions, 24 deletions
diff --git a/cmd-list-windows.c b/cmd-list-windows.c
index 0bfe94ed..1b34b1c2 100644
--- a/cmd-list-windows.c
+++ b/cmd-list-windows.c
@@ -28,13 +28,14 @@
int cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
-void cmd_list_windows_server(struct cmd_ctx *);
-void cmd_list_windows_session(struct session *, struct cmd_ctx *, int);
+void cmd_list_windows_server(struct cmd *, struct cmd_ctx *);
+void cmd_list_windows_session(
+ struct cmd *, struct session *, struct cmd_ctx *, int);
const struct cmd_entry cmd_list_windows_entry = {
"list-windows", "lsw",
- "at:", 0, 0,
- "[-a] " CMD_TARGET_SESSION_USAGE,
+ "aF:t:", 0, 0,
+ "[-a] [-F format] " CMD_TARGET_SESSION_USAGE,
0,
NULL,
NULL,
@@ -48,45 +49,69 @@ cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
struct session *s;
if (args_has(args, 'a'))
- cmd_list_windows_server(ctx);
+ cmd_list_windows_server(self, ctx);
else {
s = cmd_find_session(ctx, args_get(args, 't'), 0);
if (s == NULL)
return (-1);
- cmd_list_windows_session(s, ctx, 0);
+ cmd_list_windows_session(self, s, ctx, 0);
}
return (0);
}
void
-cmd_list_windows_server(struct cmd_ctx *ctx)
+cmd_list_windows_server(struct cmd *self, struct cmd_ctx *ctx)
{
struct session *s;
RB_FOREACH(s, sessions, &sessions)
- cmd_list_windows_session(s, ctx, 1);
+ cmd_list_windows_session(self, s, ctx, 1);
}
void
-cmd_list_windows_session(struct session *s, struct cmd_ctx *ctx, int type)
+cmd_list_windows_session(
+ struct cmd *self, struct session *s, struct cmd_ctx *ctx, int type)
{
- struct winlink *wl;
- char *layout;
+ struct args *args = self->args;
+ struct winlink *wl;
+ u_int n;
+ struct format_tree *ft;
+ const char *template;
+ char *line;
- RB_FOREACH(wl, winlinks, &s->windows) {
- layout = layout_dump(wl->window);
- if (type) {
- ctx->print(ctx, "%s:%d: %s [%ux%u] [layout %s]%s",
- s->name, wl->idx, wl->window->name, wl->window->sx,
- wl->window->sy, layout,
- wl == s->curw ? " (active)" : "");
- } else {
- ctx->print(ctx, "%d: %s [%ux%u] [layout %s]%s",
- wl->idx, wl->window->name, wl->window->sx,
- wl->window->sy, layout,
- wl == s->curw ? " (active)" : "");
+ template = args_get(args, 'F');
+ if (template == NULL) {
+ switch (type) {
+ case 0:
+ template = "#{window_index}: "
+ "#{window_name} "
+ "[#{window_width}x#{window_height}] "
+ "[layout #{window_layout}]"
+ "#{?window_active, (active),}";
+ break;
+ case 1:
+ template = "#{session_name):#{window_index}: "
+ "#{window_name} "
+ "[#{window_width}x#{window_height}] "
+ "[layout #{window_layout}]"
+ "#{?window_active, (active),}";
+ break;
}
- xfree(layout);
+ }
+
+ n = 0;
+ RB_FOREACH(wl, winlinks, &s->windows) {
+ ft = format_create();
+ format_add(ft, "line", "%u", n);
+ format_session(ft, s);
+ format_winlink(ft, s, wl);
+
+ line = format_expand(ft, template);
+ ctx->print(ctx, "%s", line);
+ xfree(line);
+
+ format_free(ft);
+ n++;
}
}