How can I write colored text to irc channel with irssi

rsz picture rsz · Mar 15, 2014 · Viewed 11.4k times · Source

I'm googling all day now and I'm searching for a method to write a text with different colors like I always saw on other IRC channels. I want to achieve this with irssi which is CLI based. I have found multiple methods which didn't work as expected. How can I for example write

WHAT

with green color for example?

I would like to achieve the same effect from a simple Bash script too. So if someone has experienced this in the past it would be helpful for me.

Answer

Nei picture Nei · Mar 17, 2014

First, make sure to enable text colors with

/set hide_colors OFF

Within irssi, to answer your concrete question, type

Ctrl+C 3 WHAT

and then enter, the text will show up in green. This convention is known as mIRC colour codes. To make it more comfortable, download the colour_popup script, place it in your ~/.irssi/scripts/autorun folder and run this command:

/statusbar prompt add -after input -alignment right colours

Then it will show you the available colours once you type Ctrl+C

On the other hand with Bash, you need to use ANSI colour codes. To output green text. try this command:

printf "\e[%dm%s\e[m\n" 32 hallo

\e[ is a CSI (terminal control sequence start) and m is the command; it means character graphics attributes like colour, bold, ...

3 refers to the dull foreground colour table, 2 is green; valid colours go from 0-7. Bright colours are 90-97; background colours are 40-47 and 100-107. There are even more colours possible with other encodings, such as 256 colour table "38;5;<idx>" where <idx> is from 0-255, or 24 bit RGB colours "38;2;12;34;56" (12/255 red, 34/255 green, 56/255 blue); this is not supported by all terminals.