summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/paste.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2014-04-02 18:12:18 +0000
committernicm <nicm@openbsd.org>2014-04-02 18:12:18 +0000
commitdbbd1b468843e6aacd4f38a2e457a78679e18a18 (patch)
tree907c5ceb12898d50c0b1b63034c022140be8ac8c /usr.bin/tmux/paste.c
parentUse the same logic for bell with and without visual-bell, from Filip (diff)
downloadwireguard-openbsd-dbbd1b468843e6aacd4f38a2e457a78679e18a18.tar.xz
wireguard-openbsd-dbbd1b468843e6aacd4f38a2e457a78679e18a18.zip
Support UTF-8 with choose-buffer, from Kosuke ASAMI. Also make
buffer_sample bigger to let it trim at window right edge.
Diffstat (limited to 'usr.bin/tmux/paste.c')
-rw-r--r--usr.bin/tmux/paste.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/usr.bin/tmux/paste.c b/usr.bin/tmux/paste.c
index 43c9d02803a..8aa385695e4 100644
--- a/usr.bin/tmux/paste.c
+++ b/usr.bin/tmux/paste.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: paste.c,v 1.16 2014/03/31 21:39:31 nicm Exp $ */
+/* $OpenBSD: paste.c,v 1.17 2014/04/02 18:12:18 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -148,25 +148,26 @@ paste_replace(struct paste_stack *ps, u_int idx, char *data, size_t size)
return (0);
}
-/* Convert a buffer into a visible string. */
+/* Convert start of buffer into a nice string. */
char *
-paste_print(struct paste_buffer *pb, size_t width)
+paste_make_sample(struct paste_buffer *pb, int utf8flag)
{
- char *buf;
- size_t len, used;
-
- if (width < 3)
- width = 3;
- buf = xmalloc(width * 4 + 1);
+ char *buf;
+ size_t len, used;
+ const int flags = VIS_OCTAL|VIS_TAB|VIS_NL;
+ const size_t width = 200;
len = pb->size;
if (len > width)
len = width;
+ buf = xmalloc(len * 4 + 4);
- used = strvisx(buf, pb->data, len, VIS_OCTAL|VIS_TAB|VIS_NL);
+ if (utf8flag)
+ used = utf8_strvis(buf, pb->data, len, flags);
+ else
+ used = strvisx(buf, pb->data, len, flags);
if (pb->size > width || used > width)
- strlcpy(buf + width - 3, "...", 4);
-
+ strlcpy(buf + width, "...", 4);
return (buf);
}