Re: Inline Color Questions

From: Mathew Earle Reuther (
Date: 08/02/02

After working more with the color code I am even further hopelessly
confused.  The term programs I am using simply do not react the same way.
They're being fed the same information I would assume, but they are not
responding in the correct manner.  With the changes made thusfar, ZMUD
appears to be handling color changes better, though it still cannot
adequately interpret bright vs. subdued colors.  (Some things which should
be the other are not, which seems to depend on the brightness of previous

As well, somehow one of my terms (PuTTYtel) managed to decide that things
should be underlined.  The only code it had been sent as near as I can
tell was &w, so it's either initializing as underlined, or &w makes it
believe things should be underlined.


I am so close to no longer caring about color.  It's frustrating to deal
with this stuff, and I don't know that having the ability to colorize
things is that vital.  (I mudded for years without ever enabling color on
a mud, and all too many that have it are exceedingly garish.)

Is it this particular color code?  Is it my term programs?  (That in
itself is a bad sign, because if mine fail, other people's will, and
that's a reason to scrap color flat out if I ever heard one!)  Are the
gods of c angry with me?

Here's the code I'm using now.  *sigh*

int is_color(char c) {
  switch (c) {
  case 'x': return 30; break;
  case 'r': return 31; break;
  case 'g': return 32; break;
  case 'y': return 33; break;
  case 'b': return 34; break;
  case 'm': return 35; break;
  case 'c': return 36; break;
  case 'w': return 37; break;

  case '0': return 40; break;
  case '1': return 44; break;
  case '2': return 42; break;
  case '3': return 46; break;
  case '4': return 41; break;
  case '5': return 45; break;
  case '6': return 43; break;
  case '7': return 47; break;

  case 'f': return  1; break;
  case '&': return -1; break;
  default : return  0; break;

char *interpret_colors(char *str, bool parse) {
  int clr = 37;
  static char cbuf[MAX_STRING_LENGTH];
  char *cp, *tmp;
  char i[256];

  if (!strchr(str, '&'))
    return (str);

  cp = cbuf;

  for (;;) {
     if (*str == '&') {
       if ((clr = is_color(LOWER(*str))) > 0 && parse) {
         if (clr >= 40)
           sprintf(i, "\x1B[%dm", clr);
         else if (clr == 1)
           sprintf(i, "\x1B[%sm", (isupper(*str) ? "5" : "25"));
           sprintf(i, "\x1B[%s;%dm", (isupper(*str) ? "1" : "21"), clr);
         tmp = i;
       } else if (clr == -1) {

        *(cp++) = '&';
      } else {
      while ((*cp = *(tmp++)))
    } else if (!(*(cp++) = *(str++)))

  *cp = '\0';
  return (cbuf);

Sorry for the length, but I just can't figure out where things are going
wrong. :(


   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/25/03 PDT