This is a color code drop in for circle 3.1 that allows many nice ANSI functions. It is loosly based on colourcode.txt by Jason Berg. See bottom of file for the color codes themselves. Dylan Myers a.k.a. Ulath of Caer Dubrin telnet://cd.dubrin.net:9900 ralgith@yahoo.com Instructions * Edit your comm.c file. * Add these function to comm.c * Be sure these go in below write_to_output and above vwrite_to_output #define COLOR_ON(ch) (!IS_NPC(ch) ? (PRF_FLAGGED((ch), PRF_COLOR_1 | PRF_COLOR_2) ? 1 : 0) : 0) /* Color replacement arrays. Renx -- 011100 */ #define A "\x1B[" const char *ANSI[] = { "&", A"0m",A"0;30m",A"0;34m",A"0;32m",A"0;36m",A"0;31m", A"0;35m",A"0;33m",A"0;37m",A"1;30m",A"1;34m",A"1;32m",A"1;36m",A"1;31m", A"1;35m",A"1;33m",A"1;37m",A"40m",A"44m",A"42m",A"46m",A"41m",A"45m", A"43m",A"47m",A"5m",A"4m",A"1m",A"7m" ,"!"}; #undef A const char CCODE[] = "&nkbgcrmywKBGCRMYW01234567luoe!"; #define NEW_STRING_LENGTH (size_t)(dest_char-save_pos) size_t proc_colors(char *txt, size_t maxlen, int parse) { char *dest_char, *source_char, *color_char, *save_pos; int i; size_t wanted; if (!txt || !strchr(txt, '&')) /* skip out if no color codes */ return strlen(txt); source_char = txt; CREATE(dest_char, char, maxlen); save_pos = dest_char; for( ; *source_char && (NEW_STRING_LENGTH < maxlen); ) { /* no color code - just copy */ if (*source_char != '&') { *dest_char++ = *source_char++; continue; } /* if we get here we have a color code */ source_char++; /* source_char now points to the code */ if (*source_char == '\0') { /* string was terminated with color code - just put it in */ *dest_char++ = '&'; /* source_char will now point to '\0' in the for() check */ continue; } if (!parse) { /* not parsing, just skip the code, unless it's && */ if (*source_char == '&') { *dest_char++ = '&'; } source_char++; /* skip to next (non-colorcode) char */ continue; } /* parse the color code */ for (i = 0; CCODE[i] != '!'; i++) { /* do we find it ? */ if ((*source_char) == CCODE[i]) { /* if so :*/ if ( NEW_STRING_LENGTH + strlen(ANSI[i]) < maxlen) { /* only substitute if there's room for the whole code */ /* color_char now points to the first char in color code*/ for(color_char = (char *)ANSI[i] ; *color_char ; ) *dest_char++ = *color_char++; } break; } } /* If we couldn't find any correct color code, or we found it and * substituted above, let's just process the next character. * - Welcor */ source_char++; } /* for loop */ /* make sure output is NULL - terminated */ *dest_char = '\0'; wanted = strlen(source_char); /* see if we wanted more space */ strncpy(txt, save_pos, maxlen-1); free(save_pos); /* plug memory leak */ return NEW_STRING_LENGTH+wanted; } #undef NEW_STRING_LENGTH --- End of Drop in Code --- My screen.h -- Included just cause it allows you to use the extra codes such as blink and underline inside code -- /* ************************************************************************ * File: screen.h Part of CircleMUD * * Usage: header file with ANSI color codes for online color * * * * All rights reserved. See license.doc for complete information. * * Modifications by Dylan Myers aka Ulath of Caer Dubrin (C) 2004 * * * * Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University * * CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991. * ************************************************************************ */ #define KNRM "\033[0m" #define KRED "\033[31m" #define KGRN "\033[32m" #define KYEL "\033[33m" #define KBLU "\033[34m" #define KMAG "\033[35m" #define KCYN "\033[36m" #define KWHT "\033[37m" #define KBLK "\033[30m" #define KBLD "\033[1m" #define KBLN "\033[5m" #define KNUL "" #define KCLR "\033[2J" #define KUND "\033[4m" #define KDAR "\033[2m" #define KBRED "\033[41m" #define KBGRN "\033[42m" #define KBYEL "\033[43m" #define KBBLU "\033[44m" #define KBMAG "\033[45m" #define KBCYN "\033[46m" #define KBWHT "\033[47m" #define KBBLK "\033[40m" /* conditional color. pass it a pointer to a char_data and a color level. */ #define C_OFF 0 #define C_SPR 1 #define C_NRM 2 #define C_CMP 3 #define _clrlevel(ch) ((PRF_FLAGGED((ch), PRF_COLOR_1) ? 1 : 0) + \ (PRF_FLAGGED((ch), PRF_COLOR_2) ? 2 : 0)) #define clr(ch,lvl) (_clrlevel(ch) >= (lvl)) #define CCNRM(ch,lvl) (clr((ch),(lvl))?KNRM:KNUL) #define CCBLK(ch,lvl) (clr((ch),(lvl))?KBLK:KNUL) #define CCRED(ch,lvl) (clr((ch),(lvl))?KRED:KNUL) #define CCGRN(ch,lvl) (clr((ch),(lvl))?KGRN:KNUL) #define CCYEL(ch,lvl) (clr((ch),(lvl))?KYEL:KNUL) #define CCBLU(ch,lvl) (clr((ch),(lvl))?KBLU:KNUL) #define CCMAG(ch,lvl) (clr((ch),(lvl))?KMAG:KNUL) #define CCCYN(ch,lvl) (clr((ch),(lvl))?KCYN:KNUL) #define CCWHT(ch,lvl) (clr((ch),(lvl))?KWHT:KNUL) #define CCBLD(ch,lvl) (clr((ch),(lvl))?KBLD:KNUL) #define CCBLN(ch,lvl) (clr((ch),(lvl))?KBLN:KNUL) #define CCCLR(ch,lvl) (clr((ch),(lvl))?KCLR:KNUL) #define CCUND(ch,lvl) (clr((ch),(lvl))?KUND:KNUL) #define CCDAR(ch,lvl) (clr((ch),(lvl))?KDAR:KNUL) #define CCBBLK(ch,lvl) (clr((ch),(lvl))?KBBLK:KNUL) #define CCBRED(ch,lvl) (clr((ch),(lvl))?KBRED:KNUL) #define CCBGRN(ch,lvl) (clr((ch),(lvl))?KBGRN:KNUL) #define CCBYEL(ch,lvl) (clr((ch),(lvl))?KBYEL:KNUL) #define CCBBLU(ch,lvl) (clr((ch),(lvl))?KBBLU:KNUL) #define CCBMAG(ch,lvl) (clr((ch),(lvl))?KBMAG:KNUL) #define CCBCYN(ch,lvl) (clr((ch),(lvl))?KBCYN:KNUL) #define CCBWHT(ch,lvl) (clr((ch),(lvl))?KBWHT:KNUL) #define COLOR_LEV(ch) (_clrlevel(ch)) #define QNRM CCNRM(ch,C_SPR) #define QBLK CCBLK(ch,C_SPR) #define QRED CCRED(ch,C_SPR) #define QGRN CCGRN(ch,C_SPR) #define QYEL CCYEL(ch,C_SPR) #define QBLU CCBLU(ch,C_SPR) #define QMAG CCMAG(ch,C_SPR) #define QCYN CCCYN(ch,C_SPR) #define QWHT CCWHT(ch,C_SPR) #define QBLD CCBLD(ch,C_SPR) #define QBLN CCBLN(ch,C_SPR) #define QCLR CCBLN(ch,C_SPR) #define QUND CCUND(ch,C_SPR) #define QDAR CCDAR(ch,C_SPR) #define QBBLK CCBBLK(ch,C_SPR) #define QBRED CCBRED(ch,C_SPR) #define QBGRN CCBGRN(ch,C_SPR) #define QBYEL CCBYEL(ch,C_SPR) #define QBBLU CCBBLU(ch,C_SPR) #define QBMAG CCBMAG(ch,C_SPR) #define QBCYN CCBCYN(ch,C_SPR) #define QBWHT CCBWHT(ch,C_SPR) -- End screen.h -- Compile and you're done. How to use it & color-codes How to use it: Wherever whenever you feel like adding some color (for those who have colorlevel >= NORMAL) you just do something like this: Color Codes: &n - normal &k - black &K - gray &0 - background black &b - blue &B - bright blue &1 - background blue &g - green &G - bright green &2 - background green &c - cyan &C - bright cyan &3 - background cyan &r - red &R - bright red &4 - background red &m - magneta &M - bright magneta &5 - background magneta &y - yellow &Y - bright yellow &6 - background yellow &w - white &W - bright white &7 - background white Extra codes: &l - blink &o - bold (just makes normal colors bright..) &u - underline &e - reverse video && - single &