KamelosoLogger.tint

Returns the corresponding TerminalForeground for the LogLevel, taking into account whether the terminal is said to be bright or not.

This is merely a convenient wrapping for logcoloursBright and logcoloursDark.

class KamelosoLogger
version(Colours)
static pure nothrow @nogc @safe
uint
tint
(,
const bool brightTerminal
)

Parameters

level LogLevel

The LogLevel of the colour we want to scry.

brightTerminal bool

Whether the colour should be for a bright terminal background or a dark one.

Return Value

Type: uint

A TerminalForeground of the right colour. Use with asANSI to get a string.

Examples

TerminalForeground errtint = KamelosoLogger.tint(LogLevel.error, brightTerminal: false);
immutable errtintString = errtint.asANSI;
static immutable LogLevel[4] logLevels =
[
    LogLevel.all,
    LogLevel.info,
    LogLevel.warning,
    LogLevel.fatal,
];

foreach (immutable logLevel; logLevels[])
{
    import std.format : format;

    immutable tintBright = tint(logLevel, brightTerminal: true);
    immutable tintBrightTable = logcoloursBright[logLevel];
    assert((tintBright == tintBrightTable), "%s != %s"
        .format(tintBright, tintBrightTable));

    immutable tintDark = tint(logLevel, brightTerminal: false);
    immutable tintDarkTable = logcoloursDark[logLevel];
    assert((tintDark == tintDarkTable), "%s != %s"
        .format(tintDark, tintDarkTable));
}