AnsiStyleSet.toSequence

Creates an ANSI SGR command that sets the foreground colour, sets the background colour, and enables all of the desired styling options, while leaving all of the other options unchanged.

Please note that the CSI (ANSI_CSI/\033[) and the SGR marker (ANSI_COLOUR_END/m) are not included in this output.

Notes: Any characters inside of buffer that are not covered by the returned slice, are left unmodified.

If this colour hasn't been initialised or assigned a value, then the returned value is simply null.

struct AnsiStyleSet
@safe @nogc nothrow const
char[]
toSequence
(
ref return char[MAX_CHARS_NEEDED] buffer
)

Parameters

buffer char[MAX_CHARS_NEEDED]

The statically allocated buffer used to store the result of this function.

Return Value

Type: char[]

A slice into buffer that contains the output of this function.

Examples

char[AnsiStyleSet.MAX_CHARS_NEEDED] buffer;

void test(string expected, AnsiStyleSet ch)
{
    auto slice = ch.toSequence(buffer);
    assert(slice == expected, "Got '"~slice~"' expected '"~expected~"'");
}

test("", AnsiStyleSet.init);
test(
    "32;48;2;255;128;64;1;4", 
    AnsiStyleSet.init
            .fg(Ansi4BitColour.green)
            .bg(AnsiRgbColour(255, 128, 64))
            .style(AnsiStyle.init.bold.underline)
);

Meta