summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/tty.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2017-03-15 09:21:21 +0000
committernicm <nicm@openbsd.org>2017-03-15 09:21:21 +0000
commit0f15a47abcf6262425cfa23abe446a7e64f0a16c (patch)
tree04aa2f4fcf8f677d162ef3bc05e6a7039435f9c1 /usr.bin/tmux/tty.c
parentdisallow KEXINIT before NEWKEYS; ok djm; report by vegard.nossum at oracle.com (diff)
downloadwireguard-openbsd-0f15a47abcf6262425cfa23abe446a7e64f0a16c.tar.xz
wireguard-openbsd-0f15a47abcf6262425cfa23abe446a7e64f0a16c.zip
Try to avoid moving the cursor to the start of the next line when
printing cells if it is already at the very end of the line and the terminal will wrap it to the next line itself, this means terminals still see it as a wrapped line for the purposes of their own mouse selection. Reported by millert@.
Diffstat (limited to 'usr.bin/tmux/tty.c')
-rw-r--r--usr.bin/tmux/tty.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c
index a8eab257c57..9a4d9d1b47d 100644
--- a/usr.bin/tmux/tty.c
+++ b/usr.bin/tmux/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.252 2017/03/08 14:34:35 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.253 2017/03/15 09:21:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -41,6 +41,8 @@ static int tty_try_colour(struct tty *, int, const char *);
static void tty_force_cursor_colour(struct tty *, const char *);
static void tty_cursor_pane(struct tty *, const struct tty_ctx *, u_int,
u_int);
+static void tty_cursor_pane_unless_wrap(struct tty *,
+ const struct tty_ctx *, u_int, u_int);
static void tty_invalidate(struct tty *);
static void tty_colours(struct tty *, const struct grid_cell *);
static void tty_check_fg(struct tty *, const struct window_pane *,
@@ -1188,7 +1190,7 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
tty_margin_off(tty);
}
- tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
+ tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy);
tty_cell(tty, ctx->cell, ctx->wp);
}
@@ -1196,7 +1198,7 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
void
tty_cmd_cells(struct tty *tty, const struct tty_ctx *ctx)
{
- tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
+ tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy);
tty_attributes(tty, ctx->cell, ctx->wp);
tty_putn(tty, ctx->ptr, ctx->num, ctx->num);
@@ -1389,6 +1391,24 @@ tty_margin(struct tty *tty, u_int rleft, u_int rright)
tty->cx = tty->cy = UINT_MAX;
}
+/*
+ * Move the cursor, unless it would wrap itself when the next character is
+ * printed.
+ */
+static void
+tty_cursor_pane_unless_wrap(struct tty *tty, const struct tty_ctx *ctx,
+ u_int cx, u_int cy)
+{
+ if (!tty_pane_full_width(tty, ctx) ||
+ (tty->term->flags & TERM_EARLYWRAP) ||
+ ctx->xoff + cx != 0 ||
+ ctx->yoff + cy != tty->cy + 1 ||
+ tty->cx < tty->sx)
+ tty_cursor_pane(tty, ctx, cx, cy);
+ else
+ log_debug("%s: will wrap at %u,%u", __func__, tty->cx, tty->cy);
+}
+
/* Move cursor inside pane. */
static void
tty_cursor_pane(struct tty *tty, const struct tty_ctx *ctx, u_int cx, u_int cy)