Module Name:    src
Committed By:   blymn
Date:           Wed Oct 19 06:09:27 UTC 2022

Modified Files:
        src/lib/libcurses: add_wchstr.c addbytes.c background.c chgat.c
            clrtobot.c color.c cr_put.c curses.c delch.c erase.c ins_wch.c
            ins_wstr.c insch.c insdelln.c insstr.c refresh.c resize.c

Log Message:
Fixes for lib/56926 amongst other things:
 - plod now correctly accounts for wide characters when plodding
 - use erase line when in color mode if the terminal has the capability
 - ensure that the CA_CONTINUATION flag is applied consistently to the
   subsequent characters in a wide character.
 - fix a bunch of refresh bugs that caused inconsistent placement of
   wide characters.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libcurses/add_wchstr.c
cvs rdiff -u -r1.64 -r1.65 src/lib/libcurses/addbytes.c
cvs rdiff -u -r1.32 -r1.33 src/lib/libcurses/background.c
cvs rdiff -u -r1.8 -r1.9 src/lib/libcurses/chgat.c
cvs rdiff -u -r1.30 -r1.31 src/lib/libcurses/clrtobot.c \
    src/lib/libcurses/curses.c
cvs rdiff -u -r1.46 -r1.47 src/lib/libcurses/color.c
cvs rdiff -u -r1.39 -r1.40 src/lib/libcurses/cr_put.c
cvs rdiff -u -r1.29 -r1.30 src/lib/libcurses/delch.c
cvs rdiff -u -r1.36 -r1.37 src/lib/libcurses/erase.c
cvs rdiff -u -r1.19 -r1.20 src/lib/libcurses/ins_wch.c
cvs rdiff -u -r1.23 -r1.24 src/lib/libcurses/ins_wstr.c
cvs rdiff -u -r1.27 -r1.28 src/lib/libcurses/insch.c
cvs rdiff -u -r1.22 -r1.23 src/lib/libcurses/insdelln.c
cvs rdiff -u -r1.10 -r1.11 src/lib/libcurses/insstr.c
cvs rdiff -u -r1.123 -r1.124 src/lib/libcurses/refresh.c
cvs rdiff -u -r1.35 -r1.36 src/lib/libcurses/resize.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libcurses/add_wchstr.c
diff -u src/lib/libcurses/add_wchstr.c:1.13 src/lib/libcurses/add_wchstr.c:1.14
--- src/lib/libcurses/add_wchstr.c:1.13	Tue May  3 07:25:34 2022
+++ src/lib/libcurses/add_wchstr.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*   $NetBSD: add_wchstr.c,v 1.13 2022/05/03 07:25:34 blymn Exp $ */
+/*   $NetBSD: add_wchstr.c,v 1.14 2022/10/19 06:09:27 blymn Exp $ */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation Inc.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: add_wchstr.c,v 1.13 2022/05/03 07:25:34 blymn Exp $");
+__RCSID("$NetBSD: add_wchstr.c,v 1.14 2022/10/19 06:09:27 blymn Exp $");
 #endif				/* not lint */
 
 #include <stdlib.h>
@@ -174,7 +174,8 @@ wadd_wchnstr(WINDOW *win, const cchar_t 
 				if (_cursesi_copy_nsp(win->bnsp, tp) == ERR)
 					return ERR;
 				tp->attr = win->battr;
-				(*tp).wcols = 1;
+				tp->wcols = 1;
+				tp->cflags = CA_BACKGROUND;
 				np = tp->nsp;
 			}
 		} else {
@@ -186,7 +187,7 @@ wadd_wchnstr(WINDOW *win, const cchar_t 
 	}
 	lnp->flags |= __ISDIRTY;
 	newx = sx + win->ch_off;
-	if (newx < *lnp->firstchp)
+	if (newx < *lnp->firstchp) 
 		*lnp->firstchp = newx;
 
 	/* add characters in the string */
@@ -210,7 +211,7 @@ wadd_wchnstr(WINDOW *win, const cchar_t 
 					    == ERR)
 						return ERR;
 					lp->attr = win->battr;
-					lp->cflags |= CA_BACKGROUND;
+					lp->cflags = CA_BACKGROUND;
 					(*lp).wcols = 1;
 					lp++, ex++;
 				}
@@ -259,6 +260,8 @@ wadd_wchnstr(WINDOW *win, const cchar_t 
 				}
 				lp->ch = chp->vals[0];
 				lp->attr = chp->attributes & WA_ATTRIBUTES;
+				lp->cflags &= ~CA_BACKGROUND;
+				lp->cflags |= CA_CONTINUATION;
 				(*lp).wcols = x - ex;
 				lp++, ex++;
 			}

Index: src/lib/libcurses/addbytes.c
diff -u src/lib/libcurses/addbytes.c:1.64 src/lib/libcurses/addbytes.c:1.65
--- src/lib/libcurses/addbytes.c:1.64	Thu May 19 07:41:26 2022
+++ src/lib/libcurses/addbytes.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: addbytes.c,v 1.64 2022/05/19 07:41:26 blymn Exp $	*/
+/*	$NetBSD: addbytes.c,v 1.65 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)addbytes.c	8.4 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: addbytes.c,v 1.64 2022/05/19 07:41:26 blymn Exp $");
+__RCSID("$NetBSD: addbytes.c,v 1.65 2022/10/19 06:09:27 blymn Exp $");
 #endif
 #endif				/* not lint */
 
