IRC colors

Posted by Vercalos on Fri 11 Mar 2005 12:44 AM — 18 posts, 83,216 views.

#0
I'm currently using MUSCHclient to connect to an IRC channel, and now I'm trying to get color to work. Any suggestions on how to get the client to recognize the colors, or convert IRC to ANSI?
Russia #1
Well, I'd say (as I often do lately): filter packets in OnPluginPacketReceive, replacing IRC codes with their ANSI equivalents. I don't know anything about the specifics of IRC though, do you have any links to the specification or something of that kind?
#2
Not that I can think of.
USA #3
How about taking a look at packet-debug. It'll let you know what you need to match on.

However, the second google link comes up with this:
http://www.visualirc.net/tech-attrs.php

Which seems like what you're looking for.
#4
Yeah, but I honestly don't know how to script it.
The most advanced stuff I've ever worked on are triggers, and the most advanced script I've ever done I can't even remember how I did, and it was just a counter.
Amended on Fri 11 Mar 2005 05:48 AM by Vercalos
Russia #5
Scripting it isn't much of a problem, but I am too lazy to go find an IRC server, connect to it and log some output. So turn on Packet Debug (under File menu, I think) and log for awhile, then post it back here. That way we can see what the codes look like and compare them with the specs (which don't make much sense without concrete examples).
#6
Umm.. Where do you get the logs?
USA #7
Edit > Debug Packets (Ctrl-Alt-F11)

