This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Colour and formatting codes

Issues often discussed about Tcl scripting. Check before posting a scripting question.
Post Reply
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Colour and formatting codes

Post by ppslim »

While not strictly a Tcl FAQ, it has been asked many times, with regards to use within Tcl scripts.

Formatting codes, are used by IRC clients, to produce a more readable format, by changing text to and from bold, underline, colour (both font and background colours) and reversed text.

Most, but not all, clients support this, and some support it differently to others.

Additionally, some clients support more than the codes listed below, however, I will point out, only the ones that are relevant.

Most of this topic will relate to how mIRC functions, seeing how this is the more widely used client. Should any issues regarding “other client” support be noted, you should point these out in a reply, as they may likely be asked in the future.

Bold text

Client support
This is produces using the CTRL+B control code, by literally holding down the CTRL key, and tapping B.

ASCII character
The bold character has a octal value of 2, but is represented as 002.

As with all the characters, simply typing 002 isn’t enough, as this will only produce the characters 0, 0 and 2. Instead, you have to escape the code, so that Tcl knows, to translate them into the correct coding.

This is done, using the Tcl escape code, which is a simple \ (backslash).

Start and stop
You set the start and end points of the formatting, by using one code to start, and one to stop. These are placed in the text string at the required points.

Example
Code:
\002Hello\002 to all

Output
Hello to all

Underline text

Client support
This is produced using the CTRL+U control code, by literally holding the CTRL key, and tapping U.

ASCII character
The underline character has a octal value of 37, but is represented as 037.

Start and stop
You set the start and end points of the formatting, by using one code to start, and one to stop. These are placed in the text string at the required points.

Example
Code:
This is how to produce a \037EXAMPLE\037 of the underline character

Output:
This is how to produce a EXAMPLE of the underline character

Reversed/italic text

Client support
In mIRC: Produced using CTRL+R, causes text to show in reverse.

This means, the font and background colours are switched.
IE, Red text, or a black background causes, black text on a red background.

Other clients: This produces the text in italic’s/stressed look.

This doesn’t apply to all other clients, as some may act like mirc.

ASCII character
This control code uses the code 26, represented as 026.

Start and stop
You set the start and end points of the formatting, by using one code to start, and one to stop. These are placed in the text string at the required points.

Example
Code:
Here is an \026EXAMPLE\026 of the output

Output other:
Here is an EXAMPLE of the output
Output mIRC:
Forum doesn’t have the formatting codes for this, I may add a image for this later

Normal text

Client support
This is produced using the CTRL+O code, and causes text to return to client default formatting.

Thus, if a script is in use on the client, to produce formatting on the screen, this will bypass this formatting, to use the client default colours, weight and decoration.

ASCII character
This code uses octal value 17, represented as 017

Start and stop
mIRC: This can be turned on and off, like in the above examples.

Other clients: This may be a one off code, where all counters are reset, and no formatting will be used, until the next control character is parsed.

Example
Code:
Here is an example of \017normalised text

Output:
There is no real way to show an example on the forum, and I may create an image later

CTCP Delimiter

Client support
All clients will support this. In most clients, you use a CTCP command to create the correct output.

ASCII character
The CTCP character uses decimal code 1, represented as 001. The order and commands used with this character are important, and are mainly beyond this document.

In brief, the CTCP protocol, is a sub-protocol of IRC (RFC 1459). It was produced after the IRC protocol, to extend the abilities of clients, and to allow structured data/requests to be made, in a fashion, that doesn’t break existing clients, and doesn’t interfere with regular data.

More technical details on what it is used for, and how you should use it, is available in The Client-to-Client Protocol (CTCP) specification

Start and stop
As noted, the position of this code is important.

The very first character of a line, needs to be the CTRL code, starting the code. The very last character needs to be the CTRL code, ending it.

This, it may only ever be the first or the last character, with none in between.

Any arguments to send, need to be enclosed between the codes.

Note: While not to do with start and stop, there is one more thing to note.

CTCP requests are made, using the PRIVMSG command, and any reply, should be sent via the NOTICE command.

CTCP commands/messages take the following format
\001<COMMAND>[ <SPACE> <ARGUMENT> [ARGUMENSTS]]\001
This means the COMMANDS can be on its own. If there are arguments to send, sererate each by a space, then terminate with a CTCP control character.

