summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-07-21 05:24:34 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-07-21 05:24:34 +0000
commita054d63e0f49d0c26d394e3fc6acdff9196a7e99 (patch)
tree9b55ce36d891b3d707ee93e999f5f52672039667
parent5d4f7858b122c5b3804fb1f743efee0b5c62d194 (diff)
Fix show-buffer when run from inside tmux, GitHub issue 2314.
-rw-r--r--usr.bin/tmux/cmd-save-buffer.c16
-rw-r--r--usr.bin/tmux/screen-write.c7
-rw-r--r--usr.bin/tmux/tmux.h3
-rw-r--r--usr.bin/tmux/utf8.c16
4 files changed, 34 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-save-buffer.c b/usr.bin/tmux/cmd-save-buffer.c
index 1a31ad951e0..cb968126bad 100644
--- a/usr.bin/tmux/cmd-save-buffer.c
+++ b/usr.bin/tmux/cmd-save-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-save-buffer.c,v 1.50 2020/04/13 20:51:57 nicm Exp $ */
+/* $OpenBSD: cmd-save-buffer.c,v 1.51 2020/07/21 05:24:33 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -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;
diff --git a/usr.bin/tmux/screen-write.c b/usr.bin/tmux/screen-write.c
index 8ebbea652db..4fc124f127e 100644
--- a/usr.bin/tmux/screen-write.c
+++ b/usr.bin/tmux/screen-write.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: screen-write.c,v 1.186 2020/07/06 10:07:02 nicm Exp $ */
+/* $OpenBSD: screen-write.c,v 1.187 2020/07/21 05:24:33 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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);
}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 82a0cf06bbc..8d6c13a9e9c 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.1073 2020/07/06 09:14:20 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1074 2020/07/21 05:24:33 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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);
diff --git a/usr.bin/tmux/utf8.c b/usr.bin/tmux/utf8.c
index 3f4a10aca91..a369b2b76ef 100644
--- a/usr.bin/tmux/utf8.c
+++ b/usr.bin/tmux/utf8.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: utf8.c,v 1.55 2020/06/09 10:37:00 nicm Exp $ */
+/* $OpenBSD: utf8.c,v 1.56 2020/07/21 05:24:33 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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)