=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/paste.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- src/usr.bin/tmux/paste.c 2009/12/03 22:50:10 1.8 +++ src/usr.bin/tmux/paste.c 2010/06/21 21:44:09 1.9 @@ -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 @@ -20,6 +20,7 @@ #include #include +#include #include "tmux.h" @@ -155,4 +156,28 @@ pb->size = 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); }