Fix show-buffer when run from inside tmux, GitHub issue 2314.

pull/2359/head
nicm 2020-07-21 05:24:33 +00:00
parent 3b089fc69f
commit 743ab5728d
4 changed files with 30 additions and 4 deletions

View File

@ -74,11 +74,12 @@ static enum cmd_retval
cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct client *c = cmdq_get_client(item);
struct paste_buffer *pb;
int flags;
const char *bufname = args_get(args, 'b'), *bufdata;
size_t bufsize;
char *path;
char *path, *tmp;
if (bufname == NULL) {
if ((pb = paste_get_top(NULL)) == NULL) {
@ -94,9 +95,16 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
}
bufdata = paste_buffer_data(pb, &bufsize);
if (cmd_get_entry(self) == &cmd_show_buffer_entry)
if (cmd_get_entry(self) == &cmd_show_buffer_entry) {
if (c->session != NULL || (c->flags & CLIENT_CONTROL)) {
utf8_stravisx(&tmp, bufdata, bufsize,
VIS_OCTAL|VIS_CSTYLE|VIS_TAB);
cmdq_print(item, "%s", tmp);
free(tmp);
return (CMD_RETURN_NORMAL);
}
path = xstrdup("-");
else
} else
path = format_single_from_target(item, args->argv[0]);
if (args_has(args, 'a'))
flags = O_APPEND;

View File

@ -514,7 +514,10 @@ screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
if (*ptr == '\001')
gc.attr ^= GRID_ATTR_CHARSET;
else if (*ptr > 0x1f && *ptr < 0x7f) {
else if (*ptr == '\n') {
screen_write_linefeed(ctx, 0, 8);
screen_write_carriagereturn(ctx);
} else if (*ptr > 0x1f && *ptr < 0x7f) {
size++;
screen_write_putc(ctx, &gc, *ptr);
}

1
tmux.h
View File

@ -2940,6 +2940,7 @@ enum utf8_state utf8_append(struct utf8_data *, u_char);
int utf8_isvalid(const char *);
int utf8_strvis(char *, const char *, size_t, int);
int utf8_stravis(char **, const char *, int);
int utf8_stravisx(char **, const char *, size_t, int);
char *utf8_sanitize(const char *);
size_t utf8_strlen(const struct utf8_data *);
u_int utf8_strwidth(const struct utf8_data *, ssize_t);

14
utf8.c
View File

@ -341,6 +341,20 @@ utf8_stravis(char **dst, const char *src, int flag)
return (len);
}
/* Same as utf8_strvis but allocate the buffer. */
int
utf8_stravisx(char **dst, const char *src, size_t srclen, int flag)
{
char *buf;
int len;
buf = xreallocarray(NULL, 4, srclen + 1);
len = utf8_strvis(buf, src, srclen, flag);
*dst = xrealloc(buf, len + 1);
return (len);
}
/* Does this string contain anything that isn't valid UTF-8? */
int
utf8_isvalid(const char *s)