[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bkgd() with character part set to 0
From: |
Thomas Dickey |
Subject: |
Re: bkgd() with character part set to 0 |
Date: |
Mon, 6 May 2024 15:07:19 -0400 |
On Mon, May 06, 2024 at 01:11:04PM -0400, Bill Gray wrote:
> I just ran into this issue, and am not quite sure how it really ought to be
> handled.
>
> In a perfect world, I think people would call bkgd() with the character part
> set to a non-zero value, such as
>
> bkgd( ' ' | COLOR_PAIR( 0));
>
> However, looking through both the ncurses and PDCurses* tests, I see a fair
> number of calls where the character bits are left blank. This appears to
> work, right up to the point where you read a background character using the
> inch() family of functions and then output it using addch(), as shown in the
> code snippet below.
>
> As the boilerplate text inside it says, on wide-char ncurses, the 0
> background character is read in, then output as ^@. I noticed the problem
> when building 'ozdemo' (a PDCurses* test program) with ncurses.
>
> PDCurses* evades this by saying that if you call bkgd( ) (internally,
> wbkgdset( )) with a zero character, it gets remapped to a space :
>
> https://github.com/Bill-Gray/PDCursesMod/blob/master/pdcurses/bkgd.c#L153
>
> I'd tend to think that the behavior with a zero character is
> implementation-dependent, and mildly risky. I expect to set the background
> explicitly to a space in future. But the conversion of 0 to a space
> (apparently done in 8-bit-char ncurses as well as in all PDCurses*) seems
> like good behavior to me.
The background should fill in a space - in revising wbkgd() and wbkgrnd() in
20181208 (released in 6.2 20200212), I broke that detail and fixed it after
releasing 6.2
Perhaps your example is another instance of the breakage.
These changes are relevant:
20200301
+ modify wbkgd() and wbkgrnd() to avoid storing a null in the
background character, because it may be used in cases where the
corresponding 0x80 is not treated as a null (report by Marc Rechte,
cf: 20181208).
20190817
+ amend 20181208 changes for wbkgd() and wbkgrnd(), fixing a few
details where it still differed from SVr4.
20181208
+ modify wbkgd() and wbkgrnd() to improve compatibility with SVr4
curses, changing the way the window rendition is updated when the
background character is modified (report by Valery Ushakov).
> -- Bill
>
> #include <curses.h>
>
> /* Compile with gcc -Wall -Wextra -pedantic -O3 -oz z.c -lncursesw
> (or with -lncurses for narrow-char build) */
>
> int main( void)
> {
> chtype c;
>
> initscr( );
> bkgd( COLOR_PAIR( 0));
> c = mvinch( 1, 1);
> mvaddch( 1, 1, c);
> mvprintw( 2, 1, "The above line will show ^@ on wide ncurses builds.");
> mvprintw( 3, 1, "It should be blank on narrow-char builds and on all");
> mvprintw( 4, 1, "PDCurses and PDCursesMod builds. Hit the any key.");
> getch( );
> endwin( );
> return(0);
> }
>
--
Thomas E. Dickey <dickey@invisible-island.net>
https://invisible-island.net
signature.asc
Description: PGP signature