=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/screen-write.c,v retrieving revision 1.88 retrieving revision 1.89 diff -c -r1.88 -r1.89 *** src/usr.bin/tmux/screen-write.c 2016/05/27 23:06:12 1.88 --- src/usr.bin/tmux/screen-write.c 2016/05/30 09:32:24 1.89 *************** *** 1,4 **** ! /* $OpenBSD: screen-write.c,v 1.88 2016/05/27 23:06:12 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: screen-write.c,v 1.89 2016/05/30 09:32:24 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 28,34 **** static void screen_write_save_last(struct screen_write_ctx *, struct tty_ctx *); ! static void screen_write_overwrite(struct screen_write_ctx *, u_int); static int screen_write_combine(struct screen_write_ctx *, const struct utf8_data *); --- 28,35 ---- static void screen_write_save_last(struct screen_write_ctx *, struct tty_ctx *); ! static int screen_write_overwrite(struct screen_write_ctx *, ! struct grid_cell *, u_int); static int screen_write_combine(struct screen_write_ctx *, const struct utf8_data *); *************** *** 917,924 **** struct grid *gd = s->grid; struct tty_ctx ttyctx; u_int width, xx, last; ! struct grid_cell tmp_gc; ! int insert; /* Ignore padding. */ if (gc->flags & GRID_FLAG_PADDING) --- 918,925 ---- struct grid *gd = s->grid; struct tty_ctx ttyctx; u_int width, xx, last; ! struct grid_cell tmp_gc, now_gc; ! int insert, skip, selected; /* Ignore padding. */ if (gc->flags & GRID_FLAG_PADDING) *************** *** 947,955 **** return; } ! /* Initialise the redraw context, saving the last cell. */ screen_write_initctx(ctx, &ttyctx); - screen_write_save_last(ctx, &ttyctx); /* If in insert mode, make space for the cells. */ if ((s->mode & MODE_INSERT) && s->cx <= screen_size_x(s) - width) { --- 948,955 ---- return; } ! /* Initialise the redraw context. */ screen_write_initctx(ctx, &ttyctx); /* If in insert mode, make space for the cells. */ if ((s->mode & MODE_INSERT) && s->cx <= screen_size_x(s) - width) { *************** *** 958,968 **** --- 958,970 ---- insert = 1; } else insert = 0; + skip = !insert; /* Check this will fit on the current line and wrap if not. */ if ((s->mode & MODE_WRAP) && s->cx > screen_size_x(s) - width) { screen_write_linefeed(ctx, 1); s->cx = 0; /* carriage return */ + skip = 0; } /* Sanity check cursor position. */ *************** *** 970,986 **** return; /* Handle overwriting of UTF-8 characters. */ ! screen_write_overwrite(ctx, width); /* * If the new character is UTF-8 wide, fill in padding cells. Have * already ensured there is enough room. */ ! for (xx = s->cx + 1; xx < s->cx + width; xx++) grid_view_set_cell(gd, xx, s->cy, &screen_write_pad_cell); /* Set the cell. */ ! grid_view_set_cell(gd, s->cx, s->cy, gc); /* * Move the cursor. If not wrapping, stick at the last character and --- 972,997 ---- return; /* Handle overwriting of UTF-8 characters. */ ! grid_view_get_cell(gd, s->cx, s->cy, &now_gc); ! if (screen_write_overwrite(ctx, &now_gc, width)) ! skip = 0; /* * If the new character is UTF-8 wide, fill in padding cells. Have * already ensured there is enough room. */ ! for (xx = s->cx + 1; xx < s->cx + width; xx++) { grid_view_set_cell(gd, xx, s->cy, &screen_write_pad_cell); + skip = 0; + } + /* If no change, do not draw. */ + if (skip) + skip = (memcmp(&now_gc, gc, sizeof now_gc) == 0); + /* Set the cell. */ ! if (!skip) ! grid_view_set_cell(gd, s->cx, s->cy, gc); /* * Move the cursor. If not wrapping, stick at the last character and *************** *** 992,1003 **** else s->cx = screen_size_x(s) - last; ! /* Draw to the screen if necessary. */ if (insert) { ttyctx.num = width; tty_write(tty_cmd_insertcharacter, &ttyctx); } ! if (screen_check_selection(s, s->cx - width, s->cy)) { memcpy(&tmp_gc, &s->sel.cell, sizeof tmp_gc); utf8_copy(&tmp_gc.data, &gc->data); tmp_gc.attr = tmp_gc.attr & ~GRID_ATTR_CHARSET; --- 1003,1025 ---- else s->cx = screen_size_x(s) - last; ! /* Create space for character in insert mode. */ if (insert) { ttyctx.num = width; tty_write(tty_cmd_insertcharacter, &ttyctx); } ! ! /* Check if this is selected. */ ! selected = screen_check_selection(s, s->cx - width, s->cy); ! if (selected) ! skip = 0; ! ! /* Save last cell if it will be needed. */ ! if (!skip && ctx->wp != NULL && ttyctx.ocx > ctx->wp->sx - width) ! screen_write_save_last(ctx, &ttyctx); ! ! /* Write to the screen. */ ! if (selected) { memcpy(&tmp_gc, &s->sel.cell, sizeof tmp_gc); utf8_copy(&tmp_gc.data, &gc->data); tmp_gc.attr = tmp_gc.attr & ~GRID_ATTR_CHARSET; *************** *** 1009,1015 **** (GRID_FLAG_FG256|GRID_FLAG_BG256); ttyctx.cell = &tmp_gc; tty_write(tty_cmd_cell, &ttyctx); ! } else { ttyctx.cell = gc; tty_write(tty_cmd_cell, &ttyctx); } --- 1031,1037 ---- (GRID_FLAG_FG256|GRID_FLAG_BG256); ttyctx.cell = &tmp_gc; tty_write(tty_cmd_cell, &ttyctx); ! } else if (!skip) { ttyctx.cell = gc; tty_write(tty_cmd_cell, &ttyctx); } *************** *** 1057,1072 **** * character, it is necessary to also overwrite any other cells which covered * by the same character. */ ! static void ! screen_write_overwrite(struct screen_write_ctx *ctx, u_int width) { struct screen *s = ctx->s; struct grid *gd = s->grid; ! struct grid_cell gc; u_int xx; ! grid_view_get_cell(gd, s->cx, s->cy, &gc); ! if (gc.flags & GRID_FLAG_PADDING) { /* * A padding cell, so clear any following and leading padding * cells back to the character. Don't overwrite the current --- 1079,1095 ---- * character, it is necessary to also overwrite any other cells which covered * by the same character. */ ! static int ! screen_write_overwrite(struct screen_write_ctx *ctx, struct grid_cell *gc, ! u_int width) { struct screen *s = ctx->s; struct grid *gd = s->grid; ! struct grid_cell tmp_gc; u_int xx; + int done = 0; ! if (gc->flags & GRID_FLAG_PADDING) { /* * A padding cell, so clear any following and leading padding * cells back to the character. Don't overwrite the current *************** *** 1074,1100 **** */ xx = s->cx + 1; while (--xx > 0) { ! grid_view_get_cell(gd, xx, s->cy, &gc); ! if (~gc.flags & GRID_FLAG_PADDING) break; grid_view_set_cell(gd, xx, s->cy, &grid_default_cell); } /* Overwrite the character at the start of this padding. */ grid_view_set_cell(gd, xx, s->cy, &grid_default_cell); } /* * Overwrite any padding cells that belong to a UTF-8 character * we'll be overwriting with the current character. */ ! xx = s->cx + width - 1; ! while (++xx < screen_size_x(s)) { ! grid_view_get_cell(gd, xx, s->cy, &gc); ! if (~gc.flags & GRID_FLAG_PADDING) ! break; ! grid_view_set_cell(gd, xx, s->cy, &grid_default_cell); } } void --- 1097,1129 ---- */ xx = s->cx + 1; while (--xx > 0) { ! grid_view_get_cell(gd, xx, s->cy, &tmp_gc); ! if (~tmp_gc.flags & GRID_FLAG_PADDING) break; grid_view_set_cell(gd, xx, s->cy, &grid_default_cell); } /* Overwrite the character at the start of this padding. */ grid_view_set_cell(gd, xx, s->cy, &grid_default_cell); + done = 1; } /* * Overwrite any padding cells that belong to a UTF-8 character * we'll be overwriting with the current character. */ ! if (gc->data.width != 1 || gc->flags & GRID_FLAG_PADDING) { ! xx = s->cx + width - 1; ! while (++xx < screen_size_x(s)) { ! grid_view_get_cell(gd, xx, s->cy, &tmp_gc); ! if (~tmp_gc.flags & GRID_FLAG_PADDING) ! break; ! grid_view_set_cell(gd, xx, s->cy, &grid_default_cell); ! done = 1; ! } } + + return (done); } void