Adding Colors to IRC Outgoing Messages

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.

Advertisement

Rotate Your Movie

I have received by e-mail a rotated video in the ‘flv’ format. The video was supposed to be a vertical one, but it turned out to be horizontal, that is ROTATED. So, I wrote a little program to rotate it back using libming.
There are two things to take care of when processing the input FLV:

  • The video stream.
  • The sound stream.

Both can be taken from the FLV file.
The code is written in C++, but can be translated easily into PHP. Following is the code:

#include <iostream>
#include <mingpp.h>

using namespace std;

int main(){
  const char *flvFile ="/path/to/inputVideoFile.flv";

  // Get the video stream from the file. The input file can be in the FLV format.
  SWFVideoStream *stream = new SWFVideoStream(flvFile);

  SWFMovie mov (9);  // Create the movie object.

  // The method 'add' returns a display item.
  // Display items can be rotated, transformed, etc.
  SWFDisplayItem *di=mov.add(stream);  

  // Sound streams are taken from a file object. 
  FILE *soundFD = fopen(flvFile, "rb+");
  SWFSoundStream sound(soundFD);

  // The original dimensions of the video are 426 X 240.
  di->rotate(-90);  // Rotate the item 90 degrees clockwise
  di->move(240, 0);  // The rotation moves point (0,240) to (-240,0).


  mov.setSoundStream(&sound,0);  // Add the sound stream at the beginning
                                 // of the movie.

  // Show the frames one by one.
  int noFrames = stream->getNumFrames();
  for (int i=0; i<noFrames; i++)
      mov.nextFrame();

  mov.setDimension(240, 426); // The new dimensions.
  mov.save("/path/to/outputVideoFile.swf", 9);
  cerr<<"Fin\n";
  return 0;
}

This will create a real vertical movie. Don’t share it on YouTube or anywhere you cannot control your movie dimensions.

StackEdit: Markdown Editor

Hello, World!

I am a blog post written in Markdown, and sent from the StackEdit editor.

Do you know those files with suffix ‘.md’? They are markdown documents, and they are easy to write and easy to read because they don’t have to contain HTML tags!

Here’s an example of how to add a link:

Type “[The Example Site](http://example.com)” to get the following link:

The Example Site

This tool can export your document as HTML. sponsors can use this tool to export documents as PDF..

Written with StackEdit.