What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Replace Colour Codes

Pages: (3): « First « 1 2 [ 3 ] Last »
Replace Colour Codes
Author: Message:
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
O.P. RE: Replace Colour Codes
quote:
Originally posted by Shondoit
Actually, you need to replace [/c] with ·$, because ·$1 will give you black, not the standard color (But that'll give problems with a number after it)

I thought black was the default colour... im sure i can make it use double digits for numbers less than 10 :p
<Eljay> "Problems encountered: shit blew up" :zippy:
09-08-2006 10:43 PM
Profile PM Find Quote Report
Shondoit
Full Member
***

Avatar
Hmm, Just Me...

Posts: 227
Reputation: 15
35 / Male / Flag
Joined: Jul 2006
RE: Replace Colour Codes
I have purple as standard font color

I would really like to know how you'd do that (make it use double digits) if you're still gonna use RegExp's
My scripts:                            [Image: shondoit.gif]
+ Timezone
+ Camelo
+ Multisearch
09-08-2006 10:49 PM
Profile PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
O.P. RE: Replace Colour Codes
Use a seperate function to check for ·$ and then find the number, if it's less than 10 add a 0 in front of it... not gonna be easy I don't think but it should work (I think :S)
<Eljay> "Problems encountered: shit blew up" :zippy:
09-08-2006 10:51 PM
Profile PM Find Quote Report
Shondoit
Full Member
***

Avatar
Hmm, Just Me...

Posts: 227
Reputation: 15
35 / Male / Flag
Joined: Jul 2006
RE: Replace Colour Codes
I think it shouldn't work...

How would you tell the difference between ·$1 and the text 5 dollar after it and ·$25 with the text dollar after it?

You have the same problem as you had before :S
My scripts:                            [Image: shondoit.gif]
+ Timezone
+ Camelo
+ Multisearch
09-08-2006 10:53 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: Replace Colour Codes
quote:
Originally posted by SpunkyLoveMuff
quote:
Originally posted by Eljay
quote:
Originally posted by SpunkyLoveMuff
Also, someone said there were a particular amount of colours (I think they said 62), I counted 54
there are 67 colours.
Using the Format Codes button in the Display Name changer section of MSN gives a total of 56 colours to use ranging from 0 to 55 and then it uses hex codes to fill in the gaps from what I can tell...
again, it is actually not a matter of what is supported, it is a matter of what is allowed on the command line. And that is actually a number ranging from 0 to 99 (also for irc color codes).

(and there are 68 different colors defined by an index)

attached the whole list in RGB (hexadecimal)


quote:
Originally posted by Shondoit
quote:
Originally posted by CookieRevised
The request was to replace bbcode color codes, so they don't exist anymore in the string. This means if a gradient is done, that code should be replaced too (with whatever) and not be left in because "irc codes don't support gradients".
I removed them already, didn't I?
Yes, but now normal colors aren't replaced with your reg.exp.....

This is because you forgot a "?". And the non-capturing match (?:xxx) can be used, but isn't needed. You could capture the match/grouping, you only don't use it in the text to replace with. In fact if you use capturing matching/grouping, you could use this match to calculate your gradient in IRC style codes and replace match $2 (the text) with the proper gradient colors if you wish.


quote:
Originally posted by Shondoit
quote:
Originally posted by CookieRevised
2) the irc codes should contain 2 digits, not 1. 1 digit is possible to use, but may conflict with the actual string you try to color if it begins with a number. Same for backgrounds.
True, and I have no idea how to do this :S... unfortunately you can't check during the 'replace' call... But it should be possible, just have to take a closer look into it...
Yes you can check during a replacement. The 'replacetext' (thus the "·\$$$1$2·\$" in your reg.exp.) can be a function. That's the big power of the replace function:
quote:
Originally posted by CookieRevised
quote:
Originally posted by SpunkyLoveMuff
I'm adding an option to turn this function on and off so that there is always an alternative method.
instead of doing such a workaround it would be relativly easy to put a 0 in front of the singel digit numbers (as it should be anyways) by making the text used to replace as a function.



