summaryrefslogtreecommitdiffstats
path: root/paste.c
diff options
context:
space:
mode:
authornicm <nicm>2014-04-02 18:12:18 +0000
committernicm <nicm>2014-04-02 18:12:18 +0000
commit252a7373d69646ae866e3a4fa18d46f673864c0e (patch)
tree3fdd2160affd9a9321157b11ce57bc8d4034e963 /paste.c
parent82f3e0e9e68d4078555cd6270473c45a3e60273b (diff)
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 'paste.c')
-rw-r--r--paste.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/paste.c b/paste.c
index 4ec87f35..98d71a07 100644
--- a/paste.c
+++ b/paste.c
@@ -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);
}