ircColourByHash

Returns the passed string coloured with an IRC colour depending on the hash of the string, making for good "random" (uniformly distributed) nick colours in IRC messages.

@safe pure
string
ircColourByHash
(
const string word
,
const Flag!"extendedOutgoingColours" extendedOutgoingColours
)

Parameters

word string

String to tint.

extendedOutgoingColours Flag!"extendedOutgoingColours"

Whether or not to use extended colours (16-98).

Return Value

Type: string

The passed string encased within IRC colour coding.

Examples

alias I = IRCControlCharacter;

// Colour based on hash

{
    immutable actual = "kameloso".ircColourByHash(Yes.extendedOutgoingColours);
    immutable expected = I.colour ~ "23kameloso" ~ I.colour;
    assert((actual == expected), actual);
}
{
    immutable actual = "kameloso^".ircColourByHash(Yes.extendedOutgoingColours);
    immutable expected = I.colour ~ "56kameloso^" ~ I.colour;
    assert((actual == expected), actual);
}
{
    immutable actual = "kameloso^11".ircColourByHash(Yes.extendedOutgoingColours);
    immutable expected = I.colour ~ "91kameloso^11" ~ I.colour;
    assert((actual == expected), actual);
}
{
    immutable actual = "flerrp".ircColourByHash(Yes.extendedOutgoingColours);
    immutable expected = I.colour ~ "90flerrp" ~ I.colour;
    assert((actual == expected), actual);
}

Meta