quote:
Originally posted by SpunkyLoveMuff
quote:
Originally posted by Shondoit
quote:
Originally posted by SpunkyLoveMuff
Yeah, I just needed [c=?] replaced with ·$? and I changed all the [/c] tags to ·$1.
Actually, you need to replace [/c] with ·$, because ·$1 will give you black, not the standard color (But that'll give problems with a number after it)
I thought black was the default colour...
The default color is whatever you set it to be in Messenger.

Also note that the actual format reset code is: "·0", not "·$". However, to only reset the colors to the default (and not the bold etc), you indeed must use "·$".


quote:
Originally posted by SpunkyLoveMuff
Use a seperate function to check for ·$ and then find the number, if it's less than 10 add a 0 in front of it... not gonna be easy I don't think but it should work (I think :S)
nope, see code below.






PS: to be very specific, what I said about those 53 characters after a hexadecimal color value is not entirly true. If there is a "]" in those 53 characters, the color tag is obviously ended, so that might comprimise coloring.

eg: [c=#FF00FF h]ello ]boo[/c]

the "h]ello" will not be entirly interpreted as being part of those 53 character long redundant text.

However!!! if the redundant text contains a complete set of color coding tags, they are ignored:

[c=#FF00FF  [c=3]hello[/c]  ]boo[/c]

here "[c=3]hello[/c]" will actually be ignored. This is because Plus! first parses the deepest nested color tags and then builds the string upwards. So while parsing "[c=3]hello[/c]", this is replaced with colors. Then [c=#FF00FF] is parsed, but since that colored "hello" string is now part of those redundant characters, it will be ignored.

To also accomplish this in our code too with need to use a positive lookahead match (?=xxxx) for those redundant characters. See code below.





The below code will:
1) replace color indexes (0 to 99)
2) replace hexadecimal color values
3) add a leading zero only if there is 1 digit as color index and the text between the color tags will conflict with the set color
4) ignore those 53 possible characters after a hexadecimal color value
5) adds a space after the reset code only if the text after the closing color tag will conflict with it.
6) can easly be adapted to include gradient converting

note that the below code is actually just 1 replace function!!

code:
var strMyNewPSM = "Hello[c=#123456blah]test[/c=3] [c=4]5555[/c] [c=4]red[/c]";

strMyNewPSM = strMyNewPSM.replace(
        /\[c=(\d{1,2}|#[0-9A-F]{6}(?=.{0,53}))\](.*?)\[\/c(?:=(\d{1,2}|#[0-9A-F]{6}(?=.{0,53})))?\]/gi,
        function (m0, m1, m2, m3, m4, m5) {
          // m0 = the complete substring that matched
          // m1 = capture 1: color value in the opening tag ([c=?])
          // m2 = capture 2: text between the color tags
          // m3 = capture 3: color value in the closing tag ([/c=?])
          // m4 = the offset where the match (m0) occured
          // m5 = entire string object

          var regConflict = /^,?(\d|#[0-9A-F]{6})/i;

          // add leading 0 if color value is only 1 digit and the text
          // between the color tags could conflict with the set color
          if (m1.length === 1 && regConflict.test(m2)) m1 = "0" + m1;
         
          var replacetext = "·$" + m1 + m2 + "·$"
 
          // check if the text that comes after the matching substring (m0)
          // wont conflict with the color reset code. if so, add a space
          // after the replacetext to avoid forcing a color value 
          if (regConflict.test(m5.substr(m0.length + m4))) replacetext += " ";

          // return the text to replace with
          return replacetext;
        }
      )

Debug.Trace(strMyNewPSM);
PS: remember that there is also another type of codes for colors. This code are the internal control characters used by Plus!. They were also used in plugins.

eg: to set a color you can use the ascii code 3. So this shortens the "·$" code to even only 1 character.

To adapt the above script with this, replace all "·$" with "\x03".

control ascii character for color ( ·$ ): 0x3
control ascii character for bold ( ·# ): 0x2
control ascii character for italic ( ·& ): 0x5
control ascii character for underlined ( ·@ ) : 0x1f
control ascii character for strikeout ( ·' ): 0x6
control ascii character for format reset ( ·0 ): 0xf



.txt File Attachment: MsgPlus Palette.txt (925 bytes)
This file has been downloaded 282 time(s).

This post was edited on 09-09-2006 at 02:59 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-09-2006 02:08 AM
Profile PM Find Quote Report
Pages: (3): « First « 1 2 [ 3 ] Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On