summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/tty.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2009-10-12 09:29:58 +0000
committernicm <nicm@openbsd.org>2009-10-12 09:29:58 +0000
commitc222f54155ce527fce9090acd3921dd96d5f85d5 (patch)
treef634ac46e08e78009f9e5bd40b0804b2552101c1 /usr.bin/tmux/tty.c
parent_absolute is redundant, just use tty_region. (diff)
downloadwireguard-openbsd-c222f54155ce527fce9090acd3921dd96d5f85d5.tar.xz
wireguard-openbsd-c222f54155ce527fce9090acd3921dd96d5f85d5.zip
Similarly add a tty_cursor_pane function to tidy up most of the calls.
Diffstat (limited to 'usr.bin/tmux/tty.c')
-rw-r--r--usr.bin/tmux/tty.c68
1 files changed, 39 insertions, 29 deletions
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c
index 65147dc410e..663010d98bd 100644
--- a/usr.bin/tmux/tty.c
+++ b/usr.bin/tmux/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.40 2009/10/12 09:16:59 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.41 2009/10/12 09:29:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -451,7 +451,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy)
if (sx > tty->sx)
sx = tty->sx;
- tty_cursor(tty, 0, py, ox, oy);
+ tty_cursor(tty, ox, oy + py);
for (i = 0; i < sx; i++) {
gc = grid_view_peek_cell(s->grid, i, py);
@@ -477,7 +477,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy)
}
tty_reset(tty);
- tty_cursor(tty, sx, py, ox, oy);
+ tty_cursor(tty, ox + sx, oy + py);
if (screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL))
tty_putcode(tty, TTYC_EL);
else {
@@ -532,7 +532,8 @@ tty_cmd_insertcharacter(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
- tty_cursor(tty, ctx->ocx, ctx->ocy, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
+
if (tty_term_has(tty->term, TTYC_ICH) ||
tty_term_has(tty->term, TTYC_ICH1))
tty_emulate_repeat(tty, TTYC_ICH, TTYC_ICH1, ctx->num);
@@ -559,7 +560,8 @@ tty_cmd_deletecharacter(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
- tty_cursor(tty, ctx->ocx, ctx->ocy, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
+
if (tty_term_has(tty->term, TTYC_DCH) ||
tty_term_has(tty->term, TTYC_DCH1))
tty_emulate_repeat(tty, TTYC_DCH, TTYC_DCH1, ctx->num);
@@ -580,8 +582,8 @@ tty_cmd_insertline(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
+ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
- tty_cursor(tty, ctx->ocx, ctx->ocy, wp->xoff, wp->yoff);
tty_emulate_repeat(tty, TTYC_IL, TTYC_IL1, ctx->num);
}
@@ -600,8 +602,8 @@ tty_cmd_deleteline(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
+ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
- tty_cursor(tty, ctx->ocx, ctx->ocy, wp->xoff, wp->yoff);
tty_emulate_repeat(tty, TTYC_DL, TTYC_DL1, ctx->num);
}
@@ -614,7 +616,8 @@ tty_cmd_clearline(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
- tty_cursor(tty, 0, ctx->ocy, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, 0, ctx->ocy);
+
if (wp->xoff == 0 && screen_size_x(s) >= tty->sx &&
tty_term_has(tty->term, TTYC_EL)) {
tty_putcode(tty, TTYC_EL);
@@ -633,7 +636,8 @@ tty_cmd_clearendofline(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
- tty_cursor(tty, ctx->ocx, ctx->ocy, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
+
if (wp->xoff == 0 && screen_size_x(s) >= tty->sx &&
tty_term_has(tty->term, TTYC_EL))
tty_putcode(tty, TTYC_EL);
@@ -652,10 +656,10 @@ tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
if (wp->xoff == 0 && tty_term_has(tty->term, TTYC_EL1)) {
- tty_cursor(tty, ctx->ocx, ctx->ocy, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
tty_putcode(tty, TTYC_EL1);
} else {
- tty_cursor(tty, 0, ctx->ocy, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, 0, ctx->ocy);
for (i = 0; i < ctx->ocx + 1; i++)
tty_putc(tty, ' ');
}
@@ -677,7 +681,7 @@ tty_cmd_reverseindex(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
- tty_cursor(tty, ctx->ocx, ctx->orupper, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->orupper);
tty_putcode(tty, TTYC_RI);
}
@@ -699,7 +703,7 @@ tty_cmd_linefeed(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
- tty_cursor(tty, ctx->ocx, ctx->ocy, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
tty_putc(tty, '\n');
}
@@ -715,13 +719,13 @@ tty_cmd_clearendofscreen(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1);
- tty_cursor(tty, ctx->ocx, ctx->ocy, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
if (wp->xoff == 0 && screen_size_x(s) >= tty->sx &&
tty_term_has(tty->term, TTYC_EL)) {
tty_putcode(tty, TTYC_EL);
if (ctx->ocy != screen_size_y(s) - 1) {
- tty_cursor(tty, 0, ctx->ocy + 1, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, 0, ctx->ocy + 1);
for (i = ctx->ocy + 1; i < screen_size_y(s); i++) {
tty_putcode(tty, TTYC_EL);
if (i == screen_size_y(s) - 1)
@@ -734,7 +738,7 @@ tty_cmd_clearendofscreen(struct tty *tty, const struct tty_ctx *ctx)
for (i = ctx->ocx; i < screen_size_x(s); i++)
tty_putc(tty, ' ');
for (j = ctx->ocy; j < screen_size_y(s); j++) {
- tty_cursor(tty, 0, j, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, 0, j);
for (i = 0; i < screen_size_x(s); i++)
tty_putc(tty, ' ');
}
@@ -751,7 +755,7 @@ tty_cmd_clearstartofscreen(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1);
- tty_cursor(tty, 0, 0, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, 0, 0);
if (wp->xoff == 0 && screen_size_x(s) >= tty->sx &&
tty_term_has(tty->term, TTYC_EL)) {
@@ -762,7 +766,7 @@ tty_cmd_clearstartofscreen(struct tty *tty, const struct tty_ctx *ctx)
}
} else {
for (j = 0; j < ctx->ocy; j++) {
- tty_cursor(tty, 0, j, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, 0, j);
for (i = 0; i < screen_size_x(s); i++)
tty_putc(tty, ' ');
}
@@ -781,7 +785,7 @@ tty_cmd_clearscreen(struct tty *tty, const struct tty_ctx *ctx)
tty_reset(tty);
tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1);
- tty_cursor(tty, 0, 0, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, 0, 0);
if (wp->xoff == 0 && screen_size_x(s) >= tty->sx &&
tty_term_has(tty->term, TTYC_EL)) {
@@ -794,7 +798,7 @@ tty_cmd_clearscreen(struct tty *tty, const struct tty_ctx *ctx)
}
} else {
for (j = 0; j < screen_size_y(s); j++) {
- tty_cursor(tty, 0, j, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, 0, j);
for (i = 0; i < screen_size_x(s); i++)
tty_putc(tty, ' ');
}
@@ -813,7 +817,7 @@ tty_cmd_alignmenttest(struct tty *tty, const struct tty_ctx *ctx)
tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1);
for (j = 0; j < screen_size_y(s); j++) {
- tty_cursor(tty, 0, j, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, 0, j);
for (i = 0; i < screen_size_x(s); i++)
tty_putc(tty, 'E');
}
@@ -822,9 +826,7 @@ tty_cmd_alignmenttest(struct tty *tty, const struct tty_ctx *ctx)
void
tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
{
- struct window_pane *wp = ctx->wp;
-
- tty_cursor(tty, ctx->ocx, ctx->ocy, wp->xoff, wp->yoff);
+ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
tty_cell(tty, ctx->cell, ctx->utf8);
}
@@ -922,14 +924,22 @@ tty_region(struct tty *tty, u_int rupper, u_int rlower)
}
void
-tty_cursor(struct tty *tty, u_int cx, u_int cy, u_int ox, u_int oy)
+tty_cursor_pane(struct tty *tty, const struct tty_ctx *ctx, u_int cx, u_int cy)
+{
+ struct window_pane *wp = ctx->wp;
+
+ tty_cursor(tty, wp->xoff + cx, wp->yoff + cy);
+}
+
+void
+tty_cursor(struct tty *tty, u_int cx, u_int cy)
{
- if (ox + cx == 0 && tty->cx != 0 && tty->cy == oy + cy) {
+ if (cx == 0 && tty->cx != 0 && tty->cy == cy) {
tty->cx = 0;
tty_putc(tty, '\r');
- } else if (tty->cx != ox + cx || tty->cy != oy + cy) {
- tty->cx = ox + cx;
- tty->cy = oy + cy;
+ } else if (tty->cx != cx || tty->cy != cy) {
+ tty->cx = cx;
+ tty->cy = cy;
tty_putcode2(tty, TTYC_CUP, tty->cy, tty->cx);
}
}