diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-05-22 11:35:38 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-05-22 11:35:38 +0000 |
commit | 78cd304b7b07161637cb18551d43b87d7e1f7be4 (patch) | |
tree | ad6f80162d80948362de9d2484e783186a92d6e0 /usr.bin/tmux/cmd-list-buffers.c | |
parent | 1a47989e1c6a692ac3c72e02286e5f1fcafc90da (diff) |
Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.
Diffstat (limited to 'usr.bin/tmux/cmd-list-buffers.c')
-rw-r--r-- | usr.bin/tmux/cmd-list-buffers.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-list-buffers.c b/usr.bin/tmux/cmd-list-buffers.c index 6283c85d622..9e1eefb5abc 100644 --- a/usr.bin/tmux/cmd-list-buffers.c +++ b/usr.bin/tmux/cmd-list-buffers.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-buffers.c,v 1.11 2011/01/04 00:42:46 nicm Exp $ */ +/* $OpenBSD: cmd-list-buffers.c,v 1.12 2012/05/22 11:35:37 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -30,8 +30,8 @@ int cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_list_buffers_entry = { "list-buffers", "lsb", - "", 0, 0, - "", + "F:", 0, 0, + "[-F format]", 0, NULL, NULL, @@ -42,16 +42,27 @@ const struct cmd_entry cmd_list_buffers_entry = { int cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx) { + struct args *args = self->args; struct paste_buffer *pb; + struct format_tree *ft; u_int idx; - char *tmp; + char *line; + const char *template; + + if ((template = args_get(args, 'F')) == NULL) + template = DEFAULT_BUFFER_LIST_TEMPLATE; idx = 0; while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) { - tmp = paste_print(pb, 50); - ctx->print(ctx, - "%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp); - xfree(tmp); + ft = format_create(); + format_add(ft, "line", "%u", idx - 1); + format_paste_buffer(ft, pb); + + line = format_expand(ft, template); + ctx->print(ctx, "%s", line); + xfree(line); + + format_free(ft); } return (0); |