@@ -293,6 +293,7 @@ _cursesi_addbyte(WINDOW *win, __LINE **l
 	 */
 	if (newx < *(*lp)->firstchp)
 		*(*lp)->firstchp = newx;
+
 	if (newx > *(*lp)->lastchp)
 		*(*lp)->lastchp = newx;
 	__CTRACE(__CTRACE_INPUT, "ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
@@ -311,7 +312,7 @@ _cursesi_addbyte(WINDOW *win, __LINE **l
 #endif
 	}
 
-	(*lp)->line[*x].cflags &= ~ CA_BACKGROUND;
+	(*lp)->line[*x].cflags &= ~ (CA_BACKGROUND | CA_CONTINUATION);
 
 	if (attributes & __COLOR)
 		(*lp)->line[*x].attr =
@@ -421,6 +422,7 @@ _cursesi_addwchar(WINDOW *win, __LINE **
 		newx = *x + win->ch_off;
 		if (newx < *(*lnp)->firstchp)
 			*(*lnp)->firstchp = newx;
+
 		if (newx > *(*lnp)->lastchp)
 			*(*lnp)->lastchp = newx;
 		__touchline(win, *y, *x, *x);
@@ -451,7 +453,7 @@ _cursesi_addwchar(WINDOW *win, __LINE **
 			    *y, sx);
 			tp = &win->alines[*y]->line[sx];
 			tp->ch = win->bch;
-			tp->cflags |= CA_BACKGROUND;
+			tp->cflags = CA_BACKGROUND;
 			if (_cursesi_copy_nsp(win->bnsp, tp) == ERR)
 				return ERR;
 
@@ -483,12 +485,14 @@ _cursesi_addwchar(WINDOW *win, __LINE **
 		newx = *x + win->ch_off;
 		if (newx < *(*lnp)->firstchp)
 			*(*lnp)->firstchp = newx;
+
 		for (tp = lp; *x < win->maxx; tp++, (*x)++) {
 			tp->ch = win->bch;
 			if (_cursesi_copy_nsp(win->bnsp, tp) == ERR)
 				return ERR;
 			tp->attr = win->battr;
 			tp->wcols = win->wcols;
+			tp->cflags = CA_BACKGROUND;
 		}
 		newx = win->maxx - 1 + win->ch_off;
 		if (newx > *(*lnp)->lastchp)
@@ -510,13 +514,14 @@ _cursesi_addwchar(WINDOW *win, __LINE **
 	newx = *x + win->ch_off;
 	if (newx < *(*lnp)->firstchp)
 		*(*lnp)->firstchp = newx;
+
 	if (lp->nsp) {
 		__cursesi_free_nsp(lp->nsp);
 		lp->nsp = NULL;
 	}
 
 	lp->ch = wch->vals[0];
-	lp->cflags &= ~CA_BACKGROUND;
+	lp->cflags &= ~ (CA_BACKGROUND | CA_CONTINUATION);
 
 	attributes = (win->wattr | wch->attributes)
 		& (WA_ATTRIBUTES & ~__COLOR);
@@ -555,7 +560,9 @@ _cursesi_addwchar(WINDOW *win, __LINE **
 	    sx + 1, sx + cw - 1);
 	__CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: *x = %d, win->maxx = %d\n",
 	    *x, win->maxx);
-	for (tp = lp + 1, *x = sx + 1; *x - sx <= cw - 1; tp++, (*x)++) {
+	for (tp = lp + 1, *x = sx + 1, i = cw - 1; i > 0; tp++, (*x)++, i--) {
+		__CTRACE(__CTRACE_INPUT,
+		    "_cursesi_addwchar: setting continuation at x %d\n", *x);
 		if (tp->nsp) {
 			__cursesi_free_nsp(tp->nsp);
 			tp->nsp = NULL;
@@ -564,9 +571,10 @@ _cursesi_addwchar(WINDOW *win, __LINE **
 		tp->attr = lp->attr & WA_ATTRIBUTES;
 		/* Mark as "continuation" cell */
 		tp->cflags |= CA_CONTINUATION;
+		tp->cflags &= ~ CA_BACKGROUND;
+		tp->wcols = i;
 	}
 
-
 	if (*x >= win->maxx) {
 		__CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: do line wrap\n");
 		if (*y == win->scr_b) {
@@ -590,7 +598,6 @@ _cursesi_addwchar(WINDOW *win, __LINE **
 		(*lnp) = win->alines[*y];
 		*(*lnp)->lastchp = win->ch_off + win->maxx - 1;
 	} else {
-
 		/* clear the remaining of the current character */
 		if (*x && *x < win->maxx) {
 			ex = sx + cw;
@@ -601,7 +608,7 @@ _cursesi_addwchar(WINDOW *win, __LINE **
 				    "remaining of current char (%d,%d)nn",
 				    *y, ex);
 				tp->ch = win->bch;
-				tp->cflags |= CA_BACKGROUND;
+				tp->cflags = CA_BACKGROUND;
 				if (_cursesi_copy_nsp(win->bnsp, tp) == ERR)
 					return ERR;
 				tp->attr = win->battr;

Index: src/lib/libcurses/background.c
diff -u src/lib/libcurses/background.c:1.32 src/lib/libcurses/background.c:1.33
--- src/lib/libcurses/background.c:1.32	Thu May  5 22:02:17 2022
+++ src/lib/libcurses/background.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: background.c,v 1.32 2022/05/05 22:02:17 blymn Exp $	*/
+/*	$NetBSD: background.c,v 1.33 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: background.c,v 1.32 2022/05/05 22:02:17 blymn Exp $");
+__RCSID("$NetBSD: background.c,v 1.33 2022/10/19 06:09:27 blymn Exp $");
 #endif				/* not lint */
 
 #include <stdlib.h>
@@ -172,7 +172,7 @@ wbkgrndset(WINDOW *win, const cchar_t *w
 	/* get a copy of the old background, we will need it. */
 	obkgrnd.ch = win->bch;
 	obkgrnd.attr = win->battr;
-	obkgrnd.cflags |= CA_BACKGROUND;
+	obkgrnd.cflags = CA_BACKGROUND;
 	obkgrnd.wcols = win->wcols;
 	obkgrnd.nsp = NULL;
 	_cursesi_copy_nsp(win->bnsp, &obkgrnd);
@@ -223,7 +223,7 @@ wbkgrndset(WINDOW *win, const cchar_t *w
 
 	nbkgrnd.ch = win->bch;
 	nbkgrnd.attr = win->battr;
-	nbkgrnd.cflags |= CA_BACKGROUND;
+	nbkgrnd.cflags = CA_BACKGROUND;
 	nbkgrnd.wcols = win->wcols;
 	nbkgrnd.nsp = NULL;
 	_cursesi_copy_nsp(win->bnsp, &nbkgrnd);

Index: src/lib/libcurses/chgat.c
diff -u src/lib/libcurses/chgat.c:1.8 src/lib/libcurses/chgat.c:1.9
--- src/lib/libcurses/chgat.c:1.8	Mon Nov 22 21:25:25 2021
+++ src/lib/libcurses/chgat.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: chgat.c,v 1.8 2021/11/22 21:25:25 blymn Exp $	*/
+/*	$NetBSD: chgat.c,v 1.9 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: chgat.c,v 1.8 2021/11/22 21:25:25 blymn Exp $");
+__RCSID("$NetBSD: chgat.c,v 1.9 2022/10/19 06:09:27 blymn Exp $");
 
 #include "curses.h"
 #include "curses_private.h"
@@ -79,6 +79,7 @@ mvwchgat(WINDOW *win , int y, int x, int
 
 	if (x + win->ch_off < *lp->firstchp)
 		*lp->firstchp = x + win->ch_off;
+
 	if (x + win->ch_off + count > *lp->lastchp)
 		*lp->lastchp = x + win->ch_off + count;
 

Index: src/lib/libcurses/clrtobot.c
diff -u src/lib/libcurses/clrtobot.c:1.30 src/lib/libcurses/clrtobot.c:1.31
--- src/lib/libcurses/clrtobot.c:1.30	Tue May  3 07:25:34 2022
+++ src/lib/libcurses/clrtobot.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: clrtobot.c,v 1.30 2022/05/03 07:25:34 blymn Exp $	*/
+/*	$NetBSD: clrtobot.c,v 1.31 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)clrtobot.c	8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: clrtobot.c,v 1.30 2022/05/03 07:25:34 blymn Exp $");
+__RCSID("$NetBSD: clrtobot.c,v 1.31 2022/10/19 06:09:27 blymn Exp $");
 #endif
 #endif				/* not lint */
 
@@ -98,6 +98,7 @@ wclrtobot(WINDOW *win)
 
 			sp->ch = bch;
 			sp->cflags |= CA_BACKGROUND;
+			sp->cflags &= CA_CONTINUATION;
 			sp->attr = battr | (sp->attr & __ALTCHARSET);
 #ifdef HAVE_WCHAR
 			if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
Index: src/lib/libcurses/curses.c
diff -u src/lib/libcurses/curses.c:1.30 src/lib/libcurses/curses.c:1.31
--- src/lib/libcurses/curses.c:1.30	Tue May  3 07:25:34 2022
+++ src/lib/libcurses/curses.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: curses.c,v 1.30 2022/05/03 07:25:34 blymn Exp $	*/
+/*	$NetBSD: curses.c,v 1.31 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -35,7 +35,7 @@
 #if 0
 static char sccsid[] = "@(#)curses.c	8.3 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: curses.c,v 1.30 2022/05/03 07:25:34 blymn Exp $");
+__RCSID("$NetBSD: curses.c,v 1.31 2022/10/19 06:09:27 blymn Exp $");
 #endif
 #endif				/* not lint */
 
@@ -92,6 +92,9 @@ _cursesi_celleq(__LDATA *x, __LDATA *y)
 	if (!ret)
 		return 0;
 
+	if ((x->cflags & CA_CONTINUATION) != (y->cflags & CA_CONTINUATION))
+		return 0;
+
 	if (!xnp && !ynp)
 		return 1;
 

Index: src/lib/libcurses/color.c
diff -u src/lib/libcurses/color.c:1.46 src/lib/libcurses/color.c:1.47
--- src/lib/libcurses/color.c:1.46	Tue Apr 12 07:03:04 2022
+++ src/lib/libcurses/color.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: color.c,v 1.46 2022/04/12 07:03:04 blymn Exp $	*/
+/*	$NetBSD: color.c,v 1.47 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: color.c,v 1.46 2022/04/12 07:03:04 blymn Exp $");
+__RCSID("$NetBSD: color.c,v 1.47 2022/10/19 06:09:27 blymn Exp $");
 #endif				/* not lint */
 
 #include "curses.h"
@@ -678,6 +678,7 @@ __change_pair(short pair)
 						 */
 						if (*lp->firstchp > x)
 							*lp->firstchp = x;
+
 						if (*lp->lastchp < x)
 							*lp->lastchp = x;
 					}

Index: src/lib/libcurses/cr_put.c
diff -u src/lib/libcurses/cr_put.c:1.39 src/lib/libcurses/cr_put.c:1.40
--- src/lib/libcurses/cr_put.c:1.39	Sun Apr 10 09:50:44 2022
+++ src/lib/libcurses/cr_put.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: cr_put.c,v 1.39 2022/04/10 09:50:44 andvar Exp $	*/
+/*	$NetBSD: cr_put.c,v 1.40 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -36,7 +36,7 @@
 #if 0
 static char sccsid[] = "@(#)cr_put.c	8.3 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: cr_put.c,v 1.39 2022/04/10 09:50:44 andvar Exp $");
+__RCSID("$NetBSD: cr_put.c,v 1.40 2022/10/19 06:09:27 blymn Exp $");
 #endif
 #endif				/* not lint */
 
@@ -221,6 +221,7 @@ static int
 plod(int cnt, int in_refresh)
 {
 	int	 i, j, k, soutcol, soutline;
+	__LDATA  *csp;
 
 	__CTRACE(__CTRACE_OUTPUT, "plod: cnt=%d, in_refresh=%d\n",
 	    cnt, in_refresh);
@@ -423,16 +424,23 @@ dontcr:while (outline < destline) {
 	 * If destcol is halfway through a multicolumn
 	 * wide char, we have no chance of plodding.
 	 */
-	k = outcol - destcol;
-	if (k < 0)
-		k = -k;
-	if ((k != 0) && (curscr->alines[outline]->line[outcol].wcols > k)) {
+	if (curscr->alines[outline]->line[outcol].cflags & CA_CONTINUATION) {
 		plodcnt = -1;
 		goto out;
 	}
 #endif /* HAVE_WCHAR */
 
 	while (outcol < destcol) {
+		int chw;
+
+		csp = &curscr->alines[outline]->line[outcol];
+#ifdef HAVE_WCHAR
+		chw = csp->wcols;
+#else
+		chw = 1;
+#endif /* HAVE_WCHAR */
+
+
 		/*
 		 * Move one char to the right.  We don't use nd space because
 		 * it's better to just print the char we are moving over.
@@ -442,44 +450,42 @@ dontcr:while (outline < destline) {
 				plodcnt--;
 			else {
 #ifndef HAVE_WCHAR
-				i = curscr->alines[outline]->line[outcol].ch
-				    & __CHARTEXT;
-				if (curscr->alines[outline]->line[outcol].attr
-				    == curscr->wattr)
+				i = csp->ch & __CHARTEXT;
+				if (csp->attr == curscr->wattr)
 					__cputchar(i);
 #else
-				if ((curscr->alines[outline]->line[outcol].attr
-				    & WA_ATTRIBUTES)
+				if ((csp->attr & WA_ATTRIBUTES)
 				    == curscr->wattr) {
-					switch (curscr->alines[outline]->line[outcol].wcols) {
-					case 1:
-						__cputwchar(curscr->alines[outline]->line[outcol].ch);
-						__cursesi_putnsp(curscr->alines[outline]->line[outcol].nsp,
+					if (csp->cflags & CA_CONTINUATION)
+						goto nondes;
+
+					if (csp->wcols >= 1) {
+						__cputwchar(csp->ch);
+						__cursesi_putnsp(csp->nsp,
 								outline,
 								outcol);
 						__CTRACE(__CTRACE_OUTPUT,
 						    "plod: (%d,%d)wcols(%d), "
 						    "putwchar(%x)\n",
 						    outline, outcol,
-						    curscr->alines[outline]->line[outcol].wcols,
-						    curscr->alines[outline]->line[outcol].ch);
-					/*FALLTHROUGH*/
-					case 0:
-						break;
-					default:
-						goto nondes;
+						    csp->wcols, csp->ch);
 					}
+
+					if (csp->wcols == 0)
+						break;
 				}
 #endif /* HAVE_WCHAR */
 				else
 					goto nondes;
 			}
-		else
-	nondes:	if (cursor_right)
-			tputs(cursor_right, 0, plodput);
-		else
-			plodput(' ');
-		outcol++;
+		else {
+		nondes:	if (cursor_right)
+				tputs(cursor_right, 0, plodput);
+			else
+				plodput(' ');
+		}
+
+		outcol += chw;
 		if (plodcnt < 0)
 			goto out;
 	}

Index: src/lib/libcurses/delch.c
diff -u src/lib/libcurses/delch.c:1.29 src/lib/libcurses/delch.c:1.30
--- src/lib/libcurses/delch.c:1.29	Tue May  3 07:25:34 2022
+++ src/lib/libcurses/delch.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: delch.c,v 1.29 2022/05/03 07:25:34 blymn Exp $	*/
+/*	$NetBSD: delch.c,v 1.30 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)delch.c	8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: delch.c,v 1.29 2022/05/03 07:25:34 blymn Exp $");
+__RCSID("$NetBSD: delch.c,v 1.30 2022/10/19 06:09:27 blymn Exp $");
 #endif
 #endif				/* not lint */
 
@@ -98,7 +98,7 @@ wdelch(WINDOW *win)
 		temp1++, temp2++;
 	}
 	temp1->ch = win->bch;
-	temp1->cflags |= CA_BACKGROUND;
+	temp1->cflags = CA_BACKGROUND;
 	if (__using_color && win != curscr)
 		temp1->attr = win->battr & __COLOR;
 	else
@@ -137,6 +137,7 @@ wdelch(WINDOW *win)
 	while (temp1 <= end) {
 		temp1->ch = win->bch;
 		temp1->cflags |= CA_BACKGROUND;
+		temp1->cflags &= ~CA_CONTINUATION;
 		temp1->attr = win->battr;
 		if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR)
 			return ERR;

Index: src/lib/libcurses/erase.c
diff -u src/lib/libcurses/erase.c:1.36 src/lib/libcurses/erase.c:1.37
--- src/lib/libcurses/erase.c:1.36	Tue May  3 07:25:34 2022
+++ src/lib/libcurses/erase.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: erase.c,v 1.36 2022/05/03 07:25:34 blymn Exp $	*/
+/*	$NetBSD: erase.c,v 1.37 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)erase.c	8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: erase.c,v 1.36 2022/05/03 07:25:34 blymn Exp $");
+__RCSID("$NetBSD: erase.c,v 1.37 2022/10/19 06:09:27 blymn Exp $");
 #endif
 #endif				/* not lint */
 
@@ -86,6 +86,7 @@ werase(WINDOW *win)
 
 			sp->ch = bch;
 			sp->cflags |= CA_BACKGROUND;
+			sp->cflags &= ~CA_CONTINUATION;
 			sp->attr = battr | (sp->attr & __ALTCHARSET);
 #ifdef HAVE_WCHAR
 			if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)

Index: src/lib/libcurses/ins_wch.c
diff -u src/lib/libcurses/ins_wch.c:1.19 src/lib/libcurses/ins_wch.c:1.20
--- src/lib/libcurses/ins_wch.c:1.19	Tue Apr 12 07:03:04 2022
+++ src/lib/libcurses/ins_wch.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*   $NetBSD: ins_wch.c,v 1.19 2022/04/12 07:03:04 blymn Exp $ */
+/*   $NetBSD: ins_wch.c,v 1.20 2022/10/19 06:09:27 blymn Exp $ */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation Inc.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ins_wch.c,v 1.19 2022/04/12 07:03:04 blymn Exp $");
+__RCSID("$NetBSD: ins_wch.c,v 1.20 2022/10/19 06:09:27 blymn Exp $");
 #endif						  /* not lint */
 
 #include <string.h>
@@ -200,6 +200,7 @@ wins_wch(WINDOW *win, const cchar_t *wch
 		temp1->ch = wch->vals[0];
 		temp1->wcols = x - ex;
 		temp1->nsp = NULL;
+		temp1->cflags |= CA_CONTINUATION;
 		ex++, temp1++;
 	}
 

Index: src/lib/libcurses/ins_wstr.c
diff -u src/lib/libcurses/ins_wstr.c:1.23 src/lib/libcurses/ins_wstr.c:1.24
--- src/lib/libcurses/ins_wstr.c:1.23	Tue Apr 12 07:03:04 2022
+++ src/lib/libcurses/ins_wstr.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*   $NetBSD: ins_wstr.c,v 1.23 2022/04/12 07:03:04 blymn Exp $ */
+/*   $NetBSD: ins_wstr.c,v 1.24 2022/10/19 06:09:27 blymn Exp $ */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation Inc.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ins_wstr.c,v 1.23 2022/04/12 07:03:04 blymn Exp $");
+__RCSID("$NetBSD: ins_wstr.c,v 1.24 2022/10/19 06:09:27 blymn Exp $");
 #endif						  /* not lint */
 
 #include <string.h>
@@ -291,6 +291,7 @@ loopdone:
 		newx = sx + win->ch_off;
 		if (newx < *lnp->firstchp)
 			*lnp->firstchp = newx;
+
 #ifdef DEBUG
 		{
 			int i;
@@ -298,9 +299,11 @@ loopdone:
 			__CTRACE(__CTRACE_INPUT, "========before=======\n");
 			for (i = 0; i < win->maxx; i++)
 			__CTRACE(__CTRACE_INPUT,
-				    "wins_nwstr: (%d,%d)=(%x,%x,%p)\n",
+				    "wins_nwstr: (%d,%d)=(%x,%x,%d,%x,%p)\n",
 				    y, i, win->alines[y]->line[i].ch,
 				    win->alines[y]->line[i].attr,
+				    win->alines[y]->line[i].wcols,
+				    win->alines[y]->line[i].cflags,
 				    win->alines[y]->line[i].nsp);
 		}
 #endif /* DEBUG */
@@ -323,6 +326,8 @@ loopdone:
 						return ERR;
 					}
 					temp1->attr = win->battr;
+					temp1->cflags |= CA_BACKGROUND;
+					temp1->cflags &= ~CA_CONTINUATION;
 					temp1->wcols = 1;
 					__CTRACE(__CTRACE_INPUT,
 					    "wins_nwstr: empty cell(%p)\n", temp1);
@@ -340,10 +345,11 @@ loopdone:
 				__CTRACE(__CTRACE_INPUT, "=====after shift====\n");
 				for (i = 0; i < win->maxx; i++)
 					__CTRACE(__CTRACE_INPUT,
-					    "wins_nwstr: (%d,%d)=(%x,%x,%p)\n",
+					    "wins_nwstr: (%d,%d)=(%x,%x,%x,%p)\n",
 					    y, i,
 					    win->alines[y]->line[i].ch,
 					    win->alines[y]->line[i].attr,
+					    win->alines[y]->line[i].cflags,
 					    win->alines[y]->line[i].nsp);
 				__CTRACE(__CTRACE_INPUT, "=====lstr====\n");
 				for (i = 0; i < len; i++)
@@ -372,10 +378,12 @@ loopdone:
 			__CTRACE(__CTRACE_INPUT, "========after=======\n");
 			for (i = 0; i < win->maxx; i++)
 				__CTRACE(__CTRACE_INPUT,
-				    "wins_nwstr: (%d,%d)=(%x,%x,%p)\n",
+				    "wins_nwstr: (%d,%d)=(%x,%x,%d,%x,%p)\n",
 				    y, i,
 				    win->alines[y]->line[i].ch,
 				    win->alines[y]->line[i].attr,
+				    win->alines[y]->line[i].wcols,
+				    win->alines[y]->line[i].cflags,
 				    win->alines[y]->line[i].nsp);
 		}
 #endif /* DEBUG */

Index: src/lib/libcurses/insch.c
diff -u src/lib/libcurses/insch.c:1.27 src/lib/libcurses/insch.c:1.28
--- src/lib/libcurses/insch.c:1.27	Tue Jan 25 03:05:06 2022
+++ src/lib/libcurses/insch.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: insch.c,v 1.27 2022/01/25 03:05:06 blymn Exp $	*/
+/*	$NetBSD: insch.c,v 1.28 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)insch.c	8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: insch.c,v 1.27 2022/01/25 03:05:06 blymn Exp $");
+__RCSID("$NetBSD: insch.c,v 1.28 2022/10/19 06:09:27 blymn Exp $");
 #endif
 #endif				/* not lint */
 
@@ -106,8 +106,14 @@ winsch(WINDOW *win, chtype ch)
 		temp1--, temp2--;
 	}
 	temp1->ch = (wchar_t)ch & __CHARTEXT;
-	if (temp1->ch == ' ')
+	if (temp1->ch == win->bch) {
 		temp1->ch = win->bch;
+		temp1->cflags &= ~CA_CONTINUATION;
+		temp1->cflags |= CA_BACKGROUND;
+	} else {
+		temp1->cflags &= ~ CA_BACKGROUND;
+	}
+
 	temp1->attr = (attr_t) ch & __ATTRIBUTES;
 	if (temp1->attr & __COLOR)
 		temp1->attr |= (win->battr & ~__COLOR);

Index: src/lib/libcurses/insdelln.c
diff -u src/lib/libcurses/insdelln.c:1.22 src/lib/libcurses/insdelln.c:1.23
--- src/lib/libcurses/insdelln.c:1.22	Tue Apr 12 21:54:16 2022
+++ src/lib/libcurses/insdelln.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: insdelln.c,v 1.22 2022/04/12 21:54:16 blymn Exp $	*/
+/*	$NetBSD: insdelln.c,v 1.23 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: insdelln.c,v 1.22 2022/04/12 21:54:16 blymn Exp $");
+__RCSID("$NetBSD: insdelln.c,v 1.23 2022/10/19 06:09:27 blymn Exp $");
 #endif				/* not lint */
 
 /*
@@ -116,7 +116,10 @@ winsdelln(WINDOW *win, int nlines)
 			for (i = 0; i < win->maxx; i++) {
 				win->alines[y]->line[i].ch = win->bch;
 				win->alines[y]->line[i].attr = attr;
-				win->alines[y]->line[i].ch = win->bch;
+				win->alines[y]->line[i].cflags |= 
+				    CA_BACKGROUND;
+				win->alines[y]->line[i].cflags &= 
+				    ~CA_CONTINUATION;
 #ifdef HAVE_WCHAR
 				lp = &win->alines[y]->line[i];
 				if (_cursesi_copy_nsp(win->bnsp, lp) == ERR)
@@ -157,7 +160,10 @@ winsdelln(WINDOW *win, int nlines)
 			for (i = 0; i < win->maxx; i++) {
 				win->alines[y]->line[i].ch = win->bch;
 				win->alines[y]->line[i].attr = attr;
-				win->alines[y]->line[i].ch = win->bch;
+				win->alines[y]->line[i].cflags |= 
+				    CA_BACKGROUND;
+				win->alines[y]->line[i].cflags &= 
+				    ~CA_CONTINUATION;
 #ifdef HAVE_WCHAR
 				lp = &win->alines[y]->line[i];
 				lp->wcols = 1;

Index: src/lib/libcurses/insstr.c
diff -u src/lib/libcurses/insstr.c:1.10 src/lib/libcurses/insstr.c:1.11
--- src/lib/libcurses/insstr.c:1.10	Tue Jan 25 03:05:06 2022
+++ src/lib/libcurses/insstr.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*   $NetBSD: insstr.c,v 1.10 2022/01/25 03:05:06 blymn Exp $ */
+/*   $NetBSD: insstr.c,v 1.11 2022/10/19 06:09:27 blymn Exp $ */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation Inc.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: insstr.c,v 1.10 2022/01/25 03:05:06 blymn Exp $");
+__RCSID("$NetBSD: insstr.c,v 1.11 2022/10/19 06:09:27 blymn Exp $");
 #endif						  /* not lint */
 
 #include <string.h>
@@ -186,6 +186,8 @@ winsnstr(WINDOW *win, const char *str, i
 	{
 		temp1->ch = (wchar_t)*scp & __CHARTEXT;
 		temp1->attr = win->wattr;
+		temp1->cflags &= ~CA_BACKGROUND;
+		temp1->cflags &= ~CA_CONTINUATION;
 #ifdef HAVE_WCHAR
 		temp1->wcols = 1;
 #endif /* HAVE_WCHAR */

Index: src/lib/libcurses/refresh.c
diff -u src/lib/libcurses/refresh.c:1.123 src/lib/libcurses/refresh.c:1.124
--- src/lib/libcurses/refresh.c:1.123	Tue May  3 07:25:34 2022
+++ src/lib/libcurses/refresh.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: refresh.c,v 1.123 2022/05/03 07:25:34 blymn Exp $	*/
+/*	$NetBSD: refresh.c,v 1.124 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)refresh.c	8.7 (Berkeley) 8/13/94";
 #else
-__RCSID("$NetBSD: refresh.c,v 1.123 2022/05/03 07:25:34 blymn Exp $");
+__RCSID("$NetBSD: refresh.c,v 1.124 2022/10/19 06:09:27 blymn Exp $");
 #endif
 #endif				/* not lint */
 
@@ -150,6 +150,10 @@ _wnoutrefresh(WINDOW *win, int begy, int
 	SCREEN *screen = win->screen;
 	short	sy, wy, wx, y_off, x_off, mx, dy_off, dx_off, endy;
 	int newy, newx;
+#ifdef HAVE_WCHAR
+	int i, tx;
+	wchar_t ch;
+#endif
 	__LINE	*wlp, *vlp, *dwlp;
 	WINDOW	*sub_win, *orig, *swin, *dwin;
 
@@ -289,29 +293,51 @@ _wnoutrefresh(WINDOW *win, int begy, int
 			while (wx < mx) {
 				__CTRACE(__CTRACE_REFRESH,
 				    "_wnoutrefresh: copy from %d, "
-				    "%d to %d, %d: '%s', 0x%x",
+				    "%d to %d, %d: '%s', 0x%x, 0x%x",
 				    wy, wx, y_off, x_off,
 				    unctrl(wlp->line[wx].ch),
-				    wlp->line[wx].attr);
+				    wlp->line[wx].attr, wlp->line[wx].cflags);
 				__CTRACE(__CTRACE_REFRESH,
-				    " (curdest %s, 0x%x)",
+				    " (curdest %s, 0x%x, 0x%x)",
 				    unctrl(vlp->line[x_off].ch),
-				    vlp->line[x_off].attr);
+				    vlp->line[x_off].attr,
+				    vlp->line[x_off].cflags);
 				/* Copy character */
 				vlp->line[x_off].ch = wlp->line[wx].ch;
 				/* Copy attributes  */
 				vlp->line[x_off].attr = wlp->line[wx].attr;
+				/* Copy character flags  */
+				vlp->line[x_off].cflags = wlp->line[wx].cflags;
 #ifdef HAVE_WCHAR
 				vlp->line[x_off].wcols = wlp->line[wx].wcols;
+
+				ch = wlp->line[wx].ch;
+				for (tx = x_off + 1, i = wlp->line[wx].wcols - 1;
+				    i > 0; i--, tx++) {
+					vlp->line[tx].ch = ch;
+					vlp->line[tx].wcols = i;
+					vlp->line[tx].cflags =
+					    CA_CONTINUATION;
+				}
 #endif /* HAVE_WCHAR */
 				if (win->flags & __ISDERWIN) {
 					dwlp->line[dx_off].ch =
 						wlp->line[wx].ch;
 					dwlp->line[dx_off].attr =
 						wlp->line[wx].attr;
+					dwlp->line[dx_off].cflags =
+						wlp->line[wx].cflags;
 #ifdef HAVE_WCHAR
 					dwlp->line[dx_off].wcols =
 						wlp->line[wx].wcols;
+
+					for (tx = dx_off + 1, i = wlp->line[wx].wcols - 1;
+					    i > 0; i--, tx++) {
+						dwlp->line[tx].ch = ch;
+						dwlp->line[tx].wcols = i;
+						dwlp->line[tx].cflags =
+						    CA_CONTINUATION;
+					}
 #endif /* HAVE_WCHAR */
 				}
 
@@ -319,6 +345,7 @@ _wnoutrefresh(WINDOW *win, int begy, int
 				if (wlp->line[wx].ch == win->bch) {
 					vlp->line[x_off].ch = win->bch;
 					vlp->line[x_off].wcols = win->wcols;
+					vlp->line[x_off].cflags = CA_BACKGROUND;
 					if (_cursesi_copy_nsp(win->bnsp,
 							      &vlp->line[x_off])
 					    == ERR)
@@ -328,6 +355,8 @@ _wnoutrefresh(WINDOW *win, int begy, int
 							win->bch;
 						dwlp->line[dx_off].wcols =
 						    win->wcols;
+						dwlp->line[dx_off].cflags =
+							wlp->line[wx].cflags;
 						if (_cursesi_copy_nsp(win->bnsp,
 						     &dwlp->line[dx_off])
 						    == ERR)
@@ -338,9 +367,15 @@ _wnoutrefresh(WINDOW *win, int begy, int
 				__CTRACE(__CTRACE_REFRESH, " = '%s', 0x%x\n",
 				    unctrl(vlp->line[x_off].ch),
 				    vlp->line[x_off].attr);
-				wx++; /* XXX should be + wcols, need to properly set continuation flag on multi-col */
+#ifdef HAVE_WCHAR
+				x_off += wlp->line[wx].wcols;
+				dx_off += wlp->line[wx].wcols;
+				wx += wlp->line[wx].wcols;
+#else
+				wx++;
 				x_off++;
 				dx_off++;
+#endif /* HAVE_WCHAR */
 			}
 
 			/* Set flags on "__virtscr" and unset on "win". */
@@ -400,7 +435,7 @@ _wnoutrefresh(WINDOW *win, int begy, int
 			 * are not forcing a redraw. A pad can be displayed
 			 * again without any of the contents changing.
 			 */
-			if ((!(win->flags & __ISPAD)) ||
+			if (!((win->flags & __ISPAD)) ||
 			    ((wlp->flags & __ISFORCED) == __ISFORCED))
 			{
 				/* Set change pointers on "win". */
@@ -578,7 +613,7 @@ doupdate(void)
 		    "stdscr(%p)-curscr(%p)-__virtscr(%p)\n",
 		    stdscr, curscr, _cursesi_screen->__virtscr);
 		for (i = 0; i < curscr->maxy; i++) {
-			__CTRACE(__CTRACE_REFRESH, "C: %d:", i);
+			__CTRACE(__CTRACE_REFRESH, "curscr: %d:", i);
 			__CTRACE(__CTRACE_REFRESH, " 0x%x \n",
 			    curscr->alines[i]->hash);
 			for (j = 0; j < curscr->maxx; j++)
@@ -596,8 +631,14 @@ doupdate(void)
 				__CTRACE(__CTRACE_REFRESH, " %d",
 				    curscr->alines[i]->line[j].wcols);
 			__CTRACE(__CTRACE_REFRESH, "\n");
+
+			__CTRACE(__CTRACE_REFRESH, " cflags:");
+			for (j = 0; j < curscr->maxx; j++)
+				__CTRACE(__CTRACE_REFRESH, " 0x%x",
+				    curscr->alines[i]->line[j].cflags);
+			__CTRACE(__CTRACE_REFRESH, "\n");
 #endif /* HAVE_WCHAR */
-			__CTRACE(__CTRACE_REFRESH, "W: %d:", i);
+			__CTRACE(__CTRACE_REFRESH, "win %p: %d:", win, i);
 			__CTRACE(__CTRACE_REFRESH, " 0x%x \n",
 			    win->alines[i]->hash);
 			__CTRACE(__CTRACE_REFRESH, " 0x%x ",
@@ -617,6 +658,11 @@ doupdate(void)
 				__CTRACE(__CTRACE_REFRESH, " %d",
 				    win->alines[i]->line[j].wcols);
 			__CTRACE(__CTRACE_REFRESH, "\n");
+			__CTRACE(__CTRACE_REFRESH, " cflags:");
+			for (j = 0; j < win->maxx; j++)
+				__CTRACE(__CTRACE_REFRESH, " 0x%x",
+				    win->alines[i]->line[j].cflags);
+			__CTRACE(__CTRACE_REFRESH, "\n");
 			__CTRACE(__CTRACE_REFRESH, " nsp:");
 			for (j = 0; j < curscr->maxx; j++)
 				__CTRACE(__CTRACE_REFRESH, " %p",
@@ -654,7 +700,9 @@ doupdate(void)
 			 * color to default.
 			 */
 			if ((was_cleared == 1) && (__using_color == 0))
-				win->alines[wy]->flags &= ~__ISFORCED;
+				win->alines[wy]->flags &= ~ 0L;
+			/*if ((was_cleared == 1) && (__using_color == 0))
+				win->alines[wy]->flags &= ~__ISFORCED;*/
 
 			if (makech(wy) == ERR)
 				return ERR;
@@ -734,15 +782,17 @@ cleanup:
 		for (i = 0; i < curscr->maxy; i++) {
 			for (j = 0; j < curscr->maxx; j++)
 				__CTRACE(__CTRACE_REFRESH,
-				    "[%d,%d](%x,%x,%d,%p)-(%x,%x,%d,%p)\n",
+				    "[%d,%d](%x,%x,%d,%x,%p)-(%x,%x,%d,%x,%p)\n",
 				    i, j,
 				    curscr->alines[i]->line[j].ch,
 				    curscr->alines[i]->line[j].attr,
 				    curscr->alines[i]->line[j].wcols,
+				    curscr->alines[i]->line[j].cflags,
 				    curscr->alines[i]->line[j].nsp,
 				    _cursesi_screen->__virtscr->alines[i]->line[j].ch,
 				    _cursesi_screen->__virtscr->alines[i]->line[j].attr,
 				    _cursesi_screen->__virtscr->alines[i]->line[j].wcols,
+				    _cursesi_screen->__virtscr->alines[i]->line[j].cflags,
 				    _cursesi_screen->__virtscr->alines[i]->line[j].nsp);
 		}
 	}
@@ -949,6 +999,10 @@ putattr_out(__LDATA *nsp)
 static int
 putch(__LDATA *nsp, __LDATA *csp, int wy, int wx)
 {
+#ifdef HAVE_WCHAR
+	int i;
+	__LDATA *tcsp;
+#endif /* HAVE_WCHAR */
 
 	if (csp != NULL)
 		putattr(nsp);
@@ -956,17 +1010,30 @@ putch(__LDATA *nsp, __LDATA *csp, int wy
 	if (!_cursesi_screen->curwin && csp) {
 		csp->attr = nsp->attr;
 		csp->ch = nsp->ch;
+		csp->cflags = nsp->cflags;
 #ifdef HAVE_WCHAR
 		if (_cursesi_copy_nsp(nsp->nsp, csp) == ERR)
 			return ERR;
 		csp->wcols = nsp->wcols;
+
+		if (nsp->wcols > 1) {
+			tcsp = csp;
+			tcsp++;
+			for (i = nsp->wcols - 1; i > 0; i--) {
+				tcsp->ch = csp->ch;
+				tcsp->attr = csp->attr;
+				tcsp->wcols = i;
+				tcsp->cflags = CA_CONTINUATION;
+				tcsp++;
+			}
+		}
 #endif /* HAVE_WCHAR */
 	}
 
 #ifndef HAVE_WCHAR
 	__cputchar((int)nsp->ch);
 #else
-	if (nsp->wcols <= 0)
+	if ((nsp->wcols <= 0) || (nsp->cflags & CA_CONTINUATION))
 		goto out;
 
 	if (((_cursesi_screen->nca & nsp->attr) == 0) && (__using_color == 1) &&
@@ -974,7 +1041,7 @@ putch(__LDATA *nsp, __LDATA *csp, int wy
 		__set_color(curscr, nsp->attr & __COLOR);
 	__cputwchar((int)nsp->ch);
 	__CTRACE(__CTRACE_REFRESH,
-	    "putch: (%d,%d)putwchar(0x%x)\n", wy, wx - 1, nsp->ch);
+	    "putch: (%d,%d)putwchar(0x%x)\n", wy, wx, nsp->ch);
 
 	/* Output non-spacing characters for the cell. */
 	__cursesi_putnsp(nsp->nsp, wy, wx);
@@ -1062,10 +1129,11 @@ static int
 makech(int wy)
 {
 	WINDOW	*win;
-	static __LDATA blank, space;
-	__LDATA *nsp, *csp, *cp, *cep, *fsp, *tld;
+	static __LDATA blank;
+	__LDATA *nsp, *csp, *cp, *cep, *fsp;
 	__LINE *wlp;
-	size_t	clsp, nlsp;	/* Last space in lines. */
+	int	nlsp;	/* offset to first space at eol. */
+	size_t	mlsp;
 	int	lch, wx, owx, chw;
 	const char	*ce;
 	attr_t	lspc;		/* Last space colour */
@@ -1082,19 +1150,13 @@ makech(int wy)
 
 	blank.ch = win->bch;
 	blank.attr = win->battr;
+	blank.cflags = CA_BACKGROUND;
 #ifdef HAVE_WCHAR
 	if (_cursesi_copy_nsp(win->bnsp, &blank) == ERR)
 		return ERR;
 	blank.wcols = win->wcols;
 	attr_mask = WA_ATTRIBUTES;
-
-	space.ch = (wchar_t) btowc((int) ' ');
-	space.nsp = NULL;
-	space.wcols = 1;
-	space.attr = WA_NORMAL;
 #else
-	space.ch = ' ';
-	space.attr = A_NORMAL;
 	attr_mask = A_ATTRIBUTES;
 #endif /* HAVE_WCHAR */
 	battr = win->battr & attr_mask;
@@ -1153,6 +1215,15 @@ makech(int wy)
 		    "makech: csp is on curscr:(%d,%d)\n", wy, wx);
 	}
 
+
+	while (win->alines[wy]->line[wx].cflags & CA_CONTINUATION) {
+		wx--;
+		if (wx <= 0) {
+			wx = 0;
+			break;
+		}
+	}
+
 	nsp = fsp = &win->alines[wy]->line[wx];
 
 #ifdef DEBUG
@@ -1171,32 +1242,35 @@ makech(int wy)
 	 */
 	if (clr_eol && !_cursesi_screen->curwin && (!(__using_color)
 	    || (__using_color && back_color_erase))) {
+		nlsp = win->maxx - 1;
 		cp = &win->alines[wy]->line[win->maxx - 1];
 #ifdef HAVE_WCHAR
-		while ((_cursesi_celleq(cp, &space) == 1) &&
+		while ((_cursesi_celleq(cp, &blank) == 1) &&
 #else
-		while (cp->ch == space.ch &&
+		while (cp->ch == blank.ch &&
 #endif /* HAVE_WCHAR */
 		    ((cp->attr & attr_mask) == battr)) {
-			if (cp-- <= win->alines[wy]->line)
-				break;
-		}
-
 #ifdef HAVE_WCHAR
-		if ((cp->cflags & CA_CONTINUATION) == CA_CONTINUATION)
+			nlsp -= cp->wcols;
+			cp -= cp->wcols;
+#else
+			nlsp--;
 			cp--;
 #endif /* HAVE_WCHAR */
 
-		if (win->alines[wy]->line > cp)
+			if (nlsp <= 0)
+				break;
+		}
+
+
+		if (nlsp < 0)
 			nlsp = 0;
-		else
-			nlsp = cp - win->alines[wy]->line;
 	}
 
 	ce = clr_eol;
 
 	while (wx <= lch) {
-		__CTRACE(__CTRACE_REFRESH, "makech: wx=%d,lch=%d\n", wx, lch);
+		__CTRACE(__CTRACE_REFRESH, "makech: wx=%d,lch=%d, nlsp=%d\n", wx, lch, nlsp);
 #ifdef HAVE_WCHAR
 		__CTRACE(__CTRACE_REFRESH, "makech: farnarkle: flags 0x%x, cflags 0x%x, color_init %d, celleq %d\n",
 			wlp->flags, nsp->cflags, __do_color_init, _cursesi_celleq(nsp, csp));
@@ -1217,12 +1291,15 @@ makech(int wy)
 				while (wx <= lch && _cursesi_celleq(nsp, csp)) {
 #ifdef HAVE_WCHAR
 					wx += nsp->wcols;
+					if (!_cursesi_screen->curwin)
+						csp += nsp->wcols;
+					nsp += nsp->wcols;
 #else
 					wx++;
-#endif
 					nsp++;
 					if (!_cursesi_screen->curwin)
 						++csp;
+#endif
 				}
 				continue;
 			}
@@ -1241,25 +1318,25 @@ makech(int wy)
 		       ((wlp->flags & __ISFORCED) || !_cursesi_celleq(nsp, csp)))
 		{
 			if ((ce != NULL) && (wx >= nlsp) &&
-			    (nsp->ch == space.ch) &&
-			    (__do_color_init == 1 || nsp->attr == space.attr))
+			    (nsp->ch == blank.ch) &&
+			    (__do_color_init == 1 || nsp->attr == blank.attr))
 			{
 				/* Check for clear to end-of-line. */
-				cep = &curscr->alines[wy]->line[win->maxx - 1];
+				cep = &win->alines[wy]->line[win->maxx - 1];
 				while (cep->ch == blank.ch && cep->attr == battr)
 					if (cep-- <= csp)
 						break;
-				if (cep >= (curscr->alines[wy]->line + win->begx * __LDATASIZE))
-					clsp = cep - curscr->alines[wy]->line -
-					    win->begx * __LDATASIZE;
-				else
-					clsp = 0;
+
+				mlsp = &win->alines[wy]->line[win->maxx - 1]
+				    - win->alines[wy]->line
+				    - win->begx * __LDATASIZE;
+
 				__CTRACE(__CTRACE_REFRESH,
-				    "makech: clsp = %zu, nlsp = %zu, strlen(ce) = %zu\n",
-				    clsp, nlsp, strlen(ce));
+				    "makech: nlsp = %d, max = %zu, strlen(ce) = %zu\n",
+				    nlsp, mlsp, strlen(ce));
 				__CTRACE(__CTRACE_REFRESH,
 				    "makech: line = %p, cep = %p, begx = %u\n",
-				    curscr->alines[wy]->line, cep, win->begx);
+				    win->alines[wy]->line, cep, win->begx);
 
 				/*
 				 * work out how to clear the line.  If:
@@ -1272,14 +1349,11 @@ makech(int wy)
 				 *    (to prevent a scroll)
 				 * then emit the ce string.
 				 */
-				if (((((clsp - nlsp > strlen(ce)) ||
-				     (__do_color_init && back_color_erase)) &&
-				     (clsp != win->maxx * __LDATASIZE)) ||
-				     (wy == win->maxy - 1)) &&
-				    (!(__using_color) ||
-				     (__using_color && back_color_erase)))
-				{
-					if(wlp->line[wx].attr & win->screen->nca) {
+				if (((wy == win->maxy - 1) ||
+				    ((mlsp - wx) > strlen(ce))) &&
+				     ((__using_color && back_color_erase) ||
+				      (! __using_color))) {
+					if (wlp->line[wx].attr & win->screen->nca) {
 						__unsetattr(0);
 					} else if (__using_color &&
 					    ((__do_color_init == 1) ||
@@ -1290,16 +1364,21 @@ makech(int wy)
 					}
 					tputs(ce, 0, __cputchar);
 					_cursesi_screen->lx = wx + win->begx;
-					while (wx++ <= clsp) {
+					csp = &curscr->alines[wy]->line[wx + win->begx];
+					wx = wx + win->begx;
+					while (wx++ <= (curscr->maxx - 1)) {
 						csp->attr = blank.attr;
 						csp->ch = blank.ch;
+						csp->cflags = CA_BACKGROUND;
 #ifdef HAVE_WCHAR
 						if (_cursesi_copy_nsp(blank.nsp, csp) == ERR)
 							return ERR;
 						csp->wcols = blank.wcols;
+						csp += blank.wcols;
+#else
+						csp++;
 #endif /* HAVE_WCHAR */
 						assert(csp != &blank);
-						csp++;
 					}
 					return OK;
 				}
@@ -1314,7 +1393,7 @@ makech(int wy)
 			chw = 1;
 #endif /* HAVE_WCHAR */
 			owx = wx;
-			if (wx + chw >= win->maxx &&
+			if (wx + chw >= (win->maxx) &&
 			    wy == win->maxy - 1 && !_cursesi_screen->curwin)
 			{
 				if (win->flags & __ENDLINE)
@@ -1324,10 +1403,11 @@ makech(int wy)
 
 					if (win->flags & __SCROLLOK)
 						e = putch(nsp, csp, wy, wx);
-					else
+					else {
 						e = putchbr(nsp, csp,
 						    nsp == fsp ? NULL : nsp - 1,
 						    wy, wx);
+					}
 					if (e == ERR)
 						return ERR;
 				}
@@ -1344,22 +1424,17 @@ makech(int wy)
 			if (wx + chw < win->maxx || wy < win->maxy - 1 ||
 			    !(win->flags & __SCROLLWIN))
 			{
-				tld = nsp;
-				if (_cursesi_celleq(&blank, nsp))
-					tld = &blank;
-				
-				if (putch(tld, csp, wy, wx) == ERR)
+				if (putch(nsp, csp, wy, wx) == ERR)
 					return ERR;
-				if (!_cursesi_screen->curwin) {
-					assert(csp != &blank);
-					csp++;
-				}
 			} else {
 				putattr(nsp);
 				putattr_out(nsp);
 			}
 			wx += chw;
 			nsp += chw;
+			if (!_cursesi_screen->curwin)
+				csp += chw;
+
 			__CTRACE(__CTRACE_REFRESH,
 			    "makech: 2: wx = %d, lx = %d\n",
 			    wx, _cursesi_screen->lx);
@@ -1626,6 +1701,7 @@ done:
 		for (i = 0; i < BLANKSIZE; i++) {
 			buf[i].ch = curscr->bch;
 			buf[i].attr = 0;
+			buf[i].cflags = CA_BACKGROUND;
 		}
 	}
 #else
@@ -1635,6 +1711,7 @@ done:
 			if (_cursesi_copy_nsp(curscr->bnsp, &buf[i]) == ERR)
 				return;
 			buf[i].attr = 0;
+			buf[i].cflags = CA_BACKGROUND;
 			buf[i].wcols = curscr->wcols;
 		}
 	}

Index: src/lib/libcurses/resize.c
diff -u src/lib/libcurses/resize.c:1.35 src/lib/libcurses/resize.c:1.36
--- src/lib/libcurses/resize.c:1.35	Tue Apr 26 22:40:32 2022
+++ src/lib/libcurses/resize.c	Wed Oct 19 06:09:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize.c,v 1.35 2022/04/26 22:40:32 blymn Exp $	*/
+/*	$NetBSD: resize.c,v 1.36 2022/10/19 06:09:27 blymn Exp $	*/
 
 /*
  * Copyright (c) 2001
@@ -33,7 +33,7 @@
 #if 0
 static char sccsid[] = "@(#)resize.c   blymn 2001/08/26";
 #else
-__RCSID("$NetBSD: resize.c,v 1.35 2022/04/26 22:40:32 blymn Exp $");
+__RCSID("$NetBSD: resize.c,v 1.36 2022/10/19 06:09:27 blymn Exp $");
 #endif
 #endif				/* not lint */
 
@@ -350,6 +350,7 @@ __resizewin(WINDOW *win, int nlines, int
 		lp = win->alines[i];
 		for (sp = lp->line, j = 0; j < win->maxx; j++, sp++) {
 			sp->attr = 0;
+			sp->cflags = CA_BACKGROUND;
 #ifndef HAVE_WCHAR
 			sp->ch = win->bch;
 #else

Reply via email to