ircColour

Returns a mIRC colour code for the passed foreground and background colour. Overload that doesn't take a string to tint, only the IRCColours to produce a colour code from.

  1. string ircColour(string line, int fg, int bg)
  2. string ircColour(IRCColour fg, IRCColour bg)
    @safe pure
    string
    ircColour

Parameters

fg IRCColour

Foreground IRCColour.

bg IRCColour

Optional background IRCColour.

Return Value

Type: string

An opening IRC colour token with the passed colours.

Examples

alias I = IRCControlCharacter;

with (IRCColour)
{
    {
        immutable line = "abcdefg".ircColour(white);
        immutable expected = I.colour ~ "00abcdefg" ~ I.colour;
        assert((line == expected), line);
    }
    {
        immutable line = "abcdefg".ircBold;
        immutable expected = I.bold ~ "abcdefg" ~ I.bold;
        assert((line == expected), line);
    }
    {
        immutable line = ircColour(white) ~ "abcdefg" ~ I.reset;
        immutable expected = I.colour ~ "00abcdefg" ~ I.reset;
        assert((line == expected), line);
    }
    {
        immutable line = "" ~ I.bold ~ I.underlined ~ ircColour(green) ~
            "abcdef" ~ "ghijkl".ircColour(red) ~ I.reset;
        immutable expected = "" ~ I.bold ~ I.underlined ~ I.colour ~ "03abcdef" ~
            I.colour ~ "04ghijkl" ~ I.colour ~ I.reset;
        assert((line == expected), line);

        immutable expressedDifferently = ircBold(ircUnderlined("abcdef".ircColour(green) ~
            "ghijkl".ircColour(red)));
        immutable expectedDifferently = "" ~ I.bold ~ I.underlined ~ I.colour ~
            "03abcdef" ~ I.colour ~ I.colour ~ "04ghijkl" ~ I.colour ~
            I.underlined ~ I.bold;
        assert((expressedDifferently == expectedDifferently), expressedDifferently);
    }
    {
        immutable account = "kameloso";
        immutable authorised = "not authorised";
        immutable line = "Account " ~ ircBold(account) ~ ": " ~ ircUnderlined(authorised) ~ "!";
        immutable expected = "Account " ~ I.bold ~ "kameloso" ~ I.bold ~ ": " ~
            I.underlined ~ "not authorised" ~ I.underlined ~ "!";
        assert((line == expected), line);
    }
}