7

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rsz
  • 1,141
  • 1
  • 18
  • 38

1 Answers1

11

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nei
  • 333
  • 1
  • 6
  • 1
    It's probably worth mentioning how to enable text colors in the first place. Some Linux distros disable them in the default config. Since apparently you haven't logged in since January, I've taken the liberty to just edit that in into your answer. – Staven Oct 17 '15 at 09:49
  • @Staven `/set hide_colors OFF` doesn't seem to work. I can see it on the outgoing messages, but not incoming messages. Any idea how to fix this? – Qix - MONICA WAS MISTREATED Nov 15 '15 at 04:02
  • This did not work for me in PuTTY on Windows. When I press Ctrl+C, irssi displays a `C` in reverse colors in my input window, and when I press "3" it just adds a 3 to the input buffer as usual. Any tips? – David Grayson Aug 25 '16 at 00:28
  • @DavidGrayson it is shown like that only when composing. After pressing Ctrl+C, a C in reverse colors will be displayed on your input window, and after adding a "3", it is simply added to the input buffer as usual. Then append the text you want in green, eg. "hello world" and send it (you may want to use an empty channel or /query yourself for these tests). When viewed in the channel, a green "hello world" will be displayed (actually, the Ctrl+C and 3 **are** sent on the wire, but parsed by the irc clients for determining how to display). – Ángel Oct 26 '16 at 22:58