egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Colour and formatting codes

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Tcl FAQ
View previous topic :: View next topic  
Author Message
ppslim
Revered One


Joined: 23 Sep 2001
Posts: 3914
Location: Liverpool, England

PostPosted: Mon Mar 10, 2003 7:48 am    Post subject: Colour and formatting codes Reply with quote

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
Quote:

\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
Quote:

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:

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.
_________________
PlusNet Supported Customer - Low cost UK ISP services
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
YooHoo
Owner


Joined: 13 Feb 2003
Posts: 939
Location: Redwood Coast

PostPosted: Thu Sep 02, 2004 2:55 pm    Post subject: Reply with quote

Link for ASCII table is broke Sad
_________________
Mr. Green
Johoho's TCL for beginners
Mr. Green
Back to top
View user's profile Send private message Send e-mail
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Mon Sep 06, 2004 1:24 am    Post subject: Reply with quote

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.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Fri Feb 15, 2008 8:39 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Feb 16, 2008 2:29 am    Post subject: Reply with quote

Bug, or feature..Depending on POV.
Back to top
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Wed May 07, 2008 12:42 pm    Post subject: Reply with quote

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:

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
Back to top
View user's profile Send private message
dwickie
Halfop


Joined: 21 Aug 2004
Posts: 76
Location: /pub/beer

PostPosted: Wed May 07, 2008 1:17 pm    Post subject: Reply with quote

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:

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)
Back to top
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Wed May 07, 2008 2:01 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
dwickie
Halfop


Joined: 21 Aug 2004
Posts: 76
Location: /pub/beer

PostPosted: Wed May 07, 2008 2:43 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Wed May 07, 2008 5:02 pm    Post subject: Reply with quote

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]
Back to top
View user's profile Send private message
dwickie
Halfop


Joined: 21 Aug 2004
Posts: 76
Location: /pub/beer

PostPosted: Wed May 07, 2008 5:11 pm    Post subject: Reply with quote

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..
Back to top
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Wed May 07, 2008 5:16 pm    Post subject: Reply with quote

Didn't test before i answered! I see it now.Hmm
Back to top
View user's profile Send private message
jurist111
Voice


Joined: 26 Aug 2010
Posts: 20
Location: pakistan

PostPosted: Sat Oct 23, 2010 8:15 pm    Post subject: hi Reply with quote

Code:

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
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Chymookie
Voice


Joined: 28 Mar 2016
Posts: 2
Location: Fungeon

PostPosted: Sun Apr 10, 2016 6:08 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Tcl FAQ All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber