Adding ANSI color

Posted by Daniel Spain on Thu 17 Nov 2011 07:56 AM — 10 posts, 37,607 views.

#0
im not familiar with other terminals other than windows which so far this has worked.
does anyone reccomend a different way to utilize color:


Send (c, "\r\n");
Send (c, "\r\n");
Send (c, "1) Elven     4) Human\r\n");
Send (c, "2) Dwarven   5) Goblin\r\n"); 
Send (c, "3) Gnomish   6) Half-Ogre\r\n");
Send (c, "\r\n");
Send (c, "Select a race: ");


as always thanks for the help.
Australia Forum Administrator #1
What code-base is this? Usually there is a way of getting the lower-level parts of the code to change things like &G into green, but it depends on the code base.
#2
one i wrote from scratch using your socket server code from tinymud for dev c++, and portions of code from the original version i wrote for dos in borland c++ 4.5 for the majorbbs platform.

i am using the borland c++ 5.5.1 compiler.
Australia Forum Administrator #3
Right, well I wouldn't embed codes like ESC [1;37m into your messages. Surely that will be hard to maintain later?

Devise a system where you use &R for red and &G for green, etc. and then do a find-and-replace of those of the actual codes for the colour. Or if the player doesn't want colour, replace them with nothing.
#4
yeah i see your point. i was playing with something like this in java a few months ago where i codes strings, like so:

"{RED}The %s attacked you for %d damage!{nor}"
"{red}There is a black dragon here.{nor}"

uppercase colors were bright
lowercase was dark.
nor was default grey color 0;37m

yeah i should do that again before i get too far and its a day process just removing em all.
Germany #5
I created tags like {red}, {blue}, {green}, etc, for my mud, too. But in practice I found them a bit longwinded, and ended up using ^r, ^b, ^g, etc.

However if you plan to use extended ANSI colour, one character is unlikely to be enough - ^r and ^R is fine for dark red and bold red, but how do you intuitively represent five shades of red with just one character?

Now would also be the time to decide if you wish to support 24-bit colour through MXP, because that uses opening and closing tags, and if you want to remain backward compatible with 256 colours and 16 colours, it's likely that you'll want a single generic implementation that can apply to all three approaches.

Amended on Fri 18 Nov 2011 11:35 AM by KaVir
Germany #6
Quote:

but how do you intuitively represent five shades of red with just one character?


maybe somwthing like ^0r, ^1r, ^2r etc. ? with just 2 characters...
Australia #7
KaVir said:

However if you plan to use extended ANSI colour, one character is unlikely to be enough - ^r and ^R is fine for dark red and bold red, but how do you intuitively represent five shades of red with just one character?

Now would also be the time to decide if you wish to support 24-bit colour through MXP, because that uses opening and closing tags, and if you want to remain backward compatible with 256 colours and 16 colours, it's likely that you'll want a single generic implementation that can apply to all three approaches.


Damn... this was going to be the first thing I attempted with TinyMud, with just simple telnet colors, but now you've got me thinking KaVir... and I'm so confuzzled!
Germany #8
Trask said:
Damn... this was going to be the first thing I attempted with TinyMud, with just simple telnet colors, but now you've got me thinking KaVir... and I'm so confuzzled!

You could try taking a look at my protocol snippet for inspiration: http://www.mudbytes.net/file-2811

It uses the tab character to indicate the start of a colour sequence, but you could easily change it an "&" (or whatever else you prefer). You could then use either the short form "&B" (bright blue), "&r" (dark red), "&O" (bright orange), etc. Or you could give an RGB value like "&[B210]" (dark brown background), "&[F010]" (very dark green foreground), etc.

Note that the snippet only uses 16 and 256 colours. However it does also support MXP, so you could fairly easily extend it to use 16.8 million colours if you wished.
Australia #9
Thanks KaVir, I'll take a look at that snippet now.