How can I write colored text to an IRC channel with Irssi?
Asked Answered
S

1

8

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.

Satisfaction answered 15/3, 2014 at 20:5 Comment(2)
see e.g wikipediaWartburg
yes i already done that but it's not working maybe you could give an example? maybe i'm doing wrong somethingSatisfaction
U
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.

Unadvised answered 17/3, 2014 at 12:31 Comment(4)
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.Fransiscafransisco
@Fransiscafransisco /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?Multifarious
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?Actuary
@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).Somber

© 2022 - 2024 — McMap. All rights reserved.