getColourByHash

Hashes the passed string and picks an ANSI colour for it by modulo.

Picks any colour, taking care not to pick black or white based on the passed CoreSettings struct (which has a field that signifies a bright terminal background).

version(Colours)
pure @safe nothrow
getColourByHash
(
const string word
,)

Parameters

word string

String to hash and base colour on.

settings CoreSettings

A copy of the program-global CoreSettings.

Return Value

Type: auto

A uint that can be used in an ANSI foreground colour sequence.

Examples

immutable nickColour = "kameloso".getColourByHash(*kameloso.common.settings);
import std.conv : to;

CoreSettings brightSettings;
CoreSettings darkSettings;
brightSettings.brightTerminal = true;

{
    immutable hash = getColourByHash("kameloso", darkSettings);
    assert((hash == 227), hash.to!string);
}
{
    immutable hash = getColourByHash("kameloso^", darkSettings);
    assert((hash == 46), hash.to!string);
}
{
    immutable hash = getColourByHash("zorael", brightSettings);
    assert((hash == 35), hash.to!string);
}
{
    immutable hash = getColourByHash("NO", brightSettings);
    assert((hash == 90), hash.to!string);
}

Meta