Then you have to un-maximize your main world (since it doesn't come to front) and you'll see it. Just copy/paste (or save to a file, or whatnot).
#8
Here are a few packets.

Incoming packet: 361 (72 bytes)

:Jen!dowie@p1647 3a 4a 65 6e 21 64 6f 77 69 65 40 70 31 36 34 37
-apx1.akl.ihug.c 2d 61 70 78 31 2e 61 6b 6c 2e 69 68 75 67 2e 63
o.nz PRIVMSG #Cl 6f 2e 6e 7a 20 50 52 49 56 4d 53 47 20 23 43 6c
anBOB :.13why co 61 6e 42 4f 42 20 3a 03 31 33 77 68 79 20 63 6f
lours?.. 6c 6f 75 72 73 3f 0d 0a

Incoming packet: 362 (81 bytes)

:ComradeZoo!hotm 3a 43 6f 6d 72 61 64 65 5a 6f 6f 21 68 6f 74 6d
ail@S01060004e23 61 69 6c 40 53 30 31 30 36 30 30 30 34 65 32 33
4dbbe.cg.shawcab 34 64 62 62 65 2e 63 67 2e 73 68 61 77 63 61 62
le.net PRIVMSG # 6c 65 2e 6e 65 74 20 50 52 49 56 4d 53 47 20 23
ClanBOB :or fly. 43 6c 61 6e 42 4f 42 20 3a 6f 72 20 66 6c 79 0d
. 0a

Sent packet: 67 (113 bytes)

privmsg #clanbob 70 72 69 76 6d 73 67 20 23 63 6c 61 6e 62 6f 62
:I'm trying to 20 3a 49 27 6d 20 74 72 79 69 6e 67 20 74 6f 20
get an output lo 67 65 74 20 61 6e 20 6f 75 74 70 75 74 20 6c 6f
g so that I can 67 20 73 6f 20 74 68 61 74 20 49 20 63 61 6e 20
write up a scrip 77 72 69 74 65 20 75 70 20 61 20 73 63 72 69 70
t so I can actua 74 20 73 6f 20 49 20 63 61 6e 20 61 63 74 75 61
lly see colors.. 6c 6c 79 20 73 65 65 20 63 6f 6c 6f 72 73 2e 0d
. 0a

Incoming packet: 363 (76 bytes)

:Jen!dowie@p1647 3a 4a 65 6e 21 64 6f 77 69 65 40 70 31 36 34 37
-apx1.akl.ihug.c 2d 61 70 78 31 2e 61 6b 6c 2e 69 68 75 67 2e 63
o.nz PRIVMSG #Cl 6f 2e 6e 7a 20 50 52 49 56 4d 53 47 20 23 43 6c
anBOB :.11having 61 6e 42 4f 42 20 3a 03 31 31 68 61 76 69 6e 67
problems?.. 20 70 72 6f 62 6c 65 6d 73 3f 0d 0a
Greece #9
IRC is RFC 1459 by the way, if you need it.
Russia #10
Check if this works. It's supposed to go into a text file named "IRC2ANSI.xml" saved in your default Plugins folder, and then needs to be installed through File->Plugins


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, March 05, 2005, 6:39 AM -->
<!-- MuClient version 3.65 -->

<!-- Plugin "ANSI_Escape" generated by Plugin Wizard -->

<muclient>
<plugin
   name="IRC2ANSI"
   author="Keldar"
   id="7eabd2446981b4760d0db8f4"
   language="VBscript"
   purpose="Converting IRC colour codes to ANSI ones"
   save_state="y"
   date_written="2005-03-12"
   requires="3.65"
   version="1.0"
   >

</plugin>


<!--  Script  -->

<script>
<![CDATA[
dim reg, codes
Set reg = New RegExp
reg.Pattern = "\x03(\,([0-9][0-5]?|)|([0-9][0-5]?)(\,([0-9][0-5]?|)|)|\,|)"
reg.Global = True

set code = CreateObject("Scripting.Dictionary")
code.Add "0", chr(&H1b) & "[1m" & chr(&H1b) & "[37m"
code.Add "1", chr(&H1b) & "[30m"
code.Add "2", chr(&H1b) & "[34m"
code.Add "3", chr(&H1b) & "[32m"
code.Add "4", chr(&H1b) & "[1m" & chr(&H1b) & "[31m"
code.Add "5", chr(&H1b) & "[31m"
code.Add "6", chr(&H1b) & "[35m"
code.Add "7", chr(&H1b) & "[33m"
code.Add "8", chr(&H1b) & "[1m" & chr(&H1b) & "[33m"
code.Add "9", chr(&H1b) & "[1m" & chr(&H1b) & "[32m"
code.Add "10", chr(&H1b) & "[36m"
code.Add "11", chr(&H1b) & "[1m" & chr(&H1b) & "[36m"
code.Add "12", chr(&H1b) & "[1m" & chr(&H1b) & "[34m"
code.Add "13", chr(&H1b) & "[1m" & chr(&H1b) & "[35m"
code.Add "14", chr(&H1b) & "[1m" & chr(&H1b) & "[30m"
code.Add "15", chr(&H1b) & "[37m"

set bcode = CreateObject("Scripting.Dictionary")
bcode.Add "0", chr(&H1b) & "[1m" & chr(&H1b) & "[46m"
bcode.Add "1", chr(&H1b) & "[39m"
bcode.Add "2", chr(&H1b) & "[43m"
bcode.Add "3", chr(&H1b) & "[41m"
bcode.Add "4", chr(&H1b) & "[1m" & chr(&H1b) & "[40m"
bcode.Add "5", chr(&H1b) & "[40m"
bcode.Add "6", chr(&H1b) & "[44m"
bcode.Add "7", chr(&H1b) & "[42m"
bcode.Add "8", chr(&H1b) & "[1m" & chr(&H1b) & "[42m"
bcode.Add "9", chr(&H1b) & "[1m" & chr(&H1b) & "[41m"
bcode.Add "10", chr(&H1b) & "[45m"
bcode.Add "11", chr(&H1b) & "[1m" & chr(&H1b) & "[45m"
bcode.Add "12", chr(&H1b) & "[1m" & chr(&H1b) & "[43m"
bcode.Add "13", chr(&H1b) & "[1m" & chr(&H1b) & "[44m"
bcode.Add "14", chr(&H1b) & "[1m" & chr(&H1b) & "[39m"
bcode.Add "15", chr(&H1b) & "[46m"

function OnPluginPacketReceived(packet)
	dim matches, match, subst
	set matches = reg.Execute(packet)
	for each match in matches
		if (match.SubMatches(0) = "") or (match.SubMatches(0) = ",") and ( len(match.SubMatches(0)) < 2 ) then
			subst = chr(&H1b) & "[0m"
		elseif ( Left(match.SubMatches(0),1) = "," ) and (match.SubMatches(1) <> "") then
			subst = chr(&H1b) & "[47m" & bcode.Item(match.SubMatches(1))
		elseif match.SubMatches(3) = "," then
			subst = code.Item(match.SubMatches(2)) & chr(&H1b) & "[49m"
		elseif match.SubMatches(3) = "" then
			subst = code.Item(match.SubMatches(2))
		else
			subst = code.Item(match.SubMatches(2)) & bcode.Item(match.SubMatches(4))
		end if
		OnPluginPacketReceived = Replace(packet, match, subst )
	next
end function

]]>
</script>


</muclient>
#11
Sorry to ask for more, but would it be possible to make a script out of this?
<triggers>
<trigger
match=":*!*@* PRIVMSG #ClanBOB :*"
omit_from_log="y"
send_to="2"
sequence="100"
other_text_colour="whitesmoke"
>
<send>&lt;%1&gt; %4</send>
</trigger>
</triggers>



Oh and the script didn't work. It turned all the text black and bled. I'm not sure if it's even possible to convert them efficiently, if at all, considering the variations. I think you'd have to know IRC and Mushclient scripting inside and out to actually be able to do it.
Amended on Sat 12 Mar 2005 09:41 AM by Vercalos
Russia #12
What's the address and port of the server you are using? And the whole procedure of connecting to it? I'll check what the problem is with it.
Russia #13
This version works, although not perfectly. The main problem is that IRC defines 16 default colours, while ANSI only has 8, so it looks awkward sometimes. Originally I tried making up for the missing 8 colours using bold, but that looks even uglier. I'll try to do it with MXP if I have time later.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, March 05, 2005, 6:39 AM -->
<!-- MuClient version 3.65 -->

<!-- Plugin "ANSI_Escape" generated by Plugin Wizard -->

<muclient>
<plugin
   name="IRC2ANSI"
   author="Keldar"
   id="7eabd2446981b4760d0db8f4"
   language="VBscript"
   purpose="Converting IRC colour codes to ANSI ones"
   save_state="y"
   date_written="2005-03-12"
   requires="3.65"
   version="1.1"
   >

</plugin>


<!--  Script  -->

<script>
<![CDATA[
dim reg, codes
Set reg = New RegExp
reg.Pattern = "(?:\x02|\x15|\x18|\x29|\x31|\x03(\,([0-9][0-5]?|)|([0-9][0-5]?)(\,([0-9][0-5]?|)|)|\,|))+?"
reg.Global = True

set code = CreateObject("Scripting.Dictionary")
'code.Add "0", chr(&H1b) & "[1m" & chr(&H1b) & "[37m"
code.Add "0", chr(&H1b) & "[37m"

code.Add "1", chr(&H1b) & "[30m"
code.Add "2", chr(&H1b) & "[34m"
code.Add "3", chr(&H1b) & "[32m"
'code.Add "4", chr(&H1b) & "[1m" & chr(&H1b) & "[31m"
code.Add "4", chr(&H1b) & "[31m"

code.Add "5", chr(&H1b) & "[31m"
code.Add "6", chr(&H1b) & "[35m"
code.Add "7", chr(&H1b) & "[33m"

'code.Add "8", chr(&H1b) & "[1m" & chr(&H1b) & "[33m"
code.Add "8", chr(&H1b) & "[33m"

'code.Add "9", chr(&H1b) & "[1m" & chr(&H1b) & "[32m"
code.Add "9", chr(&H1b) & "[32m"

code.Add "10", chr(&H1b) & "[36m"
'code.Add "11", chr(&H1b) & "[1m" & chr(&H1b) & "[36m"
code.Add "11", chr(&H1b) & "[36m"

'code.Add "12", chr(&H1b) & "[1m" & chr(&H1b) & "[34m"
code.Add "12", chr(&H1b) & "[34m"

'code.Add "13", chr(&H1b) & "[1m" & chr(&H1b) & "[35m"
code.Add "13", chr(&H1b) & "[35m"

'code.Add "14", chr(&H1b) & "[1m" & chr(&H1b) & "[30m"
code.Add "14", chr(&H1b) & "[30m"

code.Add "15", chr(&H1b) & "[37m"

dim bcode
set bcode = CreateObject("Scripting.Dictionary")
'bcode.Add "0", chr(&H1b) & "[1m" & chr(&H1b) & "[47m"
bcode.Add "0", chr(&H1b) & "[47m"
bcode.Add "1", chr(&H1b) & "[40m"
bcode.Add "2", chr(&H1b) & "[44m"
bcode.Add "3", chr(&H1b) & "[42m"
'bcode.Add "4", chr(&H1b) & "[1m" & chr(&H1b) & "[41m"
bcode.Add "4", chr(&H1b) & "[41m"

bcode.Add "5", chr(&H1b) & "[41m"
bcode.Add "6", chr(&H1b) & "[45m"
bcode.Add "7", chr(&H1b) & "[43m"
'bcode.Add "8", chr(&H1b) & "[1m" & chr(&H1b) & "[43m"
bcode.Add "8", chr(&H1b) & "[43m"

'bcode.Add "9", chr(&H1b) & "[1m" & chr(&H1b) & "[42m"
bcode.Add "9", chr(&H1b) & "[42m"

bcode.Add "10", chr(&H1b) & "[46m"
'bcode.Add "11", chr(&H1b) & "[1m" & chr(&H1b) & "[46m"
bcode.Add "11", chr(&H1b) & "[46m"

'bcode.Add "12", chr(&H1b) & "[1m" & chr(&H1b) & "[44m"
bcode.Add "12", chr(&H1b) & "[44m"

'bcode.Add "13", chr(&H1b) & "[1m" & chr(&H1b) & "[45m"
bcode.Add "13", chr(&H1b) & "[45m"
'bcode.Add "14", chr(&H1b) & "[1m" & chr(&H1b) & "[40m"
bcode.Add "14", chr(&H1b) & "[40m"
bcode.Add "15", chr(&H1b) & "[47m"

dim inverse, italic, bold, underline
inverse = vbFalse
italic = vbFalse
bold = vbFalse
underline = vbFalse

function OnPluginPacketReceived(packet)
	dim matches, match, subst
	set matches = reg.Execute(packet)
	for each match in matches
		if match = chr(&H03) then
			subst = chr(&H1b) & "[0m"
		elseif match = chr(&H02) then
			if bold then
				bold = vbFalse
				subst = chr(&H1b) & "[22m"
			else
				bold = vbTrue
				subst = chr(&H1b) & "[1m"
			end if
		elseif match = chr(&H15) then
			subst = chr(&H1b) & "[1m"
		elseif match = chr(&H18) then
			if inverse then
				inverse = vbFalse
				subst = chr(&H1b) & "[7m"
			else
				inverse = vbTrue
				subst = chr(&H1b) & "[27m"
			end if
		elseif match = chr(&H29) then
			if italic then
				italic = vbFalse
				subst = chr(&H1b) & "[5m"
			else
				italic = vbTrue
				subst = chr(&H1b) & "[25m"
			end if
		elseif match = chr(&H31) then
			if underline then
				underline = vbFalse
				subst = chr(&H1b) & "[4m"
			else
				underline = vbTrue
				subst = chr(&H1b) & "[24m"
			end if
		elseif ( Left(match.SubMatches(0),1) = "," ) and (match.SubMatches(1) <> "") then
			subst = chr(&H1b) & "[39m" & bcode.Item(match.SubMatches(1))
		elseif match.SubMatches(3) = "," then
			subst = code.Item(match.SubMatches(2)) & chr(&H1b) & "[49m"
		elseif match.SubMatches(3) = "" then
			subst = code.Item(match.SubMatches(2))
		else
			subst = code.Item(match.SubMatches(2)) & bcode.Item(match.SubMatches(4))
		end if
		packet = Replace(packet, match, subst,1, 1)
	next
	OnPluginPacketReceived = packet
end function

]]>
</script>


USA #14
Why uglier? Because Nick incorrectly set it to use 'bold' as both a color and font attribute? If so, just turn off the setting for that. Imho, its not the behaviour it should be producing anyway and it *is* ugly.
Russia #15
But if bold doesn't effect colour then it still won't be possible to use it to emulate the missing colours. If it doesn't effect the font weight then the bold tags can't be reproduced. I think it's more of an ANSI problem than anything.
#16
Hmm.. I seem remember something within MUSHclient, simply using triggers, where one could define custom colors.. I'm not sure how that works however.. I'll check the help file and see what it says, then post any details I can.

RGB colours

Triggers and scripts can also use the full RGB colour gamut - which is 256 (red) X 256 (green) X 256 (blue) colour combinations (a total of 16,777,216 possible colours). This allows for a wide range of colour presentation. In a trigger select the "other..." item from the colour combo-box. In scripts you can use things like world.ColourNote to send messages to the window in any colour.

Mapping colours

From version 3.54 onwards you can also "map" one colour to another. This is provided to allow you to customise MXP colours which do not otherwise have a mechanism for being displayed differently. See the MapColour function for more details. This allows you to have a "last moment" mapping of a colour (that you don't like) to a different colour (that you prefer).

I can post more details for script functions, but just look at the "Colour Management" for a hotlinked list of functions
Amended on Mon 14 Mar 2005 04:07 AM by Vercalos
USA #17
My point Ked was that 'bold' means different things when talking about ansi and font tags. Making the ansi attribute trigger the bold attribute therefor does not make sense in the first place. The ansi attribute could have been called, "emphasize", "high visibility", "stand out", "bright" or just about anything similar, since that was at the time the only way to do it, but 'bold' was an unfortunate and, once true fonts existed, badly misleading name for it. But we already covered why that 'feature' of having it do both in Mushclient being turned on, or possibly even existing at all with an ansi mud, is not correct, in a seperate thread. I am not clear what you mean by disabling it causing 'tags' to stop working..? Ansi tags (codes rather) do not have a 'font' bold, just a 'color' bold and MXP is a seperate system not effected by the ansi settings and what they do.