Some of the default suported characters are
PING - Measure the round trip through IRC servers.
ERROR - Tell a client of errornouse information. Can be used like echo below.
FINGER - Get information about a single client, much like the finger protocol.
ECHO - Simalar to ping, however, you can send text with this.
TIME - Get information about the current time/date and timezone for a user.
DCC - DCC chat, send and fserve requests (and others on supported clients) are initilised through the CTCP protocol.
Example
Code:
\001PING 11235465\001

Output:
No example possible

Colour control

Client support
Most clients support this code, and within mIRC, is generated using the CTRL+K combination.

ASCII character
This code uses decimal value 3, represented as 003

Start and stop/examples
Colour control codes are both simple, and complex. They allow you to change the foreground colour (font) and background colour (though some clients to not support it, they will accept the code never the less). I will role the example section into this.

There are three ways to represent the colour code.

\003
\003FF
\003FF,BB

Where FF means “Forground colour” and BB means “Background colour”, these are separated using a comma (,).

The colours codes, can be both single and/or double digits, if the first one if to be 0.

As with normal codes, you stop the formatting using the code at the required stop point, without any arguments.

Both FF and BB are made up of single, or 2 digit codes, that correspond to 1 of 16 colours (mIRC has a 17th, with a special meaning).

Here is a list of the colour names, as defined by the mIRC help documents.

Code: Select all

0-	White
1-	Black
2-	Blue
3-	Green
4-	Light Red
5-	Brown
6-	Purple
7-	Orange
8-	Yellow
9-	Light Green
10-	Cyan
11-	Light Cyan
12-	Light Blue
13-	Pink
14-	Grey
15-	Light Grey
However, other clients are known to use different codes for the colours.

In mIRC, the 17th colour is number 99, and means transparent, allowing text to blend in with the background, regardless of what colour is in use behind the character, and even better, allowing the character to bleed across colours, without being shown.

From this, we can do the following.

Make text red:
\00304Hello
\0034Hello

Yellow text on red background:
\00308,04Hello
\0038,04Hello
\00308,4Hello
\0038,4Hello

There is one small area to watch out for, when changing between colours, in one line of text. Unless you kill the colour formatting with a single code, or specifically force a background colour, the text will inherit the background colour, from the previous code.

EG
\00300,01Hello \00301to you
and
\00300,01Hello \003\00301to you

These are totally different
In the first case, the word “Hello” is “White on black”, and “to you” is “black on black”, as it inherits the back background from the first code.

In the second, there is a second single colour code character before the “to you” code. This removes all colour formatting, and prevent the background colour from being inherited.

Other control code

There are other control codes available. These include Bell (decimal 7, 007), which make computer go “ding” through the speaker (however, this is usually disabled by default, and most system do not use it because of the annoyance factor).

A complete list of the ASCII table, that can be used in your scripts, is available FROM THIS LINK

Edit: Many thanks to "user" for corrections. Tcl uses octal (base 8) numbers in the escape codes, and not our standard decimal (base 10) numbers.
User avatar
YooHoo
Owner
Posts: 939
Joined: Thu Feb 13, 2003 10:07 pm
Location: Redwood Coast

Post by YooHoo »

