]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tty/lib_vidattr.c
ncurses 5.0
[ncurses.git] / ncurses / tty / lib_vidattr.c
similarity index 90%
rename from ncurses/lib_vidattr.c
rename to ncurses/tty/lib_vidattr.c
index cbd4634a79a543fb6d6b520351c3d79bc715007c..20cc2b138011c528a4f162aadee7ecfedb58d239 100644 (file)
@@ -64,7 +64,7 @@
 #include <curses.priv.h>
 #include <term.h>
 
-MODULE_ID("$Id: lib_vidattr.c,v 1.20 1998/02/11 12:13:56 tom Exp $")
+MODULE_ID("$Id: lib_vidattr.c,v 1.23 1999/06/12 21:20:41 tom Exp $")
 
 #define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc)
 
@@ -74,11 +74,22 @@ MODULE_ID("$Id: lib_vidattr.c,v 1.20 1998/02/11 12:13:56 tom Exp $")
 #define TurnOff(mask,mode) \
        if ((turn_off & mask) && mode) { doPut(mode); turn_off &= ~mask; }
 
+       /* if there is no current screen, assume we *can* do color */
+#define SetColorsIf(why,old_attr) \
+       if ((!SP || SP->_coloron) && (why)) { \
+               int old_pair = PAIR_NUMBER(old_attr); \
+               T(("old pair = %d -- new pair = %d", old_pair, pair)); \
+               if ((pair != old_pair) \
+                || (reverse ^ ((old_attr & A_REVERSE) != 0))) { \
+                       _nc_do_color(pair, reverse, outc); \
+               } \
+       }
+
 int vidputs(attr_t newmode, int  (*outc)(int))
 {
 static attr_t previous_attr = A_NORMAL;
 attr_t turn_on, turn_off;
-int pair, current_pair;
+int pair;
 bool reverse = FALSE;
 bool used_ncv = FALSE;
 
@@ -91,7 +102,8 @@ bool used_ncv = FALSE;
        T(("previous attribute was %s", _traceattr(previous_attr)));
 
 #if !USE_XMC_SUPPORT
-       if (magic_cookie_glitch > 0)
+       if ((SP != 0)
+        && (magic_cookie_glitch > 0))
                newmode &= ~(SP->_xmc_suppress);
 #endif
 
@@ -132,26 +144,15 @@ bool used_ncv = FALSE;
                returnCode(OK);
 
        pair = PAIR_NUMBER(newmode);
-       current_pair = PAIR_NUMBER(previous_attr);
 
        if (reverse) {
                newmode &= ~A_REVERSE;
-               pair = -pair;
        }
-       if (previous_attr & A_REVERSE)
-               current_pair = -current_pair;
 
        turn_off = (~newmode & previous_attr) & ALL_BUT_COLOR;
        turn_on  = (newmode & ~previous_attr) & ALL_BUT_COLOR;
 
-       /* if there is no current screen, assume we *can* do color */
-       if ((!SP || SP->_coloron) && pair == 0) {
-               T(("old pair = %d -- new pair = %d", current_pair, pair));
-               if (pair != current_pair) {
-                       _nc_do_color(pair, reverse, outc);
-                       previous_attr &= ~A_COLOR;
-               }
-       }
+       SetColorsIf(pair == 0, previous_attr);
 
        if (newmode == A_NORMAL) {
                if((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) {
@@ -163,6 +164,7 @@ bool used_ncv = FALSE;
                        previous_attr &= ~A_COLOR;
                }
 
+               SetColorsIf(pair != 0, previous_attr);
        } else if (set_attributes && !used_ncv) {
                if (turn_on || turn_off) {
                        TPUTS_TRACE("set_attributes");
@@ -178,19 +180,27 @@ bool used_ncv = FALSE;
                                (newmode & A_ALTCHARSET) != 0), 1, outc);
                        previous_attr &= ~A_COLOR;
                }
+               SetColorsIf(pair != 0, previous_attr);
        } else {
 
                T(("turning %s off", _traceattr(turn_off)));
 
                TurnOff(A_ALTCHARSET,  exit_alt_charset_mode);
-               TurnOff(A_UNDERLINE,   exit_underline_mode);
-               TurnOff(A_STANDOUT,    exit_standout_mode);
+
+               if (!SP || SP->_use_rmul) {
+                       TurnOff(A_UNDERLINE,   exit_underline_mode);
+               }
+
+               if (!SP || SP->_use_rmso) {
+                       TurnOff(A_STANDOUT,    exit_standout_mode);
+               }
 
                if (turn_off && exit_attribute_mode) {
                        doPut(exit_attribute_mode);
                        turn_on  |= (newmode & (chtype)(~A_COLOR));
                        previous_attr &= ~A_COLOR;
                }
+               SetColorsIf(pair != 0, previous_attr);
 
                T(("turning %s on", _traceattr(turn_on)));
 
@@ -211,15 +221,6 @@ bool used_ncv = FALSE;
                TurnOn (A_VERTICAL,   enter_vertical_hl_mode);
        }
 
-       /* if there is no current screen, assume we *can* do color */
-       if ((!SP || SP->_coloron) && pair != 0) {
-               current_pair = PAIR_NUMBER(previous_attr);
-               T(("old pair = %d -- new pair = %d", current_pair, pair));
-               if (pair != current_pair) {
-                       _nc_do_color(pair, reverse, outc);
-               }
-       }
-
        if (reverse)
                newmode |= A_REVERSE;