1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1997 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 32*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 33*7c478bd9Sstevel@tonic-gate * All Rights Reserved 34*7c478bd9Sstevel@tonic-gate * 35*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 36*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 37*7c478bd9Sstevel@tonic-gate * contributors. 38*7c478bd9Sstevel@tonic-gate */ 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/ 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 45*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 46*7c478bd9Sstevel@tonic-gate #include "curses_inc.h" 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate #ifdef PC6300PLUS 49*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 50*7c478bd9Sstevel@tonic-gate #include <sys/console.h> 51*7c478bd9Sstevel@tonic-gate #endif 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate #define NUM_OF_SPECIFIC_TURN_OFFS 3 54*7c478bd9Sstevel@tonic-gate extern chtype bit_attributes[]; 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate int Oldcolors[] = { COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN, 57*7c478bd9Sstevel@tonic-gate COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE }; 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate void 60*7c478bd9Sstevel@tonic-gate vidupdate(chtype newmode, chtype oldmode, int (*outc)(char)) 61*7c478bd9Sstevel@tonic-gate { 62*7c478bd9Sstevel@tonic-gate bool color_terminal = (cur_term->_pairs_tbl) ? TRUE : FALSE; 63*7c478bd9Sstevel@tonic-gate chtype oldvideo = (oldmode & A_ATTRIBUTES) & ~A_COLOR; 64*7c478bd9Sstevel@tonic-gate chtype newvideo = (newmode & A_ATTRIBUTES) & ~A_COLOR; 65*7c478bd9Sstevel@tonic-gate int _change_video(chtype, chtype, int (*)(char)); 66*7c478bd9Sstevel@tonic-gate void _change_color(short, int (*)(char)); 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate /* if colors are used, extract the color related information from */ 69*7c478bd9Sstevel@tonic-gate /* the old and new modes and then erase color-pairs fields in */ 70*7c478bd9Sstevel@tonic-gate /* both arguments. */ 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate if (color_terminal) { 73*7c478bd9Sstevel@tonic-gate /* LINTED */ 74*7c478bd9Sstevel@tonic-gate short oldcolor = (short) PAIR_NUMBER(oldmode & A_COLOR); 75*7c478bd9Sstevel@tonic-gate /* LINTED */ 76*7c478bd9Sstevel@tonic-gate short newcolor = (short) PAIR_NUMBER(newmode & A_COLOR); 77*7c478bd9Sstevel@tonic-gate chtype turn_off = A_COLOR; 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate /* erase information about video attributes that could not */ 80*7c478bd9Sstevel@tonic-gate /* have been used with colors */ 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate if (oldcolor == 0) 83*7c478bd9Sstevel@tonic-gate oldvideo &= ~turn_off; 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate if (no_color_video != -1) 86*7c478bd9Sstevel@tonic-gate turn_off |= (((chtype) no_color_video) << 16); 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate if (oldcolor != 0) 89*7c478bd9Sstevel@tonic-gate oldvideo &= ~turn_off; 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate /* if the new mode contains color information, then first */ 93*7c478bd9Sstevel@tonic-gate /* deal with video attributes, and then with colors. This */ 94*7c478bd9Sstevel@tonic-gate /* way color information will overwrite video information. */ 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate if (newcolor != 0) { 97*7c478bd9Sstevel@tonic-gate /* erase information about video attributes that */ 98*7c478bd9Sstevel@tonic-gate /* should not be used with colors */ 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate newvideo &= ~turn_off; 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate /* if the new and the old video modes became */ 103*7c478bd9Sstevel@tonic-gate /* the same don't bother with them */ 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate if (newvideo != oldvideo) { 106*7c478bd9Sstevel@tonic-gate if ((_change_video(newvideo, oldvideo, 107*7c478bd9Sstevel@tonic-gate outc)) == -1) { 108*7c478bd9Sstevel@tonic-gate _Color_pair *cur_pair = 109*7c478bd9Sstevel@tonic-gate &cur_term->_cur_pair; 110*7c478bd9Sstevel@tonic-gate oldcolor = -1; 111*7c478bd9Sstevel@tonic-gate cur_pair->background = 112*7c478bd9Sstevel@tonic-gate cur_pair->foreground = -1; 113*7c478bd9Sstevel@tonic-gate } 114*7c478bd9Sstevel@tonic-gate } 115*7c478bd9Sstevel@tonic-gate if (newcolor != oldcolor) 116*7c478bd9Sstevel@tonic-gate _change_color(newcolor, outc); 117*7c478bd9Sstevel@tonic-gate } 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate /* new mode doesn't contain any color information. Deal */ 120*7c478bd9Sstevel@tonic-gate /* with colors first (possibly turning of the colors that */ 121*7c478bd9Sstevel@tonic-gate /* were contained in the oldmode, and then deal with video. */ 122*7c478bd9Sstevel@tonic-gate /* This way video attributes will overwrite colors. */ 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate else { 125*7c478bd9Sstevel@tonic-gate if (newcolor != oldcolor) 126*7c478bd9Sstevel@tonic-gate _change_color(newcolor, outc); 127*7c478bd9Sstevel@tonic-gate if (newvideo != oldvideo) 128*7c478bd9Sstevel@tonic-gate (void) _change_video(newvideo, oldvideo, outc); 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate } else 131*7c478bd9Sstevel@tonic-gate (void) _change_video(newvideo, oldvideo, outc); 132*7c478bd9Sstevel@tonic-gate } 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate int 136*7c478bd9Sstevel@tonic-gate _change_video(chtype newmode, chtype oldmode, int (*outc)(char)) 137*7c478bd9Sstevel@tonic-gate { 138*7c478bd9Sstevel@tonic-gate int rc = 0; 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate /* If you have set_attributes let the terminfo writer */ 141*7c478bd9Sstevel@tonic-gate /* worry about it. */ 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate if (!set_attributes) { 144*7c478bd9Sstevel@tonic-gate /* 145*7c478bd9Sstevel@tonic-gate * The trick is that we want to pre-process the new and oldmode 146*7c478bd9Sstevel@tonic-gate * so that we now know what they will really translate to on 147*7c478bd9Sstevel@tonic-gate * the physical screen. 148*7c478bd9Sstevel@tonic-gate * In the case where some attributes are being faked 149*7c478bd9Sstevel@tonic-gate * we get rid of the attributes being asked for and just have 150*7c478bd9Sstevel@tonic-gate * STANDOUT mode set. Therefore, if STANDOUT and UNDERLINE were 151*7c478bd9Sstevel@tonic-gate * on the screen but UNDERLINE was being faked to STANDOUT; and 152*7c478bd9Sstevel@tonic-gate * the new mode is just UNDERLINE, we will get rid of any faked 153*7c478bd9Sstevel@tonic-gate * modes and be left with and oldmode of STANDOUT and a new mode 154*7c478bd9Sstevel@tonic-gate * of STANDOUT, in which case the check for newmode and oldmode 155*7c478bd9Sstevel@tonic-gate * being equal will be true. 156*7c478bd9Sstevel@tonic-gate * 157*7c478bd9Sstevel@tonic-gate * 158*7c478bd9Sstevel@tonic-gate * This test is similar to the concept explained above. 159*7c478bd9Sstevel@tonic-gate * counter is the maximum attributes allowed on a terminal. 160*7c478bd9Sstevel@tonic-gate * For instance, on an hp/tvi950 without set_attributes 161*7c478bd9Sstevel@tonic-gate * the last video sequence sent will be the one the terminal 162*7c478bd9Sstevel@tonic-gate * will be in (on that spot). Therefore, in setupterm.c 163*7c478bd9Sstevel@tonic-gate * if ceol_standout_glitch or magic_cookie_glitch is set 164*7c478bd9Sstevel@tonic-gate * max_attributes is set to 1. This is because on those terminals 165*7c478bd9Sstevel@tonic-gate * only one attribute can be on at once. So, we pre-process the 166*7c478bd9Sstevel@tonic-gate * oldmode and the newmode and only leave the bits that are 167*7c478bd9Sstevel@tonic-gate * significant. In other words, if on an hp you ask for STANDOUT 168*7c478bd9Sstevel@tonic-gate * and UNDERLINE it will become only STANDOUT since that is the 169*7c478bd9Sstevel@tonic-gate * first bit that is looked at. If then the user goes from 170*7c478bd9Sstevel@tonic-gate * STANDOUT and UNDERLINE to STANDOUT and REVERSE the oldmode will 171*7c478bd9Sstevel@tonic-gate * become STANDOUT and the newmode will become STANDOUT. 172*7c478bd9Sstevel@tonic-gate * 173*7c478bd9Sstevel@tonic-gate * This also helps the code below in that on a hp or tvi950 only 174*7c478bd9Sstevel@tonic-gate * one bit will ever be set so that no code has to be added to 175*7c478bd9Sstevel@tonic-gate * cut out early in case two attributes were asked for. 176*7c478bd9Sstevel@tonic-gate */ 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate chtype check_faked, modes[2]; 179*7c478bd9Sstevel@tonic-gate int counter = max_attributes, i, j, tempmode; 180*7c478bd9Sstevel@tonic-gate int k = (cur_term->sgr_mode == oldmode) ? 1 : 2; 181*7c478bd9Sstevel@tonic-gate 182*7c478bd9Sstevel@tonic-gate modes[0] = newmode; 183*7c478bd9Sstevel@tonic-gate modes[1] = oldmode; 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate while (k-- > 0) { 186*7c478bd9Sstevel@tonic-gate if ((check_faked = (modes[k] & 187*7c478bd9Sstevel@tonic-gate cur_term->sgr_faked)) != A_NORMAL) { 188*7c478bd9Sstevel@tonic-gate modes[k] &= ~check_faked; 189*7c478bd9Sstevel@tonic-gate modes[k] |= A_STANDOUT; 190*7c478bd9Sstevel@tonic-gate } 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate if ((j = counter) >= 0) { 193*7c478bd9Sstevel@tonic-gate tempmode = A_NORMAL; 194*7c478bd9Sstevel@tonic-gate if (j > 0) { 195*7c478bd9Sstevel@tonic-gate for (i = 0; i < NUM_ATTRIBUTES; i++) { 196*7c478bd9Sstevel@tonic-gate if (modes[k] & 197*7c478bd9Sstevel@tonic-gate bit_attributes[i]) { 198*7c478bd9Sstevel@tonic-gate tempmode |= 199*7c478bd9Sstevel@tonic-gate bit_attributes[i]; 200*7c478bd9Sstevel@tonic-gate if (--j == 0) 201*7c478bd9Sstevel@tonic-gate break; 202*7c478bd9Sstevel@tonic-gate } 203*7c478bd9Sstevel@tonic-gate } 204*7c478bd9Sstevel@tonic-gate } 205*7c478bd9Sstevel@tonic-gate modes[k] = tempmode; 206*7c478bd9Sstevel@tonic-gate } 207*7c478bd9Sstevel@tonic-gate } 208*7c478bd9Sstevel@tonic-gate newmode = modes[0]; 209*7c478bd9Sstevel@tonic-gate oldmode = modes[1]; 210*7c478bd9Sstevel@tonic-gate } 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate if (newmode == oldmode) 213*7c478bd9Sstevel@tonic-gate return (rc); 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 216*7c478bd9Sstevel@tonic-gate if (outf) 217*7c478bd9Sstevel@tonic-gate fprintf(outf, "vidupdate oldmode=%o, newmode=%o\n", 218*7c478bd9Sstevel@tonic-gate oldmode, newmode); 219*7c478bd9Sstevel@tonic-gate #endif 220*7c478bd9Sstevel@tonic-gate 221*7c478bd9Sstevel@tonic-gate if (set_attributes) { 222*7c478bd9Sstevel@tonic-gate (void) tputs(tparm(set_attributes, 223*7c478bd9Sstevel@tonic-gate newmode & A_STANDOUT, 224*7c478bd9Sstevel@tonic-gate newmode & A_UNDERLINE, 225*7c478bd9Sstevel@tonic-gate newmode & A_REVERSE, 226*7c478bd9Sstevel@tonic-gate newmode & A_BLINK, 227*7c478bd9Sstevel@tonic-gate newmode & A_DIM, 228*7c478bd9Sstevel@tonic-gate newmode & A_BOLD, 229*7c478bd9Sstevel@tonic-gate newmode & A_INVIS, 230*7c478bd9Sstevel@tonic-gate newmode & A_PROTECT, 231*7c478bd9Sstevel@tonic-gate newmode & A_ALTCHARSET), 232*7c478bd9Sstevel@tonic-gate 1, outc); 233*7c478bd9Sstevel@tonic-gate rc = -1; 234*7c478bd9Sstevel@tonic-gate } else { 235*7c478bd9Sstevel@tonic-gate chtype turn_on, turn_off; 236*7c478bd9Sstevel@tonic-gate int i; 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate /* 239*7c478bd9Sstevel@tonic-gate * If we are going to turn something on anyway and we are 240*7c478bd9Sstevel@tonic-gate * on a glitchy terminal, don't bother turning it off 241*7c478bd9Sstevel@tonic-gate * since by turning something on you turn everything else off. 242*7c478bd9Sstevel@tonic-gate */ 243*7c478bd9Sstevel@tonic-gate 244*7c478bd9Sstevel@tonic-gate if ((ceol_standout_glitch || magic_cookie_glitch >= 0) && 245*7c478bd9Sstevel@tonic-gate ((turn_on = ((oldmode ^ newmode) & newmode)) != 246*7c478bd9Sstevel@tonic-gate A_NORMAL)) { 247*7c478bd9Sstevel@tonic-gate goto turn_on_code; 248*7c478bd9Sstevel@tonic-gate } 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate if ((turn_off = (oldmode & newmode) ^ oldmode) != A_NORMAL) { 251*7c478bd9Sstevel@tonic-gate /* 252*7c478bd9Sstevel@tonic-gate * Check for things to turn off. 253*7c478bd9Sstevel@tonic-gate * First see if we are going to turn off something 254*7c478bd9Sstevel@tonic-gate * that doesn't have a specific turn off capability. 255*7c478bd9Sstevel@tonic-gate * 256*7c478bd9Sstevel@tonic-gate * Then check to see if, even though there may be a specific 257*7c478bd9Sstevel@tonic-gate * turn off sequence, this terminal doesn't have one or 258*7c478bd9Sstevel@tonic-gate * the turn off sequence also turns off something else. 259*7c478bd9Sstevel@tonic-gate */ 260*7c478bd9Sstevel@tonic-gate if ((turn_off & ~(A_ALTCHARSET | A_STANDOUT | A_UNDERLINE)) || 261*7c478bd9Sstevel@tonic-gate (turn_off != (turn_off & cur_term->check_turn_off))) { 262*7c478bd9Sstevel@tonic-gate (void) tputs(tparm_p0(exit_attribute_mode), 1, outc); 263*7c478bd9Sstevel@tonic-gate rc = -1; 264*7c478bd9Sstevel@tonic-gate oldmode = A_NORMAL; 265*7c478bd9Sstevel@tonic-gate } else { 266*7c478bd9Sstevel@tonic-gate for (i = 0; i < NUM_OF_SPECIFIC_TURN_OFFS; i++) { 267*7c478bd9Sstevel@tonic-gate if (turn_off & bit_attributes[i]) { 268*7c478bd9Sstevel@tonic-gate (void) tputs(tparm_p0 269*7c478bd9Sstevel@tonic-gate (cur_term->turn_off_seq[i]), 270*7c478bd9Sstevel@tonic-gate 1, outc); 271*7c478bd9Sstevel@tonic-gate oldmode &= ~bit_attributes[i]; 272*7c478bd9Sstevel@tonic-gate rc = -1; 273*7c478bd9Sstevel@tonic-gate } 274*7c478bd9Sstevel@tonic-gate } 275*7c478bd9Sstevel@tonic-gate } 276*7c478bd9Sstevel@tonic-gate } 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate if ((turn_on = ((oldmode ^ newmode) & newmode)) != A_NORMAL) { 279*7c478bd9Sstevel@tonic-gate turn_on_code: 280*7c478bd9Sstevel@tonic-gate 281*7c478bd9Sstevel@tonic-gate /* Check for modes to turn on. */ 282*7c478bd9Sstevel@tonic-gate 283*7c478bd9Sstevel@tonic-gate for (i = 0; i < NUM_ATTRIBUTES; i++) 284*7c478bd9Sstevel@tonic-gate if (turn_on & bit_attributes[i]) { 285*7c478bd9Sstevel@tonic-gate (void) tputs(tparm_p0(cur_term->turn_on_seq[i]), 286*7c478bd9Sstevel@tonic-gate 1, outc); 287*7c478bd9Sstevel@tonic-gate rc = -1; 288*7c478bd9Sstevel@tonic-gate /* 289*7c478bd9Sstevel@tonic-gate * Keep turning off the bit(s) that we just 290*7c478bd9Sstevel@tonic-gate * sent to the screen. As soon as turn_on 291*7c478bd9Sstevel@tonic-gate * reaches A_NORMAL we don't have to turn 292*7c478bd9Sstevel@tonic-gate * anything else on and we can 293*7c478bd9Sstevel@tonic-gate * break out of the loop. 294*7c478bd9Sstevel@tonic-gate */ 295*7c478bd9Sstevel@tonic-gate if ((turn_on &= ~bit_attributes[i]) == 296*7c478bd9Sstevel@tonic-gate A_NORMAL) 297*7c478bd9Sstevel@tonic-gate break; 298*7c478bd9Sstevel@tonic-gate } 299*7c478bd9Sstevel@tonic-gate } 300*7c478bd9Sstevel@tonic-gate 301*7c478bd9Sstevel@tonic-gate if (magic_cookie_glitch > 0) 302*7c478bd9Sstevel@tonic-gate (void) tputs(cursor_left, 1, outc); 303*7c478bd9Sstevel@tonic-gate } 304*7c478bd9Sstevel@tonic-gate cur_term->sgr_mode = newmode; 305*7c478bd9Sstevel@tonic-gate return (rc); 306*7c478bd9Sstevel@tonic-gate } 307*7c478bd9Sstevel@tonic-gate 308*7c478bd9Sstevel@tonic-gate 309*7c478bd9Sstevel@tonic-gate void 310*7c478bd9Sstevel@tonic-gate _change_color(short newcolor, int (*outc)(char)) 311*7c478bd9Sstevel@tonic-gate { 312*7c478bd9Sstevel@tonic-gate #ifndef PC6300PLUS 313*7c478bd9Sstevel@tonic-gate { 314*7c478bd9Sstevel@tonic-gate _Color_pair *ptp = cur_term->_pairs_tbl; 315*7c478bd9Sstevel@tonic-gate /* pairs table pointer */ 316*7c478bd9Sstevel@tonic-gate _Color_pair *cur_pair = &cur_term->_cur_pair; 317*7c478bd9Sstevel@tonic-gate 318*7c478bd9Sstevel@tonic-gate /* MORE: we may have to change some stuff, depending on whether */ 319*7c478bd9Sstevel@tonic-gate /* HP terminals will be changing the background, or not */ 320*7c478bd9Sstevel@tonic-gate 321*7c478bd9Sstevel@tonic-gate if (newcolor == 0) { 322*7c478bd9Sstevel@tonic-gate if (orig_pair) 323*7c478bd9Sstevel@tonic-gate (void) tputs(tparm_p0(orig_pair), 1, outc); 324*7c478bd9Sstevel@tonic-gate if (set_a_background || set_a_foreground || 325*7c478bd9Sstevel@tonic-gate set_background || set_foreground) { 326*7c478bd9Sstevel@tonic-gate cur_pair->background = -1; 327*7c478bd9Sstevel@tonic-gate cur_pair->foreground = -1; 328*7c478bd9Sstevel@tonic-gate } 329*7c478bd9Sstevel@tonic-gate return; 330*7c478bd9Sstevel@tonic-gate } 331*7c478bd9Sstevel@tonic-gate 332*7c478bd9Sstevel@tonic-gate /* if we are on HP type terminal, just send an escape sequence */ 333*7c478bd9Sstevel@tonic-gate /* to use desired color pair (we could have done some optimization: */ 334*7c478bd9Sstevel@tonic-gate /* check if both the foreground and background of newcolor match */ 335*7c478bd9Sstevel@tonic-gate /* the ones of cur_term->_cur_pair. but that will happen only when */ 336*7c478bd9Sstevel@tonic-gate /* two color pairs are defined exacly the same, and probably not */ 337*7c478bd9Sstevel@tonic-gate /* worth the effort). */ 338*7c478bd9Sstevel@tonic-gate 339*7c478bd9Sstevel@tonic-gate if (set_color_pair) 340*7c478bd9Sstevel@tonic-gate (void) tputs(tparm_p1(set_color_pair, newcolor), 1, outc); 341*7c478bd9Sstevel@tonic-gate 342*7c478bd9Sstevel@tonic-gate /* on Tek model we can do some optimization. */ 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate else { 345*7c478bd9Sstevel@tonic-gate if (ptp[newcolor].background != cur_pair->background) { 346*7c478bd9Sstevel@tonic-gate if (set_a_background) 347*7c478bd9Sstevel@tonic-gate (void) tputs(tparm_p1(set_a_background, 348*7c478bd9Sstevel@tonic-gate ptp[newcolor].background), 1, outc); 349*7c478bd9Sstevel@tonic-gate else if (set_background) 350*7c478bd9Sstevel@tonic-gate (void) tputs(tparm_p1(set_background, 351*7c478bd9Sstevel@tonic-gate Oldcolors[ptp[newcolor].background]), 352*7c478bd9Sstevel@tonic-gate 1, outc); 353*7c478bd9Sstevel@tonic-gate cur_pair->background = ptp[newcolor].background; 354*7c478bd9Sstevel@tonic-gate } 355*7c478bd9Sstevel@tonic-gate if (ptp[newcolor].foreground != cur_pair->foreground) { 356*7c478bd9Sstevel@tonic-gate if (set_a_foreground) 357*7c478bd9Sstevel@tonic-gate (void) tputs(tparm_p1(set_a_foreground, 358*7c478bd9Sstevel@tonic-gate ptp[newcolor].foreground), 1, outc); 359*7c478bd9Sstevel@tonic-gate else if (set_foreground) 360*7c478bd9Sstevel@tonic-gate (void) tputs(tparm_p1(set_foreground, 361*7c478bd9Sstevel@tonic-gate Oldcolors[ptp[newcolor].foreground]), 362*7c478bd9Sstevel@tonic-gate 1, outc); 363*7c478bd9Sstevel@tonic-gate cur_pair->foreground = ptp[newcolor].foreground; 364*7c478bd9Sstevel@tonic-gate } 365*7c478bd9Sstevel@tonic-gate } 366*7c478bd9Sstevel@tonic-gate } 367*7c478bd9Sstevel@tonic-gate #else 368*7c478bd9Sstevel@tonic-gate { 369*7c478bd9Sstevel@tonic-gate /* the following code is for PC6300 PLUS: it uses BOLD terminfo */ 370*7c478bd9Sstevel@tonic-gate /* entry for turning on colors, and SGR0 for turning them off. */ 371*7c478bd9Sstevel@tonic-gate /* Every time a new color-pair is used, we are forced to do an */ 372*7c478bd9Sstevel@tonic-gate /* ioctl read, and the send 'enter_bold_mode' escape sequence. */ 373*7c478bd9Sstevel@tonic-gate /* This could be improved by using */ 374*7c478bd9Sstevel@tonic-gate /* DIM, UNDERLINE, and REVERSE in addition to BOLD */ 375*7c478bd9Sstevel@tonic-gate 376*7c478bd9Sstevel@tonic-gate struct console con; 377*7c478bd9Sstevel@tonic-gate _Color_pair *ptp = cur_term->_pairs_tbl; 378*7c478bd9Sstevel@tonic-gate /* pairs table pointer */ 379*7c478bd9Sstevel@tonic-gate back = ptp[newcolor].background; 380*7c478bd9Sstevel@tonic-gate fore = ptp[newcolor].foreground; 381*7c478bd9Sstevel@tonic-gate 382*7c478bd9Sstevel@tonic-gate (void) fflush(SP->term_file); 383*7c478bd9Sstevel@tonic-gate ioctl(cur_term->Filedes, CONIOGETDATA, &con); 384*7c478bd9Sstevel@tonic-gate #define BOLD 4 385*7c478bd9Sstevel@tonic-gate con.l[con.page].colors[BOLD] = 386*7c478bd9Sstevel@tonic-gate ((back + back + (fore > 5)) * 8 + fore) & 0177; 387*7c478bd9Sstevel@tonic-gate ioctl(cur_term->Filedes, CONIOSETDATA, &con); 388*7c478bd9Sstevel@tonic-gate (void) tputs(enter_bold_mode, 1, outc); 389*7c478bd9Sstevel@tonic-gate } 390*7c478bd9Sstevel@tonic-gate #endif 391*7c478bd9Sstevel@tonic-gate } 392