summaryrefslogtreecommitdiffstats
path: root/paste.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2010-06-21 21:44:09 +0000
committerNicholas Marriott <nicm@openbsd.org>2010-06-21 21:44:09 +0000
commitef7293379f00b85cb96dd0dff128bb503e87612b (patch)
tree10ecce1d0eddb56d6c0beb008ddc87c87d703927 /paste.c
parent386849edc1d7d322d6a48d334f83298ff7cb5501 (diff)
Add a choose-buffer command for easier use of the paste buffer stack.
Diffstat (limited to 'paste.c')
-rw-r--r--paste.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/paste.c b/paste.c
index 4596ce95..da93129a 100644
--- a/paste.c
+++ b/paste.c
@@ -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);
+}