Re: Inline Color Questions

From: Mathew Earle Reuther (graymere@zipcon.net)
Date: 08/01/02


> -   snprintf(buf, sizeof(buf), "$n says, '%s'", argument);
> +   snprintf(buf, sizeof(buf), "$n says, '%s&w'", argument);

Excellent, that's kind of what I was thinking, but wasn't entirely sure
how things were working.

> If you want to completely prohibit players from using color, a simple
> solution is to double every '&' you encounter in their input.  CircleMUD
> already does this for '$' -- see process_input().

I think as long as I can prevent color bleed I'm fine.  If someone wants
to run around making ten colored "says" that's what disciplinary commands
were made for. *shrug*  My main concern was the bleed, which is indeed
addressed here.

Now for a problem I've run across.  I cannot get the flash or backgrounds
to work.  For some reason whenever I use the appropriate code, there is no
response.  I had one odd flash and bgcolor bleed oonce when I had &&& in a
file where I meant to have &&&&, but beyond that they codes seem to just
vaporize.

&0 to &7 and &f seem to not function at all. :(

(The code is enclosed below for those who don't have it handy.)

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, bg_clr = 40, flash = 0;
  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 (IS_UPPER(*str)) sprintf(i, "\x1b[1;");
        else                sprintf(i, "\x1b[0;");

        if (clr >= 40) {
          bg_clr = 40;
          str++;
          continue;
        } else if (clr == 1) {
          flash = !flash;
          str++;
          continue;
        }

        sprintf(i, "%s%s%d;%dm", i, (flash ? "5;" : ""), bg_clr, 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);
}

-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