Using

Scripting

Text Formatting

In order to add text formating to strings either printed by XChat or sent to the server, you can't simply add %C or %B, instead you need to use another form, like \003 or \cB.

List of Codes

Format TypeOctal Escape CodeHexaD Escape CodeControl Escape Code
Bold\002\x02\cB
Color\003\x03\cC
Underline\037\x1F\c_
Original Color\017\x0F\cO
Reverse Color\026\x16\cV
Beep\007\x07\cG

Using Perc Colors (%O, %B) in scripts

You can use Perc Colors (%O, %B) in scripts if you use an extra function inside the script to convert the %B into \002. Following are two functions, one for Perl and one for Python that you can use, in each, obtain the value returned by colordecode("string"):

In Perl

sub colordecode {
        $_[0] =~ s/%(.)/macro_sub $1/eg;
        return ($_[0]);
}

sub macro_sub ($) {
        if    ($_[0] eq 'U') { return "\c_"; }
        elsif ($_[0] eq 'B') { return "\cB"; }
        elsif ($_[0] eq 'C') { return "\cC"; }
        elsif ($_[0] eq 'O') { return "\cO"; }
        elsif ($_[0] eq 'R') { return "\cV"; }
        elsif ($_[0] eq '%') { return '%';   }
        return '%'.$_[0];
}

In Python

def colordecode(word):
   _B = re.compile('%B', re.IGNORECASE)
   _C = re.compile('%C', re.IGNORECASE)
   _R = re.compile('%R', re.IGNORECASE)
   _O = re.compile('%O', re.IGNORECASE)
   _U = re.compile('%U', re.IGNORECASE)
   return _B.sub('\002', _C.sub('\003', _R.sub('\026', _O.sub('\017', _U.sub('\037', word)))))

Python code thanks to nexu



Print - Recent Changes - Search
Page last modified on February 21, 2010, at 11:22 AM