bug-ncurses
[Top][All Lists]
Advanced

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

Colors and spaces


From: Rick Richardson
Subject: Colors and spaces
Date: Sat, 21 Sep 2002 08:22:51 -0500
User-agent: Mutt/1.2.5.1i

This might be a bug, a lack of understanding, or a feature request...

In my application, I will often do something like this:

        init_pair(1, COLOR_BLUE, -1);
        ...
        wattrset(win, COLOR_PAIR(1));
        mvprintw(win, y, x, "this is a demo line");

That works fine and gives me a line of blue text on the users
background color.

Sometimes in my application, that line might be in a scrolling window
where I want a whole-line cursor.  When the cursor is to be on that
line, I or in the A_REVERSE sttribute to all characters on that line,
and when the cursor moves off that line, I turn off the A_REVERSE
attribute.  The code that does this is intended to be blissfully
unware of any color attributes associated with that line:

        // Turn whole-line cursor on or off
        for (x = sx; x < ex; ++x)
        {
                chtype  ch = mvwinch(win, y, x);
                if (on) ch |= A_REVERSE;
                else ch &= ~A_REVERSE;
                mvwaddch(win, y, x, ch);
        }

However, this code fails to do "the right thing" because the space
characters that "mvprintw()" added to the display do not have any
attributes associated with them.  The value of ch returned by
mvwinch() for all space characters is always 0x0020, while every other
character has the 0x0100 (COLOR_PAIR(1)) bits set.

I have an ugly workaround for this problem, which goes approximately
like this:

        wattrset(win, COLOR_PAIR(1));
        mvprintw(win, y, x, "this is a demo line");
        // Force attributes on space characters
        for (x = sx; x < ex; ++x)
        {
                chtype  ch = mvwinch(win, y, x);
                if ((ch & 0xff) == ' ')
                        mvwaddch(win, y, x, ch | COLOR_PAIR(1));
        }

I have to do this for every line I add to the scrolling window.

It seems to me that there needs to be a way to tell the *printw()
routines to respect the current attribute when printing spaces.
Perhaps there is a flag and I just didn't find it in the doco.
Perhaps a new routine keep_attributes_on_spaces(TRUE/FALSE) needs to
be provided.

Comments?

-Rick

N.B. The *chgat() routines were broken on one version of curses I
used, which is why I use winch()/waddch() to change attrributes,
but that is not germain to the above issue.


-- 
Rick Richardson  address@hidden        http://home.mn.rr.com/richardsons/
Stock information at your fingertips:   http://linuxtrade.0catch.com/

I've never used Linux, and probably never will. -- Me, 06/22/94
I'm using Linux.  -- Me, 12/14/95




reply via email to

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