String to hash and base colour on.
Whether the terminal has a bright background or not.
Whether to use extended colours or not.
A uint that can be used in an ANSI foreground colour sequence.
immutable nickColour = "kameloso".getColourByHash(brightTerminal: true); immutable otherColour = "kameloso^".getColourByHash(extendedColours: false);
import std.conv : to; { enum word = "kameloso"; immutable hash = getColourByHash(word, brightTerminal: false, extendedColours: true); assert((hash == 227), hash.to!string); } { enum word = "kameloso"; immutable hash = getColourByHash(word, brightTerminal: false); assert((hash == 227), hash.to!string); } { enum word = "kameloso"; immutable hash = getColourByHash(word, extendedColours: true); assert((hash == 227), hash.to!string); } { enum word = "kameloso"; immutable hash = getColourByHash(word); assert((hash == 227), hash.to!string); } { enum word = "kameloso^"; immutable hash = getColourByHash(word); assert((hash == 46), hash.to!string); } { enum word = "zorael"; immutable hash = getColourByHash( word, brightTerminal: true, extendedColours: true); assert((hash == 35), hash.to!string); } { enum word = "NO"; immutable hash = getColourByHash( word, brightTerminal: true, extendedColours: true); assert((hash == 90), hash.to!string); }
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 brightTerminal bool. If extendedColours: true is passed, it will pick from the extended colour range instead of the basic one.
Any number of flags may be passed. If duplicates are passed, the last one will be used.