2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
11 * Permission is hereby granted to reproduce and distribute ncurses *
12 * by any means and for any fee, whether alone or as part of a *
13 * larger distribution, in source or in binary form, PROVIDED *
14 * this notice is included with any such distribution, and is not *
15 * removed from any of its header files. Mention of ncurses in any *
16 * applications linked with it is highly appreciated. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
23 * vidputs(newmode, outc)
25 * newmode is taken to be the logical 'or' of the symbols in curses.h
26 * representing graphic renditions. The terminal is set to be in all of
27 * the given modes, if possible.
29 * if the new attribute is normal
30 * if exit-alt-char-set exists
32 * emit exit-attribute-mode
33 * else if set-attributes exists
34 * use it to set exactly what you want
36 * if exit-attribute-mode exists
39 * turn off those which can be turned off and aren't in
41 * turn on each mode which should be on and isn't, one by one
43 * NOTE that this algorithm won't achieve the desired mix of attributes
44 * in some cases, but those are probably just those cases in which it is
45 * actually impossible, anyway, so...
47 * NOTE that we cannot assume that there's no interaction between color
48 * and other attribute resets. So each time we reset color (or other
49 * attributes) we'll have to be prepared to restore the other.
52 #include <curses.priv.h>
55 MODULE_ID("$Id: lib_vidattr.c,v 1.14 1997/05/06 16:02:43 tom Exp $")
57 #define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc)
59 #define TurnOn(mask,mode) \
60 if ((turn_on & mask) && mode) { doPut(mode); }
62 #define TurnOff(mask,mode) \
63 if ((turn_off & mask) && mode) { doPut(mode); turn_off &= ~mask; }
65 int vidputs(attr_t newmode, int (*outc)(int))
67 static attr_t previous_attr = A_NORMAL;
68 attr_t turn_on, turn_off;
69 int pair, current_pair;
71 T((T_CALLED("vidputs(%s)"), _traceattr(newmode)));
73 /* this allows us to go on whether or not newterm() has been called */
75 previous_attr = SP->_current_attr;
77 T(("previous attribute was %s", _traceattr(previous_attr)));
79 if (newmode == previous_attr)
82 turn_off = (~newmode & previous_attr) & ALL_BUT_COLOR;
83 turn_on = (newmode & ~previous_attr) & ALL_BUT_COLOR;
85 pair = PAIR_NUMBER(newmode);
86 current_pair = PAIR_NUMBER(previous_attr);
88 /* if there is no current screen, assume we *can* do color */
89 if ((!SP || SP->_coloron) && pair == 0) {
90 T(("old pair = %d -- new pair = %d", current_pair, pair));
91 if (pair != current_pair) {
92 _nc_do_color(pair, outc);
93 previous_attr &= ~A_COLOR;
97 if (newmode == A_NORMAL) {
98 if((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) {
99 doPut(exit_alt_charset_mode);
100 previous_attr &= ~A_ALTCHARSET;
103 doPut(exit_attribute_mode);
104 previous_attr &= ~A_COLOR;
107 } else if (set_attributes) {
108 if (turn_on || turn_off) {
109 TPUTS_TRACE("set_attributes");
110 tputs(tparm(set_attributes,
111 (newmode & A_STANDOUT) != 0,
112 (newmode & A_UNDERLINE) != 0,
113 (newmode & A_REVERSE) != 0,
114 (newmode & A_BLINK) != 0,
115 (newmode & A_DIM) != 0,
116 (newmode & A_BOLD) != 0,
117 (newmode & A_INVIS) != 0,
118 (newmode & A_PROTECT) != 0,
119 (newmode & A_ALTCHARSET) != 0), 1, outc);
120 previous_attr &= ~A_COLOR;
124 T(("turning %s off", _traceattr(turn_off)));
126 TurnOff(A_ALTCHARSET, exit_alt_charset_mode);
127 TurnOff(A_UNDERLINE, exit_underline_mode);
128 TurnOff(A_STANDOUT, exit_standout_mode);
130 if (turn_off && exit_attribute_mode) {
131 doPut(exit_attribute_mode);
132 turn_on |= (newmode & (chtype)(~A_COLOR));
133 previous_attr &= ~A_COLOR;
136 T(("turning %s on", _traceattr(turn_on)));
138 TurnOn (A_ALTCHARSET, enter_alt_charset_mode);
139 TurnOn (A_BLINK, enter_blink_mode);
140 TurnOn (A_BOLD, enter_bold_mode);
141 TurnOn (A_DIM, enter_dim_mode);
142 TurnOn (A_REVERSE, enter_reverse_mode);
143 TurnOn (A_STANDOUT, enter_standout_mode);
144 TurnOn (A_PROTECT, enter_protected_mode);
145 TurnOn (A_INVIS, enter_secure_mode);
146 TurnOn (A_UNDERLINE, enter_underline_mode);
147 TurnOn (A_HORIZONTAL, enter_horizontal_hl_mode);
148 TurnOn (A_LEFT, enter_left_hl_mode);
149 TurnOn (A_LOW, enter_low_hl_mode);
150 TurnOn (A_RIGHT, enter_right_hl_mode);
151 TurnOn (A_TOP, enter_top_hl_mode);
152 TurnOn (A_VERTICAL, enter_vertical_hl_mode);
155 /* if there is no current screen, assume we *can* do color */
156 if ((!SP || SP->_coloron) && pair != 0) {
157 current_pair = PAIR_NUMBER(previous_attr);
158 T(("old pair = %d -- new pair = %d", current_pair, pair));
159 if (pair != current_pair) {
160 _nc_do_color(pair, outc);
165 SP->_current_attr = newmode;
167 previous_attr = newmode;
172 int vidattr(attr_t newmode)
174 T((T_CALLED("vidattr(%s)"), _traceattr(newmode)));
176 returnCode(vidputs(newmode, _nc_outch));
179 attr_t termattrs(void)
181 int attrs = A_NORMAL;
183 if (enter_alt_charset_mode)
184 attrs |= A_ALTCHARSET;
186 if (enter_blink_mode)
195 if (enter_reverse_mode)
198 if (enter_standout_mode)
201 if (enter_protected_mode)
204 if (enter_secure_mode)
207 if (enter_underline_mode)
208 attrs |= A_UNDERLINE;