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