summaryrefslogtreecommitdiffstats
path: root/cmd-list-windows.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2011-08-26 10:53:16 +0000
committerNicholas Marriott <nicm@openbsd.org>2011-08-26 10:53:16 +0000
commit4a5dff3f114c9d548a762fb4c5b3003d0a6f406f (patch)
tree1c982474d2a308d1a06b4224630f9d7a57fbc88b /cmd-list-windows.c
parent4697b35d4f84efb5ecd618d62cfa915535fd8020 (diff)
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 239f69f7..30adeb6e 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++;
}
}