summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/paste.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-06-21 21:44:10 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-06-21 21:44:10 +0000
commite41d01f868679769ae7e30500e6a41dbdc9613d8 (patch)
tree9c83c9b97d4dd20fd8432bff9f96d3b66a9761ec /usr.bin/tmux/paste.c
parent6efc9494c0e1e839e444f134fd91f4e33b511e77 (diff)
Add a choose-buffer command for easier use of the paste buffer stack.
Diffstat (limited to 'usr.bin/tmux/paste.c')
-rw-r--r--usr.bin/tmux/paste.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/usr.bin/tmux/paste.c b/usr.bin/tmux/paste.c
index 656475b3388..01d4416213f 100644
--- a/usr.bin/tmux/paste.c
+++ b/usr.bin/tmux/paste.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: paste.c,v 1.8 2009/12/03 22:50:10 nicm Exp $ */
+/* $OpenBSD: paste.c,v 1.9 2010/06/21 21:44:09 nicm 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);
+}