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.
This commit is contained in:
Nicholas Marriott
2011-08-26 10:53:16 +00:00
parent 4697b35d4f
commit 4a5dff3f11
7 changed files with 578 additions and 96 deletions

View File

@ -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++;
}
}