colourByHash

Shorthand function to colour a passed word by the hash of it.

  1. auto colourByHash(string word, bool brightTerminal, bool extendedColours)
    version(Colours)
    pure @safe nothrow
    colourByHash
    (
    const string word
    ,
    const bool brightTerminal = CoreSettings.init.brightTerminal
    ,
    const bool extendedColours = CoreSettings.init.extendedColours
    )
  2. auto colourByHash(string word, CoreSettings settings)

Parameters

word string

String to colour.

brightTerminal bool

Whether the terminal has a bright background or not.

extendedColours bool

Whether to use extended colours beyond the normal ANSI.

Return Value

Type: auto

word, now in colour based on the hash of its contents.

Examples

import std.conv : to;

{
    immutable coloured = "kameloso".colourByHash(brightTerminal: false, extendedColours: true);
    assert((coloured == "\033[38;5;227mkameloso\033[0m"), coloured);
}
{
    immutable coloured = "kameloso".colourByHash(extendedColours: true, brightTerminal: true);
    assert((coloured == "\033[38;5;222mkameloso\033[0m"), coloured);
}
{
    immutable coloured = "kameloso".colourByHash(brightTerminal: true);
    assert((coloured == "\033[38;5;222mkameloso\033[0m"), coloured);
}
{
    immutable coloured = "zorael".colourByHash(extendedColours: true);
    assert((coloured == "\033[35mzorael\033[0m"), coloured);
}
{
    immutable coloured = "zorael".colourByHash(extendedColours: true);
    assert((coloured == "\033[35mzorael\033[0m"), coloured);
}
{
    immutable coloured = "NO".colourByHash(extendedColours: true);
    assert((coloured == "\033[90mNO\033[0m"), coloured);
}

See Also