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 Flag!"brightTerminal" bright
)

Parameters

level LogLevel

The LogLevel of the colour we want to scry.

bright Flag!"brightTerminal"

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, No.brightTerminal);
immutable errtintString = errtint.asANSI;
import std.range : only;

auto range = only(
    LogLevel.all,
    LogLevel.info,
    LogLevel.warning,
    LogLevel.fatal);

foreach (immutable logLevel; range)
{
    import std.format : format;

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

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

Meta