Re: [Circle] COLOR

From: Ground Zero Enterprises (zero@baker.cnw.com)
Date: 07/25/96


This is a slightly improved version of the Easy Color program posted here 
by Pi (can't remember address).  Make these modifications to stock circle:

in comm.c add in includes:

#include "screen.h"

in comm.c in externs:

proc_color(char *inbuf, int color);

in comm.c right before the text:

  /*
   * now, send the output.  If this is an 'interruption', use the prepended
   * CRLF, otherwise send the straight output sans CRLF.
   */

add:

  if (t->character) {
    proc_color(i, clr(t->character, C_NRM));
    strcat(i, "\x1b[0m");  /* so if someone doesnt return their colors */ 
  }                        /* back to normal manually */
  

in your Makefile add color.o to the other object files and in the 
dependencies section add:

color.o: color.c
	$(CC) -c $(CFLAGS) color.c

and create a file called color.c that include the following:

------------------cut here--------------------

#define CNRM  "\x1B[0;0m"
#define CBLA  "\x1B[30m"
#define CRED  "\x1B[31m" 
#define CGRN  "\x1B[32m"  /* base colors */
#define CYEL  "\x1B[33m"
#define CBLU  "\x1B[34m"
#define CMAG  "\x1B[35m"
#define CCYN  "\x1B[36m"
#define CWHT  "\x1B[37m"
#define CNUL  ""

#define BBLA  "\x1B[1;30m"
#define BRED  "\x1B[1;31m"
#define BGRN  "\x1B[1;32m"
#define BYEL  "\x1B[1;33m" /* bright colors */
#define BBLU  "\x1B[1;34m"
#define BMAG  "\x1B[1;35m"
#define BCYN  "\x1B[1;36m"
#define BWHT  "\x1B[1;37m"

#define BKBLA  "\x1B[40m"
#define BKRED  "\x1B[41m"
#define BKGRN  "\x1B[42m"
#define BKYEL  "\x1B[43m" /* background colors */
#define BKBLU  "\x1B[44m"
#define BKMAG  "\x1B[45m"
#define BKCYN  "\x1B[46m"
#define BKWHT  "\x1B[47m"

#define FLA  "\x1B[5m"    /* flashing   */
#define UND  "\x1B[4m"    /* underlined */


const char *COLORLIST[] = {CNUL, CNRM, CBLA, CRED, CGRN, CYEL, CBLU, CMAG, 
                           CCYN, CWHT, BBLA, BRED, BGRN, BYEL, BBLU, 
                           BMAG, BCYN, BWHT, BKBLA, BKRED, BKGRN, 
                           BKYEL, BKBLU, BKMAG, BKCYN, BKWHT, FLA, UND}; 


int parse_code(char code) 
{
  
  switch (code) {
  case 'n':
    return 1;
    break;
  case 'l':
    return 2;
    break;
  case 'r':
    return 3;
    break;
  case 'g':
    return 4;
    break;
  case 'y':
    return 5;
    break;
  case 'b':
    return 6;
    break;
  case 'm':
    return 7;
    break;
  case 'c':
    return 8;
    break;
  case 'w':
    return 9;
    break;
  case 'L':
    return 10;
    break;
  case 'R':
    return 11;
    break;
  case 'G':
    return 12;
    break;
  case 'Y':
    return 13;
    break;
  case 'B':
    return 14;
    break;
  case 'M':
    return 15;
    break;
  case 'C':
    return 16;
    break;
  case 'W':
    return 17;
    break;
  case '1':
    return 18;
    break;
  case '2':
    return 19;
    break;
  case '3':
    return 20;
    break;
  case '4':
    return 21;
    break;
  case '5':
    return 22;
    break;
  case '6':
    return 23;
    break;
  case '7':
    return 24;
    break;
  case '8':
    return 25;
    break;
  case 'f':
    return 26;
    break;
  case 'u':
    return 27;
    break;
  default:
    return 0;
    break;
  }
}

void proc_color(char *inbuf, int color)
{
  register int j = 0, p = 0;
  int k, max, code;
  char out_buf[32768];

  if (*inbuf == '\0') 
    return;

  while (inbuf[j] != '\0') {
    if (inbuf[j] == '&' && (code = parse_code(inbuf[j+1]))) {
      j += 2;
      if (color) {
        max = strlen(COLORLIST[code]);
        for (k = 0; k < max; k++) { 
          out_buf[p] = COLORLIST[code][k]; 
          p++; 
        }
      }
    } else {
      out_buf[p] = inbuf[j]; 
      j++;
      p++;
    }
  }
  out_buf[p] = '\0';
  strcpy(inbuf, out_buf);
}

------------------cut here--------------------


Chris

+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/07/00 PST