summaryrefslogtreecommitdiffstats
path: root/cmd-list-sessions.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-sessions.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-sessions.c')
-rw-r--r--cmd-list-sessions.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c
index 6c0f2dae..10e6b16d 100644
--- a/cmd-list-sessions.c
+++ b/cmd-list-sessions.c
@@ -31,40 +31,45 @@ int cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_list_sessions_entry = {
"list-sessions", "ls",
- "", 0, 0,
- "",
+ "F:", 0, 0,
+ "[-F format]",
0,
NULL,
NULL,
cmd_list_sessions_exec
};
-/* ARGSUSED */
int
-cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
+cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx)
{
+ struct args *args = self->args;
struct session *s;
- struct session_group *sg;
- char *tim, tmp[64];
- u_int idx;
- time_t t;
+ u_int n;
+ struct format_tree *ft;
+ const char *template;
+ char *line;
+ template = args_get(args, 'F');
+ if (template == NULL) {
+ template = "#{session_name}: #{session_windows} windows "
+ "(created #{session_created_string}) [#{session_width}x"
+ "#{session_height}]#{?session_grouped, (group ,}"
+ "#{session_group}#{?session_grouped,),}"
+ "#{?session_attached, (attached),}";
+ }
+
+ n = 0;
RB_FOREACH(s, sessions, &sessions) {
- sg = session_group_find(s);
- if (sg == NULL)
- *tmp = '\0';
- else {
- idx = session_group_index(sg);
- xsnprintf(tmp, sizeof tmp, " (group %u)", idx);
- }
+ ft = format_create();
+ format_add(ft, "line", "%u", n);
+ format_session(ft, s);
- t = s->creation_time.tv_sec;
- tim = ctime(&t);
- *strchr(tim, '\n') = '\0';
+ line = format_expand(ft, template);
+ ctx->print(ctx, "%s", line);
+ xfree(line);
- ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s",
- s->name, winlink_count(&s->windows), tim, s->sx, s->sy,
- tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
+ format_free(ft);
+ n++;
}
return (0);