Skip to content

Instantly share code, notes, and snippets.

@SoniEx2
Last active February 28, 2021 00:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SoniEx2/887133046525cdddb547 to your computer and use it in GitHub Desktop.
Save SoniEx2/887133046525cdddb547 to your computer and use it in GitHub Desktop.

CTCP COLOR

CTCP COLOR is a CTCP ACTION-like CTCP, but instead of providing a different message style, it provides different colors.

Let:

X-DELIM ::= '\x01'
SPACE ::= ' '

The syntax for CTCP COLOR is as follows:

COLOR-MODE ::= 'RGB' | 'mIRC' | 'TERM8' | 'TERM16' | 'TERM256' | 'RESET'
COLOR-PLANE ::= 'FG' | 'BG' | '*'
STACKOP ::= 'PUSH' | 'POP'
CTCP-COLOR ::= X-DELIM 'COLOR ' (COLOR-PLANE SPACE COLOR-MODE SPACE COLOR | STACKOP) | X-DELIM

| is used to denote alternation.

RGB is supplied as either: 3 ASCII/decimal values ranging from 0 to 255, for red, green and blue, respectively; a 6-byte hexadecimal code (e.g. FF0000 for red; case insensitive); or a 3-byte hexadecimal code (e.g. F00 for red; also case insensitive). 3-byte hexadecimal is converted to 6-byte hexadecimal by multiplying each digit by (hexadecimal) 11, e.g. F00 becomes FF0000.

When using dual-plane mode (COLOR-PLANE *), you put 2 colors: foreground first, then background, e.g. for red foreground and black background, in RGB/TrueColor mode, you use COLOR * RGB FF0000 000000. When using this mode it is also possible to specify RESET as a color.

COLOR PUSH and COLOR POP save the current configuration on a stack and restore it, respectively.

An example message using mIRC colors:

Hi! \x0304This text is red!\x03

Same message, using CTCP COLOR:

Hi! \x01COLOR FG mIRC 04\x01This text is red!\x01COLOR * RESET\x01

Same message, using CTCP COLOR RGB: (may be different due to the fact that clients use palettes for mIRC colors, and those can usually be configured)

Hi! \x01COLOR FG RGB FF0000\x01This text is red!\x01COLOR * RESET\x01

Same message, with stackops:

Hi! \x01COLOR PUSH\x01\x01COLOR FG RGB FF0000\x01This text is red!\x01COLOR POP\x01

Compact version

Due to IRC's 512 char limit, there's also a compact CTCP COLOR. The differences:

COLOR-MODE ::= 'TC' | 'M' | '8' | '16' | '256' | 'R'
COLOR-PLANE ::= 'FG' | 'BG' | 'C'
STACKOP ::= '+' | '-'
CTCP-COLOR ::= X-DELIM (COLOR-PLANE SPACE COLOR-MODE SPACE COLOR | 'C' STACKOP) X-DELIM

RGB mode is 'TC', which stands for TrueColor, mIRC mode is 'M', terminal modes are '8', '16' or '256', reset is 'R', and instead of using a 'COLOR' CTCP we have 3 CTCPs: 'FG', 'BG' and 'C'. 'FG' sets foreground color, 'BG' sets background color, 'C' sets both. In this representation, it is recommended (but not required) to use either 3-byte or 6-byte hexadecimal representation for RGB/TrueColor mode.

Thus, the above examples become:

mIRC mode:

Hi! \x01FG M 04\x01This text is red!\x01C R\x01

RGB mode:

Hi! \x01FG TC FF0000\x01This text is red!\x01C R\x01

You can, of course, specify both FG and BG colors:

Hi! \x01C TC FF0000 000000\x01This text is red with black background!\x01C R\x01

You can also specify R to reset a color:

Hi! \x01C TC FF0000 R\x01This text is red with default background!\x01C R\x01

Stackops, compact version:

Hi! \x01C +\x01\x01FG TC FF0000\x01This text is red!\x01C -\x01

Notes

You shouldn't assume the color stack is always going to be fully popped at the end of a message. Setting foreground doesn't modify background, and vice versa. We don't specify how much you have to implement because if you're a terminal app you may implement just TERM8 and TERM16 (for example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment