Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2018-2020,2023 Thomas E. Dickey * |
| 3 | * Copyright 1998-2014,2017 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 4 | * * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a * |
| 6 | * copy of this software and associated documentation files (the * |
| 7 | * "Software"), to deal in the Software without restriction, including * |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, * |
| 9 | * distribute, distribute with modifications, sublicense, and/or sell * |
| 10 | * copies of the Software, and to permit persons to whom the Software is * |
| 11 | * furnished to do so, subject to the following conditions: * |
| 12 | * * |
| 13 | * The above copyright notice and this permission notice shall be included * |
| 14 | * in all copies or substantial portions of the Software. * |
| 15 | * * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * |
| 17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * |
| 19 | * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * |
| 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * |
| 21 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * |
| 22 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * |
| 23 | * * |
| 24 | * Except as contained in this notice, the name(s) of the above copyright * |
| 25 | * holders shall not be used in advertising or otherwise to promote the * |
| 26 | * sale, use or other dealings in this Software without prior written * |
| 27 | * authorization. * |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | /**************************************************************************** |
| 31 | * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * |
| 32 | * and: Eric S. Raymond <esr@snark.thyrsus.com> * |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 33 | * and: Thomas E. Dickey 1996-on * |
| 34 | * and: Juergen Pfeifer 2009 * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 35 | ****************************************************************************/ |
| 36 | |
| 37 | /* |
| 38 | * vidputs(newmode, outc) |
| 39 | * |
| 40 | * newmode is taken to be the logical 'or' of the symbols in curses.h |
| 41 | * representing graphic renditions. The terminal is set to be in all of |
| 42 | * the given modes, if possible. |
| 43 | * |
| 44 | * if the new attribute is normal |
| 45 | * if exit-alt-char-set exists |
| 46 | * emit it |
| 47 | * emit exit-attribute-mode |
| 48 | * else if set-attributes exists |
| 49 | * use it to set exactly what you want |
| 50 | * else |
| 51 | * if exit-attribute-mode exists |
| 52 | * turn off everything |
| 53 | * else |
| 54 | * turn off those which can be turned off and aren't in |
| 55 | * newmode. |
| 56 | * turn on each mode which should be on and isn't, one by one |
| 57 | * |
| 58 | * NOTE that this algorithm won't achieve the desired mix of attributes |
| 59 | * in some cases, but those are probably just those cases in which it is |
| 60 | * actually impossible, anyway, so... |
| 61 | * |
| 62 | * NOTE that we cannot assume that there's no interaction between color |
| 63 | * and other attribute resets. So each time we reset color (or other |
| 64 | * attributes) we'll have to be prepared to restore the other. |
| 65 | */ |
| 66 | |
| 67 | #include <curses.priv.h> |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 68 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 69 | #ifndef CUR |
| 70 | #define CUR SP_TERMTYPE |
| 71 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 72 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 73 | MODULE_ID("$Id: lib_vidattr.c,v 1.79 2023/04/28 20:59:26 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 74 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 75 | #define doPut(mode) \ |
| 76 | TPUTS_TRACE(#mode); \ |
| 77 | NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx mode, 1, outc) |
| 78 | |
| 79 | #define TurnOn(mask, mode) \ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 80 | if ((turn_on & mask) && mode) { \ |
| 81 | TPUTS_TRACE(#mode); \ |
| 82 | NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx mode, 1, outc); \ |
| 83 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 84 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 85 | #define TurnOff(mask, mode) \ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 86 | if ((turn_off & mask) && mode) { \ |
| 87 | TPUTS_TRACE(#mode); \ |
| 88 | NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx mode, 1, outc); \ |
| 89 | turn_off &= ~mask; \ |
| 90 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 91 | |
| 92 | /* if there is no current screen, assume we *can* do color */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 93 | #define SetColorsIf(why, old_attr) \ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 94 | if (can_color && (why)) { \ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 95 | int old_pair = PairNumber(old_attr); \ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 96 | TR(TRACE_ATTRS, ("old pair = %d -- new pair = %d", old_pair, pair)); \ |
| 97 | if ((pair != old_pair) \ |
| 98 | || (fix_pair0 && (pair == 0)) \ |
| 99 | || (reverse ^ ((old_attr & A_REVERSE) != 0))) { \ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 100 | NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_ARGx \ |
| 101 | (short) old_pair, \ |
| 102 | (short) pair, \ |
| 103 | reverse, outc); \ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 104 | } \ |
| 105 | } |
| 106 | |
| 107 | #define PreviousAttr _nc_prescreen.previous_attr |
| 108 | |
| 109 | NCURSES_EXPORT(int) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 110 | NCURSES_SP_NAME(vidputs) (NCURSES_SP_DCLx |
| 111 | chtype newmode, |
| 112 | NCURSES_SP_OUTC outc) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 113 | { |
| 114 | attr_t turn_on, turn_off; |
| 115 | int pair; |
| 116 | bool reverse = FALSE; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 117 | bool can_color = (SP_PARM == 0 || SP_PARM->_coloron); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 118 | #if NCURSES_EXT_FUNCS |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 119 | bool fix_pair0 = (SP_PARM != 0 && SP_PARM->_coloron && !SP_PARM->_default_color); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 120 | #else |
| 121 | #define fix_pair0 FALSE |
| 122 | #endif |
| 123 | |
| 124 | newmode &= A_ATTRIBUTES; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 125 | |
| 126 | T((T_CALLED("vidputs(%p,%s)"), (void *) SP_PARM, _traceattr(newmode))); |
| 127 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 128 | if (!IsValidTIScreen(SP_PARM)) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 129 | returnCode(ERR); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 130 | |
| 131 | /* this allows us to go on whether or not newterm() has been called */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 132 | if (SP_PARM) |
| 133 | PreviousAttr = AttrOf(SCREEN_ATTRS(SP_PARM)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 134 | |
| 135 | TR(TRACE_ATTRS, ("previous attribute was %s", _traceattr(PreviousAttr))); |
| 136 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 137 | if ((SP_PARM != 0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 138 | && (magic_cookie_glitch > 0)) { |
| 139 | #if USE_XMC_SUPPORT |
| 140 | static const chtype table[] = |
| 141 | { |
| 142 | A_STANDOUT, |
| 143 | A_UNDERLINE, |
| 144 | A_REVERSE, |
| 145 | A_BLINK, |
| 146 | A_DIM, |
| 147 | A_BOLD, |
| 148 | A_INVIS, |
| 149 | A_PROTECT, |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 150 | #if USE_ITALIC |
| 151 | A_ITALIC, |
| 152 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 153 | }; |
| 154 | unsigned n; |
| 155 | int used = 0; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 156 | #ifdef max_attributes /* not in U/Win */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 157 | int limit = (max_attributes <= 0) ? 1 : max_attributes; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 158 | #else |
| 159 | int limit = 1; |
| 160 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 161 | chtype retain = 0; |
| 162 | |
| 163 | /* |
| 164 | * Limit the number of attribute bits set in the newmode according to |
| 165 | * the terminfo max_attributes value. |
| 166 | */ |
| 167 | for (n = 0; n < SIZEOF(table); ++n) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 168 | if ((table[n] & SP_PARM->_ok_attributes) == 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 169 | newmode &= ~table[n]; |
| 170 | } else if ((table[n] & newmode) != 0) { |
| 171 | if (used++ >= limit) { |
| 172 | newmode &= ~table[n]; |
| 173 | if (newmode == retain) |
| 174 | break; |
| 175 | } else { |
| 176 | retain = newmode; |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | #else |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 181 | newmode &= ~(SP_PARM->_xmc_suppress); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 182 | #endif |
| 183 | TR(TRACE_ATTRS, ("suppressed attribute is %s", _traceattr(newmode))); |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * If we have a terminal that cannot combine color with video |
| 188 | * attributes, use the colors in preference. |
| 189 | */ |
| 190 | if (((newmode & A_COLOR) != 0 |
| 191 | || fix_pair0) |
| 192 | && (no_color_video > 0)) { |
| 193 | /* |
| 194 | * If we had chosen the A_xxx definitions to correspond to the |
| 195 | * no_color_video mask, we could simply shift it up and mask off the |
| 196 | * attributes. But we did not (actually copied Solaris' definitions). |
| 197 | * However, this is still simpler/faster than a lookup table. |
| 198 | * |
| 199 | * The 63 corresponds to A_STANDOUT, A_UNDERLINE, A_REVERSE, A_BLINK, |
| 200 | * A_DIM, A_BOLD which are 1:1 with no_color_video. The bits that |
| 201 | * correspond to A_INVIS, A_PROTECT (192) must be shifted up 1 and |
| 202 | * A_ALTCHARSET (256) down 2 to line up. We use the NCURSES_BITS |
| 203 | * macro so this will work properly for the wide-character layout. |
| 204 | */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 205 | unsigned value = (unsigned) no_color_video; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 206 | attr_t mask = NCURSES_BITS((value & 63) |
| 207 | | ((value & 192) << 1) |
| 208 | | ((value & 256) >> 2), 8); |
| 209 | |
| 210 | if ((mask & A_REVERSE) != 0 |
| 211 | && (newmode & A_REVERSE) != 0) { |
| 212 | reverse = TRUE; |
| 213 | mask &= ~A_REVERSE; |
| 214 | } |
| 215 | newmode &= ~mask; |
| 216 | } |
| 217 | |
| 218 | if (newmode == PreviousAttr) |
| 219 | returnCode(OK); |
| 220 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 221 | pair = PairNumber(newmode); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 222 | |
| 223 | if (reverse) { |
| 224 | newmode &= ~A_REVERSE; |
| 225 | } |
| 226 | |
| 227 | turn_off = (~newmode & PreviousAttr) & ALL_BUT_COLOR; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 228 | turn_on = (newmode & ~(PreviousAttr & TPARM_ATTR)) & ALL_BUT_COLOR; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 229 | |
| 230 | SetColorsIf(((pair == 0) && !fix_pair0), PreviousAttr); |
| 231 | |
| 232 | if (newmode == A_NORMAL) { |
| 233 | if ((PreviousAttr & A_ALTCHARSET) && exit_alt_charset_mode) { |
| 234 | doPut(exit_alt_charset_mode); |
| 235 | PreviousAttr &= ~A_ALTCHARSET; |
| 236 | } |
| 237 | if (PreviousAttr) { |
| 238 | if (exit_attribute_mode) { |
| 239 | doPut(exit_attribute_mode); |
| 240 | } else { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 241 | if (!SP_PARM || SP_PARM->_use_rmul) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 242 | TurnOff(A_UNDERLINE, exit_underline_mode); |
| 243 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 244 | if (!SP_PARM || SP_PARM->_use_rmso) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 245 | TurnOff(A_STANDOUT, exit_standout_mode); |
| 246 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 247 | #if USE_ITALIC |
| 248 | if (!SP_PARM || SP_PARM->_use_ritm) { |
| 249 | TurnOff(A_ITALIC, exit_italics_mode); |
| 250 | } |
| 251 | #endif |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 252 | (void) turn_off; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 253 | } |
| 254 | PreviousAttr &= ALL_BUT_COLOR; |
| 255 | } |
| 256 | |
| 257 | SetColorsIf((pair != 0) || fix_pair0, PreviousAttr); |
| 258 | } else if (set_attributes) { |
| 259 | if (turn_on || turn_off) { |
| 260 | TPUTS_TRACE("set_attributes"); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 261 | NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 262 | TIPARM_9(set_attributes, |
| 263 | (newmode & A_STANDOUT) != 0, |
| 264 | (newmode & A_UNDERLINE) != 0, |
| 265 | (newmode & A_REVERSE) != 0, |
| 266 | (newmode & A_BLINK) != 0, |
| 267 | (newmode & A_DIM) != 0, |
| 268 | (newmode & A_BOLD) != 0, |
| 269 | (newmode & A_INVIS) != 0, |
| 270 | (newmode & A_PROTECT) != 0, |
| 271 | (newmode & A_ALTCHARSET) != 0), |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 272 | 1, outc); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 273 | PreviousAttr &= ALL_BUT_COLOR; |
| 274 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 275 | #if USE_ITALIC |
| 276 | if (!SP_PARM || SP_PARM->_use_ritm) { |
| 277 | if (turn_on & A_ITALIC) { |
| 278 | TurnOn(A_ITALIC, enter_italics_mode); |
| 279 | } else if (turn_off & A_ITALIC) { |
| 280 | TurnOff(A_ITALIC, exit_italics_mode); |
| 281 | } |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 282 | (void) turn_off; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 283 | } |
| 284 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 285 | SetColorsIf((pair != 0) || fix_pair0, PreviousAttr); |
| 286 | } else { |
| 287 | |
| 288 | TR(TRACE_ATTRS, ("turning %s off", _traceattr(turn_off))); |
| 289 | |
| 290 | TurnOff(A_ALTCHARSET, exit_alt_charset_mode); |
| 291 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 292 | if (!SP_PARM || SP_PARM->_use_rmul) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 293 | TurnOff(A_UNDERLINE, exit_underline_mode); |
| 294 | } |
| 295 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 296 | if (!SP_PARM || SP_PARM->_use_rmso) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 297 | TurnOff(A_STANDOUT, exit_standout_mode); |
| 298 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 299 | #if USE_ITALIC |
| 300 | if (!SP_PARM || SP_PARM->_use_ritm) { |
| 301 | TurnOff(A_ITALIC, exit_italics_mode); |
| 302 | } |
| 303 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 304 | if (turn_off && exit_attribute_mode) { |
| 305 | doPut(exit_attribute_mode); |
| 306 | turn_on |= (newmode & ALL_BUT_COLOR); |
| 307 | PreviousAttr &= ALL_BUT_COLOR; |
| 308 | } |
| 309 | SetColorsIf((pair != 0) || fix_pair0, PreviousAttr); |
| 310 | |
| 311 | TR(TRACE_ATTRS, ("turning %s on", _traceattr(turn_on))); |
| 312 | /* *INDENT-OFF* */ |
| 313 | TurnOn(A_ALTCHARSET, enter_alt_charset_mode); |
| 314 | TurnOn(A_BLINK, enter_blink_mode); |
| 315 | TurnOn(A_BOLD, enter_bold_mode); |
| 316 | TurnOn(A_DIM, enter_dim_mode); |
| 317 | TurnOn(A_REVERSE, enter_reverse_mode); |
| 318 | TurnOn(A_STANDOUT, enter_standout_mode); |
| 319 | TurnOn(A_PROTECT, enter_protected_mode); |
| 320 | TurnOn(A_INVIS, enter_secure_mode); |
| 321 | TurnOn(A_UNDERLINE, enter_underline_mode); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 322 | #if USE_ITALIC |
| 323 | TurnOn(A_ITALIC, enter_italics_mode); |
| 324 | #endif |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 325 | #if USE_WIDEC_SUPPORT && defined(enter_horizontal_hl_mode) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 326 | TurnOn(A_HORIZONTAL, enter_horizontal_hl_mode); |
| 327 | TurnOn(A_LEFT, enter_left_hl_mode); |
| 328 | TurnOn(A_LOW, enter_low_hl_mode); |
| 329 | TurnOn(A_RIGHT, enter_right_hl_mode); |
| 330 | TurnOn(A_TOP, enter_top_hl_mode); |
| 331 | TurnOn(A_VERTICAL, enter_vertical_hl_mode); |
| 332 | #endif |
| 333 | /* *INDENT-ON* */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | if (reverse) |
| 337 | newmode |= A_REVERSE; |
| 338 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 339 | if (SP_PARM) |
| 340 | SetAttr(SCREEN_ATTRS(SP_PARM), newmode); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 341 | else |
| 342 | PreviousAttr = newmode; |
| 343 | |
| 344 | returnCode(OK); |
| 345 | } |
| 346 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 347 | #if NCURSES_SP_FUNCS |
| 348 | NCURSES_EXPORT(int) |
| 349 | vidputs(chtype newmode, NCURSES_OUTC outc) |
| 350 | { |
| 351 | SetSafeOutcWrapper(outc); |
| 352 | return NCURSES_SP_NAME(vidputs) (CURRENT_SCREEN, |
| 353 | newmode, |
| 354 | _nc_outc_wrapper); |
| 355 | } |
| 356 | #endif |
| 357 | |
| 358 | NCURSES_EXPORT(int) |
| 359 | NCURSES_SP_NAME(vidattr) (NCURSES_SP_DCLx chtype newmode) |
| 360 | { |
| 361 | T((T_CALLED("vidattr(%p,%s)"), (void *) SP_PARM, _traceattr(newmode))); |
| 362 | returnCode(NCURSES_SP_NAME(vidputs) (NCURSES_SP_ARGx |
| 363 | newmode, |
| 364 | NCURSES_SP_NAME(_nc_putchar))); |
| 365 | } |
| 366 | |
| 367 | #if NCURSES_SP_FUNCS |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 368 | NCURSES_EXPORT(int) |
| 369 | vidattr(chtype newmode) |
| 370 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 371 | return NCURSES_SP_NAME(vidattr) (CURRENT_SCREEN, newmode); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 372 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 373 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 374 | |
| 375 | NCURSES_EXPORT(chtype) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 376 | NCURSES_SP_NAME(termattrs) (NCURSES_SP_DCL0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 377 | { |
| 378 | chtype attrs = A_NORMAL; |
| 379 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 380 | T((T_CALLED("termattrs(%p)"), (void *) SP_PARM)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 381 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 382 | if (HasTerminal(SP_PARM)) { |
| 383 | #ifdef USE_TERM_DRIVER |
| 384 | attrs = CallDriver(SP_PARM, td_conattr); |
| 385 | #else /* ! USE_TERM_DRIVER */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 386 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 387 | if (enter_alt_charset_mode) |
| 388 | attrs |= A_ALTCHARSET; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 389 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 390 | if (enter_blink_mode) |
| 391 | attrs |= A_BLINK; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 392 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 393 | if (enter_bold_mode) |
| 394 | attrs |= A_BOLD; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 395 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 396 | if (enter_dim_mode) |
| 397 | attrs |= A_DIM; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 398 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 399 | if (enter_reverse_mode) |
| 400 | attrs |= A_REVERSE; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 401 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 402 | if (enter_standout_mode) |
| 403 | attrs |= A_STANDOUT; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 404 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 405 | if (enter_protected_mode) |
| 406 | attrs |= A_PROTECT; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 407 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 408 | if (enter_secure_mode) |
| 409 | attrs |= A_INVIS; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 410 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 411 | if (enter_underline_mode) |
| 412 | attrs |= A_UNDERLINE; |
| 413 | |
| 414 | if (SP_PARM->_coloron) |
| 415 | attrs |= A_COLOR; |
| 416 | |
| 417 | #if USE_ITALIC |
| 418 | if (enter_italics_mode) |
| 419 | attrs |= A_ITALIC; |
| 420 | #endif |
| 421 | |
| 422 | #endif /* USE_TERM_DRIVER */ |
| 423 | } |
| 424 | returnChtype(attrs); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 425 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 426 | |
| 427 | #if NCURSES_SP_FUNCS |
| 428 | NCURSES_EXPORT(chtype) |
| 429 | termattrs(void) |
| 430 | { |
| 431 | return NCURSES_SP_NAME(termattrs) (CURRENT_SCREEN); |
| 432 | } |
| 433 | #endif |