1 /* NetHack 3.6 termcap.c $NHDT-Date: 1447234979 2015/11/11 09:42:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.23 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed. See license for details. */
7 #if defined(TTY_GRAPHICS) && !defined(NO_TERMS)
12 #ifdef MICROPORT_286_BUG
13 #define Tgetstr(key) (tgetstr(key, tbuf))
15 #define Tgetstr(key) (tgetstr(key, &tbufptr))
16 #endif /* MICROPORT_286_BUG **/
18 static char *FDECL(s_atr2str, (int));
19 static char *FDECL(e_atr2str, (int));
21 void FDECL(cmov, (int, int));
22 void FDECL(nocmov, (int, int));
23 #if defined(TEXTCOLOR) && defined(TERMLIB)
24 #if !defined(UNIX) || !defined(TERMINFO)
26 static void FDECL(analyze_seq, (char *, int *, int *));
29 static void NDECL(init_hilite);
30 static void NDECL(kill_hilite);
33 /* (see tcap.h) -- nh_CM, nh_ND, nh_CD, nh_HI,nh_HE, nh_US,nh_UE, ul_hack */
34 struct tc_lcl_data tc_lcl_data = { 0, 0, 0, 0, 0, 0, 0, FALSE };
36 STATIC_VAR char *HO, *CL, *CE, *UP, *XD, *BC, *SO, *SE, *TI, *TE;
37 STATIC_VAR char *VS, *VE;
41 STATIC_VAR char *MB, *MH;
42 STATIC_VAR char *MD; /* may already be in use below */
46 boolean dynamic_HIHE = FALSE;
51 STATIC_OVL char PC = '\0';
52 STATIC_VAR char tbuf[512];
57 const char *hilites[CLR_MAX]; /* terminal escapes for the various colors */
59 char NEARDATA *hilites[CLR_MAX]; /* terminal escapes for the various colors */
63 static char *KS = (char *) 0, *KE = (char *) 0; /* keypad sequences */
64 static char nullstr[] = "";
66 #if defined(ASCIIGRAPH) && !defined(NO_TERMS)
67 extern boolean HE_resets_AS;
71 STATIC_VAR char tgotobuf[20];
73 #define tgoto(fmt, x, y) (Sprintf(tgotobuf, fmt, y + ' ', x + ' '), tgotobuf)
75 #define tgoto(fmt, x, y) (Sprintf(tgotobuf, fmt, y + 1, x + 1), tgotobuf)
85 register const char *term;
90 term = verify_termcap();
93 term = getenv("TERM");
95 #if defined(TOS) && defined(__GNUC__)
97 term = "builtin"; /* library has a default */
102 error("Can't get TERM.");
108 TI = VS = VE = TE = nullstr;
110 CE = "\033K"; /* the VT52 termcap */
112 nh_CM = "\033Y%c%c"; /* used with function tgoto() */
118 /* HI and HE will be updated in init_hilite if we're using color */
123 CL = "\033E"; /* last thing set */
131 if (CO < COLNO || LI < ROWNO + 3)
136 /* nh_CD = "\033[J"; */
137 CE = "\033[K"; /* the ANSI termcap */
139 nh_CM = "\033[%d;%dH";
141 nh_CM = "\033[%i%d;%dH";
146 #ifdef MICRO /* backspaces are non-destructive */
151 nh_HI = SO = "\033[1m";
154 TI = nh_HE = ME = SE = nh_UE = "\033[0m";
155 /* strictly, SE should be 2, and nh_UE should be 24,
156 but we can't trust all ANSI emulators to be
157 that complete. -3. */
162 TE = VS = VE = nullstr;
164 for (i = 0; i < CLR_MAX / 2; i++)
165 if (i != CLR_BLACK) {
166 hilites[i | BRIGHT] = (char *) alloc(sizeof("\033[1;3%dm"));
167 Sprintf(hilites[i | BRIGHT], "\033[1;3%dm", i);
171 hilites[CLR_BLUE] = hilites[CLR_BLUE | BRIGHT];
175 hilites[i] = (char *) alloc(sizeof("\033[0;3%dm"));
176 Sprintf(hilites[i], "\033[0;3%dm", i);
182 CL = "\033[2J"; /* last thing set */
186 #endif /* ANSI_DEFAULT */
189 tptr = (char *) alloc(1024);
192 if (!strncmp(term, "5620", 4))
193 flags.null = FALSE; /* this should be a termcap flag */
194 if (tgetent(tptr, term) < 1) {
196 (void) strncpy(buf, term,
197 (BUFSZ - 1) - (sizeof("Unknown terminal type: . ")));
198 buf[BUFSZ - 1] = '\0';
199 error("Unknown terminal type: %s.", term);
201 if ((pc = Tgetstr("pc")) != 0)
204 if (!(BC = Tgetstr("le"))) /* both termcap and terminfo use le */
206 error("Terminal must backspace.");
208 if (!(BC = Tgetstr("bc"))) { /* termcap also uses bc/bs */
211 error("Terminal must backspace.");
225 * LI and CO are set in ioctl.c via a TIOCGWINSZ if available. If
226 * the kernel has values for either we should use them rather than
227 * the values from TERMCAP ...
235 #if defined(TOS) && defined(__GNUC__)
236 if (!strcmp(term, "builtin")) {
243 if (!LI || !CO) /* if we don't override it */
248 if (CO < COLNO || LI < ROWNO + 3)
251 nh_ND = Tgetstr("nd");
253 error("NetHack can't have OS.");
258 /* It seems that xd is no longer supported, and we should use
259 a linefeed instead; unfortunately this requires resetting
260 CRMOD, and many output routines will have to be modified
261 slightly. Let's leave that till the next release. */
263 /* not: XD = Tgetstr("do"); */
264 if (!(nh_CM = Tgetstr("cm"))) {
266 error("NetHack needs CM or UP or HO.");
267 tty_raw_print("Playing NetHack on terminals without CM is suspect.");
272 nh_US = Tgetstr("us");
273 nh_UE = Tgetstr("ue");
274 SG = tgetnum("sg"); /* -1: not fnd; else # of spaces left by so */
275 if (!SO || !SE || (SG > 0))
276 SO = SE = nh_US = nh_UE = nullstr;
281 VS = Tgetstr("eA"); /* enable graphics */
283 KS = Tgetstr("ks"); /* keypad start (special mode) */
284 KE = Tgetstr("ke"); /* keypad end (ordinary mode [ie, digits]) */
285 MR = Tgetstr("mr"); /* reverse */
287 MB = Tgetstr("mb"); /* blink */
288 MD = Tgetstr("md"); /* boldface */
289 MH = Tgetstr("mh"); /* dim */
291 ME = Tgetstr("me"); /* turn off all attributes */
292 if (!ME || (SE == nullstr))
293 ME = SE; /* default to SE value */
295 /* Get rid of padding numbers for nh_HI and nh_HE. Hope they
296 * aren't really needed!!! nh_HI and nh_HE are outputted to the
297 * pager as a string - so how can you send it NULs???
300 for (i = 0; digit(SO[i]); ++i)
302 nh_HI = dupstr(&SO[i]);
303 for (i = 0; digit(ME[i]); ++i)
305 nh_HE = dupstr(&ME[i]);
310 nh_CD = Tgetstr("cd");
315 #if defined(TOS) && defined(__GNUC__)
316 if (!strcmp(term, "builtin") || !strcmp(term, "tw52")
317 || !strcmp(term, "st52")) {
326 if (!(CL = Tgetstr("cl"))) /* last thing set */
327 error("NetHack needs CL.");
328 if ((int) (tbufptr - tbuf) > (int) (sizeof tbuf))
329 error("TERMCAP entry too big...\n");
330 free((genericptr_t) tptr);
334 /* note: at present, this routine is not part of the formal window interface
336 /* deallocate resources prior to final termination */
340 /* we only attempt to clean up a few individual termcap variables */
346 free((genericptr_t) nh_HI), nh_HI = (char *) 0;
347 free((genericptr_t) nh_HE), nh_HE = (char *) 0;
348 dynamic_HIHE = FALSE;
355 tty_number_pad(state)
359 case -1: /* activate keypad mode (escape sequences) */
363 case 1: /* activate numeric mode for keypad (digits) */
367 case 0: /* don't need to do anything--leave terminal as-is */
374 extern void NDECL((*decgraphics_mode_callback)); /* defined in drawing.c */
375 static void NDECL(tty_decgraphics_termcap_fixup);
378 We call this routine whenever DECgraphics mode is enabled, even if it
379 has been previously set, in case the user manages to reset the fonts.
380 The actual termcap fixup only needs to be done once, but we can't
381 call xputs() from the option setting or graphics assigning routines,
382 so this is a convenient hook.
385 tty_decgraphics_termcap_fixup()
387 static char ctrlN[] = "\016";
388 static char ctrlO[] = "\017";
389 static char appMode[] = "\033=";
390 static char numMode[] = "\033>";
392 /* these values are missing from some termcaps */
394 AS = ctrlN; /* ^N (shift-out [graphics font]) */
396 AE = ctrlO; /* ^O (shift-in [regular font]) */
398 KS = appMode; /* ESC= (application keypad mode) */
400 KE = numMode; /* ESC> (numeric keypad mode) */
402 * Select the line-drawing character set as the alternate font.
403 * Do not select NA ASCII as the primary font since people may
404 * reasonably be using the UK character set.
406 if (SYMHANDLING(H_DEC))
412 #if defined(ASCIIGRAPH) && !defined(NO_TERMS)
413 /* some termcaps suffer from the bizarre notion that resetting
414 video attributes should also reset the chosen character set */
416 const char *nh_he = nh_HE, *ae = AE;
417 int he_limit, ae_length;
419 if (digit(*ae)) { /* skip over delay prefix, if any */
431 /* can't use nethack's case-insensitive strstri() here, and some old
432 systems don't have strstr(), so use brute force substring search */
433 ae_length = strlen(ae), he_limit = strlen(nh_he);
434 while (he_limit >= ae_length) {
435 if (strncmp(nh_he, ae, ae_length) == 0) {
446 #if defined(ASCIIGRAPH) && defined(PC9800)
447 extern void NDECL((*ibmgraphics_mode_callback)); /* defined in drawing.c */
451 extern void NDECL((*ascgraphics_mode_callback)); /* defined in drawing.c */
452 static void NDECL(tty_ascgraphics_hilite_fixup);
455 tty_ascgraphics_hilite_fixup()
459 for (c = 0; c < CLR_MAX / 2; c++)
460 if (c != CLR_BLACK) {
461 hilites[c | BRIGHT] = (char *) alloc(sizeof("\033[1;3%dm"));
462 Sprintf(hilites[c | BRIGHT], "\033[1;3%dm", c);
464 hilites[c] = (char *) alloc(sizeof("\033[0;3%dm"));
465 Sprintf(hilites[c], "\033[0;3%dm", c);
477 if (!SYMHANDLING(H_IBM))
478 tty_ascgraphics_hilite_fixup();
479 /* set up callback in case option is not set yet but toggled later */
480 ascgraphics_mode_callback = tty_ascgraphics_hilite_fixup;
482 if (SYMHANDLING(H_IBM))
484 /* set up callback in case option is not set yet but toggled later */
485 ibmgraphics_mode_callback = init_hilite;
490 if (SYMHANDLING(H_DEC))
491 tty_decgraphics_termcap_fixup();
492 /* set up callback in case option is not set yet but toggled later */
493 decgraphics_mode_callback = tty_decgraphics_termcap_fixup;
496 tty_number_pad(1); /* make keypad send digits */
507 /* Cursor movements */
509 /* Note to overlay tinkerers. The placement of this overlay controls the
511 of the function xputc(). This function is not currently in trampoli.[ch]
512 files for what is deemed to be performance reasons. If this define is
514 and or xputc() is taken out of the ROOT overlay, then action must be taken
521 if ((int) ttyDisplay->cury > y) {
523 while ((int) ttyDisplay->cury > y) { /* Go up. */
531 tty_curs(BASE_WINDOW, x + 1, y);
532 } /* else impossible("..."); */
533 } else if ((int) ttyDisplay->cury < y) {
535 while ((int) ttyDisplay->cury < y) {
542 while ((int) ttyDisplay->cury < y) {
544 ttyDisplay->curx = 0;
549 if ((int) ttyDisplay->curx < x) { /* Go to the right. */
553 /* should instead print what is there already */
554 while ((int) ttyDisplay->curx < x) {
559 } else if ((int) ttyDisplay->curx > x) {
560 while ((int) ttyDisplay->curx > x) { /* Go to the left. */
571 xputs(tgoto(nh_CM, x, y));
572 ttyDisplay->cury = y;
573 ttyDisplay->curx = x;
576 /* See note above. xputc() is a special function. */
597 (void) jputchar('\0');
599 (void) fputs(s, stdout);
601 #if defined(NHSTDC) || defined(ULTRIX_PROTO)
602 tputs(s, 1, (int (*) ()) xputc);
614 } else { /* no-CE fix - free after Harold Rynes */
615 register int cx = ttyDisplay->curx + 1;
617 /* this looks terrible, especially on a slow terminal
618 but is better than nothing */
623 tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + 1,
624 (int) ttyDisplay->cury);
631 /* note: if CL is null, then termcap initialization failed,
632 so don't attempt screen-oriented I/O during final cleanup.
646 xputs(tgoto(nh_CM, 0, 0));
648 tty_curs(BASE_WINDOW, 1, 0); /* using UP ... */
649 ttyDisplay->curx = ttyDisplay->cury = 0;
666 #if 0 /* if you need one of these, uncomment it (here and in extern.h) */
691 /* not in most termcap entries */
716 (void) putchar('\007'); /* curx does not change */
718 (void) cputchar('\007'); /* curx does not change */
720 (void) fflush(stdout);
741 static const short tmspc10[] = { /* from termcap */
742 0, 2000, 1333, 909, 743, 666, 333, 166, 83,
743 55, 50, 41, 27, 20, 13, 10, 5
746 static const short tmspc10[] = { /* from termcap */
747 0, 2000, 1333, 909, 743, 666, 500, 333, 166,
748 83, 55, 41, 20, 10, 5
762 (void) fflush(stdout);
763 msleep(50); /* sleep for 50 milliseconds */
768 /* simulate the delay with "cursor here" */
769 #if 1 /*JP*//*JPTB need?*/
773 for (i = 0; i < 3; i++) {
774 cmov(ttyDisplay->curx, ttyDisplay->cury);
775 (void) fflush(stdout);
781 /* BUG: if the padding character is visible, as it is on the 5620
782 then this looks terrible. */
785 /* cbosgd!cbcephus!pds for SYS V R2 */
787 tputs("$<50>", 1, (int (*) ()) xputc);
789 tputs("$<50>", 1, xputc);
792 #if defined(NHSTDC) || defined(ULTRIX_PROTO)
793 tputs("50", 1, (int (*) ()) xputc);
795 tputs("50", 1, xputc);
799 } else if (ospeed > 0 && ospeed < SIZE(tmspc10) && nh_CM) {
800 /* delay by sending cm(here) an appropriate number of times */
802 strlen(tgoto(nh_CM, ttyDisplay->curx, ttyDisplay->cury));
803 register int i = 500 + tmspc10[ospeed] / 2;
806 cmov((int) ttyDisplay->curx, (int) ttyDisplay->cury);
807 i -= cmlen * tmspc10[ospeed];
813 /* must only be called with curx = 1 */
815 cl_eos() /* free after Robert Viduya */
820 register int cy = ttyDisplay->cury + 1;
822 while (cy <= LI - 2) {
828 tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + 1,
829 (int) ttyDisplay->cury);
833 #if defined(TEXTCOLOR) && defined(TERMLIB)
834 #if defined(UNIX) && defined(TERMINFO)
836 * Sets up color highlighting, using terminfo(4) escape sequences.
838 * Having never seen a terminfo system without curses, we assume this
839 * inclusion is safe. On systems with color terminfo, it should define
840 * the 8 COLOR_FOOs, and avoid us having to guess whether this particular
841 * terminfo uses BGR or RGB for its indexes.
843 * If we don't get the definitions, then guess. Original color terminfos
844 * used BGR for the original Sf (setf, Standard foreground) codes, but
845 * there was a near-total lack of user documentation, so some subsequent
846 * terminfos, such as early Linux ncurses and SCO UNIX, used RGB. Possibly
847 * as a result of the confusion, AF (setaf, ANSI Foreground) codes were
848 * introduced, but this caused yet more confusion. Later Linux ncurses
849 * have BGR Sf, RGB AF, and RGB COLOR_FOO, which appears to be the SVR4
850 * standard. We could switch the colors around when using Sf with ncurses,
851 * which would help things on later ncurses and hurt things on early ncurses.
852 * We'll try just preferring AF and hoping it always agrees with COLOR_FOO,
853 * and falling back to Sf if AF isn't defined.
855 * In any case, treat black specially so we don't try to display black
856 * characters on the assumed black background.
859 /* `curses' is aptly named; various versions don't like these
860 macros used elsewhere within nethack; fortunately they're
861 not needed beyond this point, so we don't need to worry
862 about reconstructing them after the header file inclusion. */
866 #define m_move curses_m_move /* Some curses.h decl m_move(), not used here \
871 #if !defined(LINUX) && !defined(__FreeBSD__) && !defined(NOTPARMDECL)
872 extern char *tparm();
875 #ifndef COLOR_BLACK /* trust include file */
876 #ifndef _M_UNIX /* guess BGR */
877 #define COLOR_BLACK 0
879 #define COLOR_GREEN 2
882 #define COLOR_MAGENTA 5
883 #define COLOR_YELLOW 6
884 #define COLOR_WHITE 7
885 #else /* guess RGB */
886 #define COLOR_BLACK 0
888 #define COLOR_GREEN 2
889 #define COLOR_YELLOW 3
891 #define COLOR_MAGENTA 5
893 #define COLOR_WHITE 7
897 /* Mapping data for the six terminfo colors that resolve to pairs of nethack
898 * colors. Black and white are handled specially.
901 int ti_color, nh_color, nh_bright_color;
902 } ti_map[6] = { { COLOR_RED, CLR_RED, CLR_ORANGE },
903 { COLOR_GREEN, CLR_GREEN, CLR_BRIGHT_GREEN },
904 { COLOR_YELLOW, CLR_BROWN, CLR_YELLOW },
905 { COLOR_BLUE, CLR_BLUE, CLR_BRIGHT_BLUE },
906 { COLOR_MAGENTA, CLR_MAGENTA, CLR_BRIGHT_MAGENTA },
907 { COLOR_CYAN, CLR_CYAN, CLR_BRIGHT_CYAN } };
909 static char nilstring[] = "";
915 char *setf, *scratch;
918 if (tgetnum("Co") < 8 || (MD == NULL) || (strlen(MD) == 0)
919 || ((setf = tgetstr("AF", (char **) 0)) == (char *) 0
920 && (setf = tgetstr("Sf", (char **) 0)) == (char *) 0)) {
921 /* Fallback when colors not available
922 * It's arbitrary to collapse all colors except gray
923 * together, but that's what the previous code did.
925 hilites[CLR_BLACK] = nh_HI;
926 hilites[CLR_RED] = nh_HI;
927 hilites[CLR_GREEN] = nh_HI;
928 hilites[CLR_BROWN] = nh_HI;
929 hilites[CLR_BLUE] = nh_HI;
930 hilites[CLR_MAGENTA] = nh_HI;
931 hilites[CLR_CYAN] = nh_HI;
932 hilites[CLR_GRAY] = nilstring;
933 hilites[NO_COLOR] = nilstring;
934 hilites[CLR_ORANGE] = nh_HI;
935 hilites[CLR_BRIGHT_GREEN] = nh_HI;
936 hilites[CLR_YELLOW] = nh_HI;
937 hilites[CLR_BRIGHT_BLUE] = nh_HI;
938 hilites[CLR_BRIGHT_MAGENTA] = nh_HI;
939 hilites[CLR_BRIGHT_CYAN] = nh_HI;
940 hilites[CLR_WHITE] = nh_HI;
949 scratch = tparm(setf, ti_map[c].ti_color);
950 work = (char *) alloc(strlen(scratch) + md_len + 1);
952 hilites[ti_map[c].nh_bright_color] = work;
954 Strcpy(work, scratch);
955 hilites[ti_map[c].nh_color] = work;
958 scratch = tparm(setf, COLOR_WHITE);
959 hilites[CLR_WHITE] = (char *) alloc(strlen(scratch) + md_len + 1);
960 Strcpy(hilites[CLR_WHITE], MD);
961 Strcat(hilites[CLR_WHITE], scratch);
963 hilites[CLR_GRAY] = nilstring;
964 hilites[NO_COLOR] = nilstring;
966 if (iflags.wc2_darkgray) {
967 /* On many terminals, esp. those using classic PC CGA/EGA/VGA
968 * textmode, specifying "hilight" and "black" simultaneously
969 * produces a dark shade of gray that is visible against a
970 * black background. We can use it to represent black objects.
972 scratch = tparm(setf, COLOR_BLACK);
973 hilites[CLR_BLACK] = (char *) alloc(strlen(scratch) + md_len + 1);
974 Strcpy(hilites[CLR_BLACK], MD);
975 Strcat(hilites[CLR_BLACK], scratch);
977 /* But it's concievable that hilighted black-on-black could
978 * still be invisible on many others. We substitute blue for
981 hilites[CLR_BLACK] = hilites[CLR_BLUE];
988 /* if colors weren't available, no freeing needed */
989 if (hilites[CLR_BLACK] == nh_HI)
992 if (hilites[CLR_BLACK] != hilites[CLR_BLUE])
993 free(hilites[CLR_BLACK]);
995 /* CLR_BLUE overlaps CLR_BRIGHT_BLUE, do not free */
996 /* CLR_GREEN overlaps CLR_BRIGHT_GREEN, do not free */
997 /* CLR_CYAN overlaps CLR_BRIGHT_CYAN, do not free */
998 /* CLR_RED overlaps CLR_ORANGE, do not free */
999 /* CLR_MAGENTA overlaps CLR_BRIGHT_MAGENTA, do not free */
1000 /* CLR_BROWN overlaps CLR_YELLOW, do not free */
1001 /* CLR_GRAY is static 'nilstring', do not free */
1002 /* NO_COLOR is static 'nilstring', do not free */
1003 free(hilites[CLR_BRIGHT_BLUE]);
1004 free(hilites[CLR_BRIGHT_GREEN]);
1005 free(hilites[CLR_BRIGHT_CYAN]);
1006 free(hilites[CLR_YELLOW]);
1007 free(hilites[CLR_ORANGE]);
1008 free(hilites[CLR_BRIGHT_MAGENTA]);
1009 free(hilites[CLR_WHITE]);
1012 #else /* UNIX && TERMINFO */
1015 /* find the foreground and background colors set by nh_HI or nh_HE */
1017 analyze_seq(str, fg, bg)
1021 register int c, code;
1028 *fg = *bg = NO_COLOR;
1031 c = (str[0] == '\233') ? 1 : 2; /* index of char beyond esc prefix */
1032 len = strlen(str) - 1; /* length excluding attrib suffix */
1033 if ((c != 1 && (str[0] != '\033' || str[1] != '[')) || (len - c) < 1
1038 if ((code = atoi(&str[c])) == 0) { /* reset */
1039 /* this also catches errors */
1044 *fg = *bg = NO_COLOR;
1046 } else if (code == 1) { /* bold */
1049 /* I doubt we'll ever resort to using blinking characters,
1050 unless we want a pulsing glow for something. But, in case
1052 } else if (code == 5) { /* blinking */
1054 } else if (code == 25) { /* stop blinking */
1057 } else if (code == 7 || code == 27) { /* reverse */
1058 code = *fg & ~BRIGHT;
1059 *fg = *bg | (*fg & BRIGHT);
1061 } else if (code >= 30 && code <= 37) { /* hi_foreground RGB */
1063 } else if (code >= 40 && code <= 47) { /* hi_background RGB */
1066 while (digit(str[++c]))
1074 * Sets up highlighting sequences, using ANSI escape sequences (highlight code
1075 * found in print.c). The nh_HI and nh_HE sequences (usually from SO) are
1076 * scanned to find foreground and background colors.
1084 extern unsigned long tos_numcolors; /* in tos.c */
1085 static char NOCOL[] = "\033b0", COLHE[] = "\033q\033b0";
1087 if (tos_numcolors <= 2) {
1090 /* Under TOS, the "bright" and "dim" colors are reversed. Moreover,
1091 * on the Falcon the dim colors are *really* dim; so we make most
1092 * of the colors the bright versions, with a few exceptions where
1093 * the dim ones look OK.
1096 for (c = 1; c < SIZE(hilites); c++) {
1098 foo = (char *) alloc(sizeof("\033b0"));
1099 if (tos_numcolors > 4)
1100 Sprintf(foo, "\033b%c", (c & ~BRIGHT) + '0');
1102 Strcpy(foo, "\033b0");
1106 if (tos_numcolors == 4) {
1107 TI = "\033b0\033c3\033E\033e";
1108 TE = "\033b3\033c0\033J";
1110 hilites[CLR_GREEN] = hilites[CLR_GREEN | BRIGHT] = "\033b2";
1111 hilites[CLR_RED] = hilites[CLR_RED | BRIGHT] = "\033b1";
1113 sprintf(hilites[CLR_BROWN], "\033b%c", (CLR_BROWN ^ BRIGHT) + '0');
1114 sprintf(hilites[CLR_GREEN], "\033b%c", (CLR_GREEN ^ BRIGHT) + '0');
1116 TI = "\033b0\033c\017\033E\033e";
1117 TE = "\033b\017\033c0\033J";
1119 hilites[CLR_WHITE] = hilites[CLR_BLACK] = NOCOL;
1120 hilites[NO_COLOR] = hilites[CLR_GRAY];
1125 int backg, foreg, hi_backg, hi_foreg;
1127 for (c = 0; c < SIZE(hilites); c++)
1129 hilites[CLR_GRAY] = hilites[NO_COLOR] = (char *) 0;
1131 analyze_seq(nh_HI, &hi_foreg, &hi_backg);
1132 analyze_seq(nh_HE, &foreg, &backg);
1134 for (c = 0; c < SIZE(hilites); c++)
1135 /* avoid invisibility */
1136 if ((backg & ~BRIGHT) != c) {
1142 hilites[c] = (char *) 0;
1143 else if (c != hi_foreg || backg != hi_backg) {
1144 hilites[c] = (char *) alloc(sizeof("\033[%d;3%d;4%dm"));
1145 Sprintf(hilites[c], "\033[%d", !!(c & BRIGHT));
1146 if ((c | BRIGHT) != (foreg | BRIGHT))
1147 Sprintf(eos(hilites[c]), ";3%d", c & ~BRIGHT);
1148 if (backg != CLR_BLACK)
1149 Sprintf(eos(hilites[c]), ";4%d", backg & ~BRIGHT);
1150 Strcat(hilites[c], "m");
1155 /* brighten low-visibility colors */
1156 hilites[CLR_BLUE] = hilites[CLR_BLUE | BRIGHT];
1167 for (c = 0; c < CLR_MAX / 2; c++) {
1168 if (hilites[c | BRIGHT] == hilites[c])
1169 hilites[c | BRIGHT] = 0;
1170 if (hilites[c] && (hilites[c] != nh_HI))
1171 free((genericptr_t) hilites[c]), hilites[c] = 0;
1172 if (hilites[c | BRIGHT] && (hilites[c | BRIGHT] != nh_HI))
1173 free((genericptr_t) hilites[c | BRIGHT]), hilites[c | BRIGHT] = 0;
1179 #endif /* TEXTCOLOR */
1181 static char nulstr[] = "";
1193 #if defined(TERMLIB) && defined(TEXTCOLOR)
1222 term_start_attr(attr)
1226 xputs(s_atr2str(attr));
1235 xputs(e_atr2str(attr));
1240 term_start_raw_bold()
1260 term_start_color(color)
1263 xputs(hilites[color]);
1271 /* XXX has_color() should be added to windowprocs */
1272 if (windowprocs.name != NULL && !strcmpi(windowprocs.name, "X11"))
1276 /* XXX has_color() should be added to windowprocs */
1277 if (windowprocs.name != NULL && !strcmpi(windowprocs.name, "Gem"))
1281 /* XXX has_color() should be added to windowprocs */
1282 if (windowprocs.name != NULL && !strcmpi(windowprocs.name, "Qt"))
1285 #ifdef AMII_GRAPHICS
1286 /* hilites[] not used */
1287 return iflags.use_color;
1289 return hilites[color] != (char *) 0;
1292 #endif /* TEXTCOLOR */
1294 #endif /* TTY_GRAPHICS */