Gammon Forum
Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
Programming
General
Adding ANSI color
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Daniel Spain
(15 posts) bio
|
Date
| Thu 17 Nov 2011 07:56 AM (UTC) |
Message
| 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[1;37m");
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. | top |
|
Posted by
| Nick Gammon
Australia (23,042 posts) bio
Forum Administrator |
Date
| Reply #1 on Thu 17 Nov 2011 06:27 PM (UTC) |
Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Daniel Spain
(15 posts) bio
|
Date
| Reply #2 on Fri 18 Nov 2011 03:17 AM (UTC) |
Message
| 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. | top |
|
Posted by
| Nick Gammon
Australia (23,042 posts) bio
Forum Administrator |
Date
| Reply #3 on Fri 18 Nov 2011 03:40 AM (UTC) |
Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Daniel Spain
(15 posts) bio
|
Date
| Reply #4 on Fri 18 Nov 2011 05:36 AM (UTC) |
Message
| 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.
| top |
|
Posted by
| KaVir
Germany (117 posts) bio
|
Date
| Reply #5 on Fri 18 Nov 2011 10:03 AM (UTC) Amended on Fri 18 Nov 2011 11:35 AM (UTC) by KaVir
|
Message
| 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.
| top |
|
Posted by
| Erendir
Germany (47 posts) bio
|
Date
| Reply #6 on Sat 19 Nov 2011 09:55 AM (UTC) |
Message
|
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... | top |
|
Posted by
| Trask
Australia (23 posts) bio
|
Date
| Reply #7 on Wed 18 Jan 2012 11:41 PM (UTC) |
Message
|
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! | top |
|
Posted by
| KaVir
Germany (117 posts) bio
|
Date
| Reply #8 on Thu 19 Jan 2012 12:29 PM (UTC) |
Message
|
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.
| top |
|
Posted by
| Trask
Australia (23 posts) bio
|
Date
| Reply #9 on Wed 25 Jan 2012 04:47 AM (UTC) |
Message
| Thanks KaVir, I'll take a look at that snippet now.
| top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
26,401 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top
Quick links:
MUSHclient.
MUSHclient help.
Forum shortcuts.
Posting templates.
Lua modules.
Lua documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.