Playing around with other MUD engines, I really liked being able to add highlights in descriptions. I didn't set out to really add color too but the functionality is exactly the same so I'm just grouping it all here under the same subject. I have to say that this took me a lot longer to work out than it should have even looking through the ColdCore database - does that really even have ANSI color in it?

So adding color is, of course, exactly as it is in everything else: send an escape code on the user's connection followed by the ANSI codes. It's as simple as that. Of course, the hard part was figuring out what to put into the buffer to actually send an escape code. After a lot of trial and error and searching lots of references on the subject and even going through the ColdCore textdump for any hints, I finally found the right escape sequence. However, bear in mind that the escape sequence only works when you use it as a buffer - converting it to a string to try and use it as such drops the actual escape character and renders it useless.

So the two ANSI escape codes for highlighting text:

    `[27, 91, 49, 109] (bold)
    `[27, 91, 48, 109] (reset)

The "27, 91" is the actual escape character. If you were to do it in a terminal, it would show up similar to "\[". 49 = 1 (bold) and 48 = 0 (reset). 109 = m, the terminating character in the code. So the second buffer breaks down to (escape code) + 0 + m or "\[0m" which is the ANSI escape code for reset or reverting text back to what it was.

I did write a parser into my .tell() method that will explode the argument string based on a tag (\B) and then loop through the list and add the bold or reset code depending on a flag to indicate where in the string we are. It's terribly inefficient so I'll spare you, the reader. If I ever manage to get back around to rewriting it better, I'll add it here.

In the meantime, here's a snippet of code lines to show you how it works. I've included the color codes to show that aspect of it as well.

    cwrite(str_to_buf("this is a "));
    cwrite(`[27, 91, 49, 109]);
    cwrite(str_to_buf("test"));
    cwrite(`[27, 91, 48, 109]);
    cwrite(str_to_buf(" of bolding\n"));
    cwrite(str_to_buf("some colors:\n"));
    cwrite(`[27, 91, 51, 49, 109]);
    cwrite(str_to_buf("red"));
    cwrite(`[27, 91, 48, 109]);
    cwrite(str_to_buf("\n"));
    cwrite(`[27, 91, 51, 52, 109]);
    cwrite(str_to_buf("blue"));
    cwrite(`[27, 91, 48, 109]);
    cwrite(str_to_buf("\n"));
    cwrite(`[27, 91, 51, 50, 109]);
    cwrite(str_to_buf("green"));
    cwrite(`[27, 91, 48, 109]);
    cwrite(str_to_buf("\n"));

Enjoy!