aboutsummaryrefslogtreecommitdiff
path: root/cmd-choose-buffer.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2012-05-22 21:03:25 +0000
committerTiago Cunha <tcunha@gmx.com>2012-05-22 21:03:25 +0000
commit5cc4961fd28fe920236c6716f6ff751d22d90188 (patch)
tree7cd1846843b9693dd46f0eae010e5297c6f5ce79 /cmd-choose-buffer.c
parentbaafc17a1e9e6b622bcb36dfd096c1316dcbbfda (diff)
downloadrtmux-5cc4961fd28fe920236c6716f6ff751d22d90188.tar.gz
rtmux-5cc4961fd28fe920236c6716f6ff751d22d90188.tar.bz2
rtmux-5cc4961fd28fe920236c6716f6ff751d22d90188.zip
Sync OpenBSD patchset 1119:
Switch all of the various choose- and list- commands over to the format infrastructure, from Thomas Adam.
Diffstat (limited to 'cmd-choose-buffer.c')
-rw-r--r--cmd-choose-buffer.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/cmd-choose-buffer.c b/cmd-choose-buffer.c
index 0b2edb32..29535a26 100644
--- a/cmd-choose-buffer.c
+++ b/cmd-choose-buffer.c
@@ -33,8 +33,8 @@ void cmd_choose_buffer_free(void *);
const struct cmd_entry cmd_choose_buffer_entry = {
"choose-buffer", NULL,
- "t:", 0, 1,
- CMD_TARGET_WINDOW_USAGE " [template]",
+ "F:t:", 0, 1,
+ CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
0,
NULL,
NULL,
@@ -53,14 +53,19 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
struct cmd_choose_buffer_data *cdata;
struct winlink *wl;
struct paste_buffer *pb;
+ struct format_tree *ft;
u_int idx;
- char *tmp;
+ char *line;
+ const char *template;
if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively");
return (-1);
}
+ if ((template = args_get(args, 'F')) == NULL)
+ template = DEFAULT_BUFFER_LIST_TEMPLATE;
+
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
return (-1);
@@ -72,10 +77,15 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
idx = 0;
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
- tmp = paste_print(pb, 50);
- window_choose_add(wl->window->active, idx - 1,
- "%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);
+ window_choose_add(wl->window->active, idx - 1, "%s", line);
+
+ xfree(line);
+ format_free(ft);
}
cdata = xmalloc(sizeof *cdata);