withANSI

Applies an ANSI code to a passed string and returns it as a new one. Convenience function to colour a piece of text without being passed an output sink to fill into.

version(Colours)
pure @safe nothrow
string
withANSI
(
const string text
,
const uint code
,)

Parameters

text string

Original string.

code uint

ANSI code.

overrideType ANSICodeType

Force a specific ANSICodeType in cases where there is ambiguity.

Return Value

Type: string

A new string consisting of the passed text argument, but with the supplied ANSI code applied.

Examples

with (TerminalForeground)
{
    // Normal string-returning versions
    writeln("Hello ", red.asANSI, "world!", default_.asANSI);
    writeln("H3LL0".withANSI(red), ' ', "W0RLD!".withANSI(default_));
}