[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  Programming
. -> [Folder]  General
. . -> [Subject]  Adding ANSI color

Adding ANSI color

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Daniel Spain   (15 posts)  [Biography] 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");
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,986 posts)  [Biography] 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
[Go to top] top

Posted by Daniel Spain   (15 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,986 posts)  [Biography] 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
[Go to top] top

Posted by Daniel Spain   (15 posts)  [Biography] 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.
[Go to top] top

Posted by KaVir   Germany  (117 posts)  [Biography] 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.

[Go to top] top

Posted by Erendir   Germany  (47 posts)  [Biography] 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...
[Go to top] top

Posted by Trask   Australia  (23 posts)  [Biography] 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!
[Go to top] top

Posted by KaVir   Germany  (117 posts)  [Biography] 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.
[Go to top] top

Posted by Trask   Australia  (23 posts)  [Biography] 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.
[Go to top] 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.


24,626 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] 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.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]