Re: Inline Color Questions

From: Mathew Earle Reuther (graymere@zipcon.net)
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
colors)

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.

*sigh*

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 == '&') {
       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"));
         else
           sprintf(i, "\x1B[%s;%dm", (isupper(*str) ? "1" : "21"), clr);
         tmp = i;
       } else if (clr == -1) {

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

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

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

-Mathew

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



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