Link for ASCII table is broke :(
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Here is a good source for ASCII Codes:
http://www.ascii.cl/htmlcodes.htm
http://www.ascii.cl/index.htm

Nevertheless, ASCII is so popular now, just type "ascii codes" on www.google.com you will instantly get one better to better website regarding ascii codes.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

In one respect, the formatting for color in the above FAQ is misleading. It implies that a single digit added to the \003 such as \0034 for foreground color red is fine. It is not. If the next digit (the first digit intended as the actual output text) happened to be numeric then it would be interpreted as part of the color code. Color codes must always be two digits long such that no such misinterpretation can occur. ie. \00304 and not \0034.

Examples :-

-----

"\00345 people perished\003"
would output nothing at all because \00345 does not exist as a color code

while

"\003045 people perished\003" would correctly output '5 people perished' in red text

-----

"\00315 people perished\003"
would output 'people perished' in light grey instead of the intended '5 people perished' in black

while

"\003015 people perished\003"
would correctly output '5 people perished' in black

-----

To be fair, if the first digit of the output text is non numeric, then the issue doesn't arise.

However, just to make the reader ever more wary of making this mistake. There will not be an error in the partyline to assist in tracing this self inflicted bug.

ALWAYS express color codes as two digit.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Bug, or feature..Depending on POV.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Want to share my experience with color codes.
this array method makes it easy for you to write your script and makes it more clean.

Code: Select all

array set colors {
blue \0032
green \0033
red \0034
purple \0036
orange \0037
yellow \0038
lightgreen \0039
lightblue \00312
pink \00313
grey \00314
lightgrey \00315
nocolor \003
bold \002
underline \037
}
foreach {color code} [array get colors] { proc $color {} "return $code" }
After this you need to set global colors
and then use [pink] [bold] [nocolor]
very useful for me. So hope you see it useful too
d
dwickie
Halfop
Posts: 76
Joined: Sat Aug 21, 2004 8:53 am
Location: /pub/beer

Post by dwickie »

ztian299 wrote:Want to share my experience with color codes.
this array method makes it easy for you to write your script and makes it more clean.

Code: Select all

array set colors {
blue \0032
green \0033
red \0034
purple \0036
orange \0037
yellow \0038
lightgreen \0039
lightblue \00312
pink \00313
grey \00314
lightgrey \00315
nocolor \003
bold \002
underline \037
}
foreach {color code} [array get colors] { proc $color {} "return $code" }
After this you need to set global colors
and then use [pink] [bold] [nocolor]
very useful for me. So hope you see it useful too
you really SHOULD use 2 digits color codes (reason why is in post above yours)
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

This don't make any sence, since the color codes only work as two digits in mIRC. It's same as in eggdrop only with \003 first
d
dwickie
Halfop
Posts: 76
Joined: Sat Aug 21, 2004 8:53 am
Location: /pub/beer

Post by dwickie »

ztian299 wrote:This don't make any sence, since the color codes only work as two digits in mIRC. It's same as in eggdrop only with \003 first
you didnt read the explanation, did you?

if you use \0034Text you'll get red text - thats ok
*BUT* if you want to colorize something with number at the begin, you have problem, for example:

\003415 Baloons

will be shown as 5 Baloons (and not "15 Baloons" in red) because there will be color code 41

just try it, if you enter higher color code than 15 in mirc, no color is used, but two digit color code is stripped, in irssi are colos repeated (code 16 is same as 0, code 17 same as 1, code 20 same as 4 etc...)


so thats why people should ALWAYS use two digit color codes for coloring variable text, that could be starting with number.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Ok, sorry..big mistake from me!
Understand you well!
But with array it could resolve the problem?
since you put
[bold]HERE[bold]

I mean this because you don't do \00341HERE
instead [color]TEXT[color]
d
dwickie
Halfop
Posts: 76
Joined: Sat Aug 21, 2004 8:53 am
Location: /pub/beer

Post by dwickie »

ztian299 wrote:Ok, sorry..big mistake from me!
Understand you well!
But with array it could resolve the problem?
since you put
[bold]HERE[bold]

I mean this because you don't do \00341HERE
instead [color]TEXT[color]
its the same, if you do [red]TEXT its ok, BUT if you do [red]15 Baloons, its WRONG again. [red] returns \0034, so result will be again wrong:

\003415 Baloons

and on irc will be again just readable "5 Baloons"

this of course happens only if you want to colorize variable text, you can use onedigit color for coloring static messages, but for coloring variables always use 2-digit. For example \00304$text\003, \00304[output]\003, etc..
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Didn't test before i answered! I see it now.Hmm
j
jurist111
Voice
Posts: 20
Joined: Thu Aug 26, 2010 8:36 am
Location: pakistan

hi

Post by jurist111 »

Code: Select all

array set colors { 
blue \0032 
green \0033 
red \0034 
purple \0036 
orange \0037 
yellow \0038 
lightgreen \0039 
lightblue \00312 
pink \00313 
grey \00314 
lightgrey \00315 
nocolor \003 
bold \002 
underline \037 
} 
foreach {color code} [array get colors] { proc $color {} "return $code" } 
where to give this colors in eggdrop .. i basically wants to create color questions i.e
blue|!react fast! Guess the color ------>
where n how i can give the color ?
it will b in question file?
or trivia tcl?
JuRiSt
User avatar
Chymookie
Voice
Posts: 2
Joined: Mon Mar 28, 2016 1:57 pm
Location: Fungeon
Contact:

Post by Chymookie »

Original Poster - this helped clarify a few things in regards to a colorfaq I was directed to that wasn't as detailed.

If there was an emote for thumbs up, or rock on - it'd be coming your way!

I'll rpost again if/when I anything comes up from using codes in regards to any scripts I learn/work on.
Post Reply