diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-10-12 09:29:59 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-10-12 09:29:59 +0000 |
commit | 40c6298d6b72f9115d128af279ef618475d9c434 (patch) | |
tree | 88df6f4832c7d71d897b9436c444394d9fd92d50 | |
parent | 8e5e41d4e5e420668f51ba6a0b1d7efef91b6c72 (diff) |
Similarly add a tty_cursor_pane function to tidy up most of the calls.
-rw-r--r-- | usr.bin/tmux/screen-redraw.c | 15 | ||||
-rw-r--r-- | usr.bin/tmux/server.c | 6 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 5 | ||||
-rw-r--r-- | usr.bin/tmux/tty.c | 68 |
4 files changed, 53 insertions, 41 deletions
diff --git a/usr.bin/tmux/screen-redraw.c b/usr.bin/tmux/screen-redraw.c index d3bdd6dc67b..3514964cfb9 100644 --- a/usr.bin/tmux/screen-redraw.c +++ b/usr.bin/tmux/screen-redraw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-redraw.c,v 1.11 2009/09/10 17:16:24 nicm Exp $ */ +/* $OpenBSD: screen-redraw.c,v 1.12 2009/10/12 09:29:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -195,7 +195,7 @@ screen_redraw_screen(struct client *c, int status_only) for (i = 0; i < tty->sx; i++) { type = screen_redraw_check_cell(c, i, j); if (type != CELL_INSIDE) { - tty_cursor(tty, i, j, 0, 0); + tty_cursor(tty, i, j); tty_putc(tty, border[type]); } } @@ -239,7 +239,7 @@ screen_redraw_draw_number(struct client *c, struct window_pane *wp) struct tty *tty = &c->tty; struct session *s = c->session; struct grid_cell gc; - u_int idx, px, py, i, j; + u_int idx, px, py, i, j, xoff, yoff; int colour; char buf[16], *ptr; size_t len; @@ -251,10 +251,11 @@ screen_redraw_draw_number(struct client *c, struct window_pane *wp) return; colour = options_get_number(&s->options, "display-panes-colour"); - px = wp->sx / 2; - py = wp->sy / 2; + px = wp->sx / 2; py = wp->sy / 2; + xoff = wp->xoff; yoff = wp->yoff; + if (wp->sx < len * 6 || wp->sy < 5) { - tty_cursor(tty, px - len / 2, py, wp->xoff, wp->yoff); + tty_cursor(tty, xoff + px - len / 2, yoff + py); memcpy(&gc, &grid_default_cell, sizeof gc); colour_set_fg(&gc, colour); tty_attributes(tty, &gc); @@ -275,7 +276,7 @@ screen_redraw_draw_number(struct client *c, struct window_pane *wp) for (j = 0; j < 5; j++) { for (i = px; i < px + 5; i++) { - tty_cursor(tty, i, py + j, wp->xoff, wp->yoff); + tty_cursor(tty, xoff + i, yoff + py + j); if (clock_table[idx][j][i - px]) tty_putc(tty, ' '); } diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c index d27d08de8b7..ad1bcf5e421 100644 --- a/usr.bin/tmux/server.c +++ b/usr.bin/tmux/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.57 2009/10/12 09:16:59 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.58 2009/10/12 09:29:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1054,9 +1054,9 @@ server_handle_client(struct client *c) status = options_get_number(oo, "status"); if (!window_pane_visible(wp) || wp->yoff + s->cy >= c->tty.sy - status) - tty_cursor(&c->tty, 0, 0, 0, 0); + tty_cursor(&c->tty, 0, 0); else - tty_cursor(&c->tty, s->cx, s->cy, wp->xoff, wp->yoff); + tty_cursor(&c->tty, wp->xoff + s->cx, wp->yoff + s->cy); mode = s->mode; if (TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry) != NULL && diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 499a741b88f..4b85f80bc4f 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.133 2009/10/12 09:16:59 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.134 2009/10/12 09:29:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1249,7 +1249,8 @@ void tty_attributes(struct tty *, const struct grid_cell *); void tty_reset(struct tty *); void tty_region_pane(struct tty *, const struct tty_ctx *, u_int, u_int); void tty_region(struct tty *, u_int, u_int); -void tty_cursor(struct tty *, u_int, u_int, u_int, u_int); +void tty_cursor_pane(struct tty *, const struct tty_ctx *, u_int, u_int); +void tty_cursor(struct tty *, u_int, u_int); void tty_putcode(struct tty *, enum tty_code_code); void tty_putcode1(struct tty *, enum tty_code_code, int); void tty_putcode2(struct tty *, enum tty_code_code, int, int); 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); } } |