colourByHash

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

  1. auto colourByHash(string word, Flags flags)
  2. auto colourByHash(string word, CoreSettings settings)
    version(Colours)
    pure @safe nothrow
    colourByHash
    (
    const string word
    ,)

Parameters

word string

String to colour.

settings CoreSettings

A copy of the program-global CoreSettings.

Return Value

Type: auto

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

Examples

import std.conv : to;

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

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

See Also