[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bkgd() with character part set to 0
From: |
Bill Gray |
Subject: |
bkgd() with character part set to 0 |
Date: |
Mon, 6 May 2024 13:11:04 -0400 |
User-agent: |
Mozilla Thunderbird |
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.
-- 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);
}
- bkgd() with character part set to 0,
Bill Gray <=