String to hash and base colour on.
A variadic combination of one or more std.typecons.Flag flags to configure the output.
A uint that can be used in an ANSI foreground colour sequence.
immutable nickColour = "kameloso".getColourByHash(Yes.brightTerminal); immutable otherColour = "kameloso^".getColourByHash(No.extendedColours);
import std.conv : to; { enum word = "kameloso"; immutable hash = getColourByHash(word, No.brightTerminal, Yes.extendedColours); assert((hash == 227), hash.to!string); } { enum word = "kameloso"; immutable hash = getColourByHash(word, No.brightTerminal); assert((hash == 227), hash.to!string); } { enum word = "kameloso"; immutable hash = getColourByHash(word, Yes.extendedColours); 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, No.brightTerminal, Yes.brightTerminal, No.extendedColours, Yes.extendedColours); assert((hash == 35), hash.to!string); } { enum word = "NO"; immutable hash = getColourByHash( word, Yes.brightTerminal, Yes.extendedColours, Yes.extendedColours); 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 Flag!"brightTerminal" flag. If the Flag!"extendedColours" flag 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.