diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-08-26 10:53:17 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-08-26 10:53:17 +0000 |
commit | 7d0c27e57c5433127a6b066490225462a0ca43ef (patch) | |
tree | 27bf008a9d47b95e8565441e4aba11c8d53bf548 /usr.bin/tmux/cmd-list-sessions.c | |
parent | d247255c032f05d4da81025e9b0dfcd4552c02e7 (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 'usr.bin/tmux/cmd-list-sessions.c')
-rw-r--r-- | usr.bin/tmux/cmd-list-sessions.c | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/usr.bin/tmux/cmd-list-sessions.c b/usr.bin/tmux/cmd-list-sessions.c index 1361b35517a..fde0e7faa26 100644 --- a/usr.bin/tmux/cmd-list-sessions.c +++ b/usr.bin/tmux/cmd-list-sessions.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-sessions.c,v 1.9 2011/01/04 00:42:46 nicm Exp $ */ +/* $OpenBSD: cmd-list-sessions.c,v 1.10 2011/08/26 10:53:16 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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); |