=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/screen-write.c,v retrieving revision 1.171 retrieving revision 1.172 diff -c -r1.171 -r1.172 *** src/usr.bin/tmux/screen-write.c 2020/04/18 15:22:05 1.171 --- src/usr.bin/tmux/screen-write.c 2020/04/18 17:20:25 1.172 *************** *** 1,4 **** ! /* $OpenBSD: screen-write.c,v 1.171 2020/04/18 15:22:05 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: screen-write.c,v 1.172 2020/04/18 17:20:25 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 162,168 **** if (ctx->s->write_list == NULL) screen_write_make_list(ctx->s); - ctx->list = ctx->s->write_list; ctx->item = xcalloc(1, sizeof *ctx->item); ctx->scrolled = 0; --- 162,167 ---- *************** *** 965,971 **** grid_view_clear(s->grid, 0, s->cy, sx, 1, bg); screen_write_collect_clear(ctx, s->cy, 1); ! ctx->list[s->cy].bg = 1 + bg; ctx->item->used = 0; } --- 964,970 ---- grid_view_clear(s->grid, 0, s->cy, sx, 1, bg); screen_write_collect_clear(ctx, s->cy, 1); ! ctx->s->write_list[s->cy].bg = 1 + bg; ctx->item->used = 0; } *************** *** 993,999 **** ci->x = s->cx; ci->type = CLEAR_END; ci->bg = bg; ! TAILQ_INSERT_TAIL(&ctx->list[s->cy].items, ci, entry); ctx->item = xcalloc(1, sizeof *ctx->item); } } --- 992,998 ---- ci->x = s->cx; ci->type = CLEAR_END; ci->bg = bg; ! TAILQ_INSERT_TAIL(&ctx->s->write_list[s->cy].items, ci, entry); ctx->item = xcalloc(1, sizeof *ctx->item); } } *************** *** 1020,1026 **** ci->x = s->cx; ci->type = CLEAR_START; ci->bg = bg; ! TAILQ_INSERT_TAIL(&ctx->list[s->cy].items, ci, entry); ctx->item = xcalloc(1, sizeof *ctx->item); } } --- 1019,1025 ---- ci->x = s->cx; ci->type = CLEAR_START; ci->bg = bg; ! TAILQ_INSERT_TAIL(&ctx->s->write_list[s->cy].items, ci, entry); ctx->item = xcalloc(1, sizeof *ctx->item); } } *************** *** 1264,1272 **** u_int items = 0; int redundant = 0; ! if (TAILQ_EMPTY(&ctx->list[y].items)) return (0); ! TAILQ_FOREACH_SAFE(ci, &ctx->list[y].items, entry, tmp) { switch (ci->type) { case CLEAR_START: if (ci->x >= x) { --- 1263,1271 ---- u_int items = 0; int redundant = 0; ! if (TAILQ_EMPTY(&ctx->s->write_list[y].items)) return (0); ! TAILQ_FOREACH_SAFE(ci, &ctx->s->write_list[y].items, entry, tmp) { switch (ci->type) { case CLEAR_START: if (ci->x >= x) { *************** *** 1286,1292 **** } items++; size += ci->used; ! TAILQ_REMOVE(&ctx->list[y].items, ci, entry); free(ci); } ctx->skipped += size; --- 1285,1291 ---- } items++; size += ci->used; ! TAILQ_REMOVE(&ctx->s->write_list[y].items, ci, entry); free(ci); } ctx->skipped += size; *************** *** 1305,1313 **** int redundant = 0; u_int items = 0; ! if (TAILQ_EMPTY(&ctx->list[y].items)) return (0); ! TAILQ_FOREACH_SAFE(ci, &ctx->list[y].items, entry, tmp) { switch (ci->type) { case CLEAR_START: if (ci->x >= x) --- 1304,1312 ---- int redundant = 0; u_int items = 0; ! if (TAILQ_EMPTY(&ctx->s->write_list[y].items)) return (0); ! TAILQ_FOREACH_SAFE(ci, &ctx->s->write_list[y].items, entry, tmp) { switch (ci->type) { case CLEAR_START: if (ci->x >= x) *************** *** 1327,1333 **** } items++; size += ci->used; ! TAILQ_REMOVE(&ctx->list[y].items, ci, entry); free(ci); } ctx->skipped += size; --- 1326,1332 ---- } items++; size += ci->used; ! TAILQ_REMOVE(&ctx->s->write_list[y].items, ci, entry); free(ci); } ctx->skipped += size; *************** *** 1341,1358 **** screen_write_collect_clear(struct screen_write_ctx *ctx, u_int y, u_int n) { struct screen_write_collect_item *ci, *tmp; u_int i, items; size_t size; for (i = y; i < y + n; i++) { ! if (TAILQ_EMPTY(&ctx->list[i].items)) continue; items = 0; size = 0; ! TAILQ_FOREACH_SAFE(ci, &ctx->list[i].items, entry, tmp) { items++; size += ci->used; ! TAILQ_REMOVE(&ctx->list[i].items, ci, entry); free(ci); } ctx->skipped += size; --- 1340,1359 ---- screen_write_collect_clear(struct screen_write_ctx *ctx, u_int y, u_int n) { struct screen_write_collect_item *ci, *tmp; + struct screen_write_collect_line *cl; u_int i, items; size_t size; for (i = y; i < y + n; i++) { ! if (TAILQ_EMPTY(&ctx->s->write_list[i].items)) continue; items = 0; size = 0; ! cl = &ctx->s->write_list[i]; ! TAILQ_FOREACH_SAFE(ci, &cl->items, entry, tmp) { items++; size += ci->used; ! TAILQ_REMOVE(&cl->items, ci, entry); free(ci); } ctx->skipped += size; *************** *** 1374,1387 **** s->rupper, s->rlower); screen_write_collect_clear(ctx, s->rupper, 1); ! saved = ctx->list[s->rupper].data; for (y = s->rupper; y < s->rlower; y++) { ! cl = &ctx->list[y + 1]; ! TAILQ_CONCAT(&ctx->list[y].items, &cl->items, entry); ! ctx->list[y].data = cl->data; } ! ctx->list[s->rlower].data = saved; ! ctx->list[s->rlower].bg = 1 + 8; } /* Flush collected lines. */ --- 1375,1388 ---- s->rupper, s->rlower); screen_write_collect_clear(ctx, s->rupper, 1); ! saved = ctx->s->write_list[s->rupper].data; for (y = s->rupper; y < s->rlower; y++) { ! cl = &ctx->s->write_list[y + 1]; ! TAILQ_CONCAT(&ctx->s->write_list[y].items, &cl->items, entry); ! ctx->s->write_list[y].data = cl->data; } ! ctx->s->write_list[s->rlower].data = saved; ! ctx->s->write_list[s->rlower].bg = 1 + 8; } /* Flush collected lines. */ *************** *** 1391,1396 **** --- 1392,1398 ---- { struct screen *s = ctx->s; struct screen_write_collect_item *ci, *tmp; + struct screen_write_collect_line *cl; u_int y, cx, cy, items = 0; struct tty_ctx ttyctx; size_t written = 0; *************** *** 1414,1426 **** cx = s->cx; cy = s->cy; for (y = 0; y < screen_size_y(s); y++) { ! if (ctx->list[y].bg != 0) { screen_write_set_cursor(ctx, 0, y); screen_write_initctx(ctx, &ttyctx, 1); ! ttyctx.bg = ctx->list[y].bg - 1; tty_write(tty_cmd_clearline, &ttyctx); } ! TAILQ_FOREACH_SAFE(ci, &ctx->list[y].items, entry, tmp) { screen_write_set_cursor(ctx, ci->x, y); if (ci->type == CLEAR_END) { screen_write_initctx(ctx, &ttyctx, 1); --- 1416,1429 ---- cx = s->cx; cy = s->cy; for (y = 0; y < screen_size_y(s); y++) { ! cl = &ctx->s->write_list[y]; ! if (cl->bg != 0) { screen_write_set_cursor(ctx, 0, y); screen_write_initctx(ctx, &ttyctx, 1); ! ttyctx.bg = cl->bg - 1; tty_write(tty_cmd_clearline, &ttyctx); } ! TAILQ_FOREACH_SAFE(ci, &cl->items, entry, tmp) { screen_write_set_cursor(ctx, ci->x, y); if (ci->type == CLEAR_END) { screen_write_initctx(ctx, &ttyctx, 1); *************** *** 1434,1440 **** screen_write_initctx(ctx, &ttyctx, 0); ttyctx.cell = &ci->gc; ttyctx.wrapped = ci->wrapped; ! ttyctx.ptr = ctx->list[y].data + ci->x; ttyctx.num = ci->used; tty_write(tty_cmd_cells, &ttyctx); } --- 1437,1443 ---- screen_write_initctx(ctx, &ttyctx, 0); ttyctx.cell = &ci->gc; ttyctx.wrapped = ci->wrapped; ! ttyctx.ptr = cl->data + ci->x; ttyctx.num = ci->used; tty_write(tty_cmd_cells, &ttyctx); } *************** *** 1442,1451 **** items++; written += ci->used; ! TAILQ_REMOVE(&ctx->list[y].items, ci, entry); free(ci); } ! ctx->list[y].bg = 0; } s->cx = cx; s->cy = cy; --- 1445,1454 ---- items++; written += ci->used; ! TAILQ_REMOVE(&cl->items, ci, entry); free(ci); } ! cl->bg = 0; } s->cx = cx; s->cy = cy; *************** *** 1460,1465 **** --- 1463,1469 ---- { struct screen *s = ctx->s; struct screen_write_collect_item *ci = ctx->item; + struct screen_write_collect_line *cl = &s->write_list[s->cy]; struct grid_cell gc; u_int xx; *************** *** 1467,1477 **** return; ci->x = s->cx; ! TAILQ_INSERT_TAIL(&ctx->list[s->cy].items, ci, entry); ctx->item = xcalloc(1, sizeof *ctx->item); log_debug("%s: %u %.*s (at %u,%u)", __func__, ci->used, ! (int)ci->used, ctx->list[s->cy].data + ci->x, s->cx, s->cy); if (s->cx != 0) { for (xx = s->cx; xx > 0; xx--) { --- 1471,1481 ---- return; ci->x = s->cx; ! TAILQ_INSERT_TAIL(&cl->items, ci, entry); ctx->item = xcalloc(1, sizeof *ctx->item); log_debug("%s: %u %.*s (at %u,%u)", __func__, ci->used, ! (int)ci->used, cl->data + ci->x, s->cx, s->cy); if (s->cx != 0) { for (xx = s->cx; xx > 0; xx--) { *************** *** 1487,1494 **** } } ! grid_view_set_cells(s->grid, s->cx, s->cy, &ci->gc, ! ctx->list[s->cy].data + ci->x, ci->used); screen_write_set_cursor(ctx, s->cx + ci->used, -1); for (xx = s->cx; xx < screen_size_x(s); xx++) { --- 1491,1498 ---- } } ! grid_view_set_cells(s->grid, s->cx, s->cy, &ci->gc, cl->data + ci->x, ! ci->used); screen_write_set_cursor(ctx, s->cx + ci->used, -1); for (xx = s->cx; xx < screen_size_x(s); xx++) { *************** *** 1547,1555 **** if (ci->used == 0) memcpy(&ci->gc, gc, sizeof ci->gc); ! if (ctx->list[s->cy].data == NULL) ! ctx->list[s->cy].data = xmalloc(screen_size_x(ctx->s)); ! ctx->list[s->cy].data[s->cx + ci->used++] = gc->data.data[0]; } /* Write cell data. */ --- 1551,1559 ---- if (ci->used == 0) memcpy(&ci->gc, gc, sizeof ci->gc); ! if (ctx->s->write_list[s->cy].data == NULL) ! ctx->s->write_list[s->cy].data = xmalloc(screen_size_x(ctx->s)); ! ctx->s->write_list[s->cy].data[s->cx + ci->used++] = gc->data.data[0]; } /* Write cell data. */