PHP & More

A technical blog about programming in PHP and about technology in general: programming, workarounds and troubleshooting

The other day, I participated in a discussion on GimpNet IRC (irc://irc.gimp.org). I saw there a message in which some words were colored. Since my client is Pidgin, I cannot add colors simply by clicking on the Font button, and selecting a color: all the menu options are disabled.

Searching the web for IRC colors, I found that mIRC supports adding colors to the text. If you are not a mIRC user, at least you can find the list of color codes here. The page does not describe how to add colors and other text attributes in other clients, but to learn at least about the sequences to be sent to the server, writing a script is recommended. To find the way to write scripts using the IRC protocol, I recommend using the PERL language. A great place to find PERL modules is the CPAN (Comprehensive PERL Archive Network) site. Search for IRC. A good class to create mIRC color strings is String::IRC – add color codes for mIRC compatible client.

Following is a script I’ve written to print the sequences:

use String::IRC;
use strict;

sub print_char {
    my $ch=shift;
    my $ord=ord($ch);
    if ($ord<32 or $ord>126){
        printf "\033[37;1m<%x>\033[0m", $ord;
    } else {
        print $ch;
    }
}

sub print_string {
    my $str=shift;
    my $len=length($str);
    for (my $i=0; $i<$len;$i++){
        print_char(substr($str,$i,1));
    }
    print "\n";
}

my $red=String::IRC->new("Red")->red;
print_string "Red: $red";
my $red_underlined=String::IRC->new("Red Underlined")->red->underline;
print_string "Red Underlined $red_underlined";
my $red_bold=String::IRC->new("Red Bold")->red->bold;
print_string "Red Bold: $red_bold";
my $red_inverse=String::IRC->new("Red Inverse")->red->inverse;
print_string "Red Inverse: $red_inverse";

The output of the script is in the following image:

The hex codes of control characters appear in white. They can be added as Unicode characters.

So,

  • Unicode character 0x02 begins a bold string or sub-string.
  • Unicode character 0x1f begins an underlined string or sub-string.
  • Unicode character 0x03 begins a colored string or sub-string when followed by:
    • A foreground code
    • Foreground and background codes separated by a comma.
  • Unicode character 0x0f resumes to the default text format.

Now, to add a Control Character in Pidgin

First, check that the input method is “System”. To do it, left-click inside the input area and choose the input method:

Use your system’s method to insert a Unicode characterFor example, In Linux/UNIX, type <Ctrl>+<shift>+U followed by the hexadecimal code of the character, and the space or Enter.

%d bloggers like this: