diff options
author | Tiago Cunha <tcunha@gmx.com> | 2010-06-22 23:35:20 +0000 |
---|---|---|
committer | Tiago Cunha <tcunha@gmx.com> | 2010-06-22 23:35:20 +0000 |
commit | bf1e23741015c60e869bd0cdff16e86a35195f7d (patch) | |
tree | 4b2d2cd21b102b93ec6614608d7526c6b89acb5a /paste.c | |
parent | 8d3b726396d3f5124d31a792a5f3358357f2e105 (diff) | |
download | rtmux-bf1e23741015c60e869bd0cdff16e86a35195f7d.tar.gz rtmux-bf1e23741015c60e869bd0cdff16e86a35195f7d.tar.bz2 rtmux-bf1e23741015c60e869bd0cdff16e86a35195f7d.zip |
Sync OpenBSD patchset 726:
Add a choose-buffer command for easier use of the paste buffer stack.
Diffstat (limited to 'paste.c')
-rw-r--r-- | paste.c | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -1,4 +1,4 @@ -/* $Id: paste.c,v 1.13 2009-12-04 22:14:47 tcunha Exp $ */ +/* $Id: paste.c,v 1.14 2010-06-22 23:35:20 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -20,6 +20,7 @@ #include <sys/time.h> #include <string.h> +#include <vis.h> #include "tmux.h" @@ -156,3 +157,27 @@ paste_replace(struct paste_stack *ps, u_int idx, char *data, size_t size) return (0); } + +/* Convert a buffer into a visible string. */ +char * +paste_print(struct paste_buffer *pb, size_t width) +{ + char *buf; + size_t len, used; + + if (width < 3) + width = 3; + buf = xmalloc(width * 4 + 1); + + len = pb->size; + if (len > width) + len = width; + + used = strvisx(buf, pb->data, len, VIS_OCTAL|VIS_TAB|VIS_NL); + if (pb->size > width || used > width) { + buf[width - 3] = '\0'; + strlcat(buf, "...", width); + } + + return (buf); +} |