asTruecolour

Produces a terminal colour token for the colour passed, expressed in terms of red, green and blue. Convenience function to colour a piece of text without being passed an output sink to fill into.

version(Colours)
pure @safe
string
asTruecolour
(
const string word
,
const uint r
,
const uint g
,
const uint b
,
const Flag!"brightTerminal" bright = No.brightTerminal
,
const Flag!"normalise" normalise = Yes.normalise
)

Parameters

word string

String to tint.

r uint

Red value.

g uint

Green value.

b uint

Blue value.

bright Flag!"brightTerminal"

Whether the terminal has a bright background or not.

normalise Flag!"normalise"

Whether or not to normalise colours so that they aren't too dark or too bright.

Return Value

Type: string

The passed string word encompassed by terminal colour tags.

Examples

string foo = "Foo Bar".asTruecolour(172, 172, 255);

int r, g, b;
numFromHex("003388", r, g, b);
string bar = "Bar Foo".asTruecolour(r, g, b);
import std.format : format;

immutable name = "blarbhl".asTruecolour(255, 255, 255, No.brightTerminal, No.normalise);
immutable alsoName = "%c[38;2;%d;%d;%dm%s%c[0m"
    .format(cast(char)TerminalToken.format, 255, 255, 255,
       "blarbhl", cast(char)TerminalToken.format);

assert((name == alsoName), alsoName);

Meta