=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/screen-write.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- src/usr.bin/tmux/screen-write.c 2009/10/12 17:19:47 1.30 +++ src/usr.bin/tmux/screen-write.c 2009/10/17 08:24:46 1.31 @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-write.c,v 1.30 2009/10/12 17:19:47 nicm Exp $ */ +/* $OpenBSD: screen-write.c,v 1.31 2009/10/17 08:24:46 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -22,7 +22,7 @@ #include "tmux.h" -void screen_write_initctx(struct screen_write_ctx *, struct tty_ctx *); +void screen_write_initctx(struct screen_write_ctx *, struct tty_ctx *, int); void screen_write_overwrite(struct screen_write_ctx *); /* Initialise writing with a window. */ @@ -418,9 +418,14 @@ /* Set up context for TTY command. */ void -screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx) +screen_write_initctx( + struct screen_write_ctx *ctx, struct tty_ctx *ttyctx, int save_last) { - struct screen *s = ctx->s; + struct screen *s = ctx->s; + struct grid *gd = s->grid; + const struct grid_cell *gc; + const struct grid_utf8 *gu; + u_int xx; ttyctx->wp = ctx->wp; @@ -429,6 +434,23 @@ ttyctx->orlower = s->rlower; ttyctx->orupper = s->rupper; + + if (!save_last) + return; + + /* Save the last cell on the screen. */ + gc = NULL; + for (xx = 1; xx < screen_size_x(s); xx++) { + gc = grid_view_peek_cell(gd, screen_size_x(s) - xx, s->cy); + if (!(gc->flags & GRID_FLAG_PADDING)) + break; + } + ttyctx->last_width = xx; + memcpy(&ttyctx->last_cell, gc, sizeof ttyctx->last_cell); + if (gc->flags & GRID_FLAG_UTF8) { + gu = grid_view_peek_utf8(gd, screen_size_x(s) - xx, s->cy); + memcpy(&ttyctx->last_utf8, gu, sizeof ttyctx->last_utf8); + } } /* Cursor up by ny. */ @@ -541,7 +563,7 @@ struct grid_cell gc; u_int xx, yy; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); memcpy(&gc, &grid_default_cell, sizeof gc); gc.data = 'E'; @@ -576,7 +598,7 @@ if (nx == 0) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); if (s->cx <= screen_size_x(s) - 1) grid_view_insert_cells(s->grid, s->cx, s->cy, nx); @@ -600,7 +622,7 @@ if (nx == 0) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); if (s->cx <= screen_size_x(s) - 1) grid_view_delete_cells(s->grid, s->cx, s->cy, nx); @@ -625,7 +647,7 @@ if (ny == 0) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); grid_view_insert_lines(s->grid, s->cy, ny); @@ -639,7 +661,7 @@ if (ny == 0) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); if (s->cy < s->rupper || s->cy > s->rlower) grid_view_insert_lines(s->grid, s->cy, ny); @@ -666,7 +688,7 @@ if (ny == 0) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); grid_view_delete_lines(s->grid, s->cy, ny); @@ -680,7 +702,7 @@ if (ny == 0) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); if (s->cy < s->rupper || s->cy > s->rlower) grid_view_delete_lines(s->grid, s->cy, ny); @@ -698,7 +720,7 @@ struct screen *s = ctx->s; struct tty_ctx ttyctx; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); grid_view_clear(s->grid, 0, s->cy, screen_size_x(s), 1); @@ -713,7 +735,7 @@ struct tty_ctx ttyctx; u_int sx; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); sx = screen_size_x(s); @@ -731,7 +753,7 @@ struct tty_ctx ttyctx; u_int sx; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); sx = screen_size_x(s); @@ -777,7 +799,7 @@ struct screen *s = ctx->s; struct tty_ctx ttyctx; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); if (s->cy == s->rupper) grid_view_scroll_region_down(s->grid, s->rupper, s->rlower); @@ -861,7 +883,7 @@ { struct tty_ctx ttyctx; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); screen_write_linefeedscreen(ctx, wrapped); @@ -909,7 +931,7 @@ struct tty_ctx ttyctx; u_int sx, sy; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); sx = screen_size_x(s); sy = screen_size_y(s); @@ -929,7 +951,7 @@ struct tty_ctx ttyctx; u_int sx; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); sx = screen_size_x(s); @@ -950,7 +972,7 @@ struct screen *s = ctx->s; struct tty_ctx ttyctx; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); grid_view_clear(s->grid, 0, 0, screen_size_x(s), screen_size_y(s)); @@ -1004,8 +1026,12 @@ } memcpy(tmp_gu->data + i, udata, UTF8_SIZE - i); - /* Assume the previous character has just been input. */ - screen_write_initctx(ctx, &ttyctx); + /* + * Assume the previous character has just been input. + * XXX There is no guarantee this is true, need to redraw + * entire line. + */ + screen_write_initctx(ctx, &ttyctx, 0); ttyctx.ptr = udata; tty_write(tty_cmd_utf8character, &ttyctx); return; @@ -1019,6 +1045,9 @@ gc = &tmp_gc; } + /* Initialise the redraw context, saving the last cell. */ + screen_write_initctx(ctx, &ttyctx, 1); + /* If in insert mode, make space for the cells. */ if (s->mode & MODE_INSERT && s->cx <= screen_size_x(s) - width) { xx = screen_size_x(s) - s->cx - width; @@ -1063,7 +1092,6 @@ grid_view_set_utf8(gd, s->cx, s->cy, &gu); /* Move the cursor. */ - screen_write_initctx(ctx, &ttyctx); s->cx += width; /* Draw to the screen if necessary. */