bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Starange behavior of bkgd when called after bkgdset


From: Thomas Dickey
Subject: Re: Starange behavior of bkgd when called after bkgdset
Date: Sun, 26 Jun 2022 05:45:41 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Sat, Jun 25, 2022 at 11:19:56PM -0400, Bill Gray wrote:
> On 6/25/22 17:41, Thomas Dickey wrote:
> > On Sat, Jun 25, 2022 at 05:06:54PM -0400, Thomas Dickey wrote:
> > > On Sat, Jun 25, 2022 at 04:27:58PM -0400, Thomas Dickey wrote:
> > > > On Sat, Jun 25, 2022 at 07:18:58PM +0200, Anton Vidovic wrote:
> > > ...
> > > > > Compare that to the second situation:
> > > > > 
> > > > > Calling bkgdset('+') sets only the bg char of the single line (because
> > > > > of the "\n" subsequent call to addstr):
> > > > > 
> > > > > call+1+++++++++
> > > > > 
> > > > > and the subsequent call to bkgd('-') only affects that line and the
> > > > > second line and leaves the rest of the screen without any background
> > > > > char:
> > > > > 
> > > > > call-1---------
> > > > > call-2---------
> > > 
> > > Interestingly enough, Solaris (SVr4) curses does this.
> > > The colors may differ (no bce), but the +'s and -'s match up.
> > > 
> > > > sure - if I conclude that it's correct.
> > > 
> > > yes... more documentation is needed, to explain this.
> > 
> > Actually it's there, in the second bullet:
> > 
> >     bkgd
> >         The bkgd and wbkgd functions set the background property of the 
> > current
> >         or  specified window and then apply this setting to every character 
> > po‐
> >         sition in that window:
> > 
> >         •   The rendition of every character on the screen is  changed  to  
> > the
> >             new background rendition.
> > 
> >         •   Wherever  the former background character appears, it is 
> > changed to
> >             the new background character.
> 
>    Apologies in advance if I'm being a bit thick here.  I think I grasp what
> the background _character_ ought to do,  but am unclear about how the
> background _colors_ should behave in this case where you've used bkgdset()
> and then bkgd().

As I understood the SVr4 code (illumos-gate), and reimplemented the
logic in ncurses, the old background has an effect with color (and
attributes).  Since neither SVr4 nor X/Open gives adequate detail,
I documented this in the manual page:

https://invisible-island.net/ncurses/man/curs_bkgd.3x.html#h3-bkgd

       o   The library then checks if the cell uses  color,  i.e.,  its  color
           pair  value  is nonzero.  If not, it simply replaces the attributes
           and color pair in the cell  with  those  from  the  new  background
           character.

       o   If  the  cell uses color, and that matches the color in the current
           background, the library removes attributes which may have come from
           the current background and adds attributes from the new background.
           It finishes by setting the cell to  use  the  color  from  the  new
           background.

       o   If  the  cell  uses color, and that does not match the color in the
           current  background,  the  library  updates  only   the   non-color
           attributes,  first  removing  those  which  may  have come from the
           current  background,  and  then  adding  attributes  from  the  new
           background.
> 
>    I made minor modifications to run this in ncurses 6.2,  PDCurses, and
> PDCursesMod,  and to first show 'call 0   ++++',  for reasons that will
> become clear :
> 
> https://www.projectpluto.com/temp/bkgd_t.c
> 
>    With ncurses 6.2,  running Anton's test program got me
> 
> 6.2
> call 0    ++++
> call+1+++++++++++++++++++
> 
>    with only the 'call 1' line with a red background.  Hit a key,  and that
> becomes
> 
> 6.2
> call 0    ++++
> call-1-------------------
> call-2-------------------
> (no dashes except on those two lines)
> 
>    and the entire screen now has a blue background.  Screenshots at
> 
> https://projectpluto.com/temp/before.png
> https://projectpluto.com/temp/after.png
> 
>    Are you saying that the intended behavior (demonstrated in 6.3) is that
> only the call-1 and call-2 lines should have a blue background, with the
> rest of the screen left white on black?
> 
>    Trying it with PDCurses and PDCursesMod got the same 'before',  but the
> 'after' becomes :
> 
> https://projectpluto.com/temp/after_pdcm.png
> 
>    Similar to ncurses 6.2,  except only the call 1 and 2 lines change color,
> and the '++++' for call 0 becomes '----'.  I _think_ that second bullet
> point means it should change just like that.  But it seems a little strange.
> 
> Thanks!          -- Bill
> 
> > I'll add a few sentences to explain this special case.
> > 
> > > What's happening is due to this check:
> > > https://github.com/ThomasDickey/ncurses-snapshots/blob/6bf016303929e7f49758b7ed27e3b255310b959f/ncurses/base/lib_bkgd.c#L222
> > > 
> > >           if (CharEq(*cp, old_bkgd)) {
> > > #if USE_WIDEC_SUPPORT
> > >               if (!narrow) {
> > >                   if (Charable(new_bkgd)) {
> > >                       SetChar2(*cp, CharOf(new_char));
> > >                   } else {
> > >                       SetChar(*cp, L' ', AttrOf(new_char));
> > >                   }
> > >                   memcpy(cp->chars,
> > >                          new_char.chars,
> > >                          CCHARW_MAX * sizeof(cp->chars[0]));
> > >               } else
> > > #endif
> > >                   SetChar2(*cp, CharOf(new_char));
> > >           }
> > > 
> > > In the logic which I adapted from Solaris, that comparison against
> > > old_bkgd is checking each cell to determine if the cell used the
> > > same background-character as the old value for the background-character.
> > > If it did not, it leaves that untouched.
> > > 
> > > Setting the background character to "+" without filling the screen with 
> > > +'s
> > > produces this special case.
> > 
> 

-- 
Thomas E. Dickey <dickey@invisible-island.net>
https://invisible-island.net
ftp://ftp.invisible-island.net

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]