AnsiText

A struct used to compose together a piece of ANSI text.

Notes: A reset command (\033[0m) is automatically appended, so you don't have to worry about that.

This struct is simply a wrapper around AnsiColour, AnsiTextFlags types, and the populateActiveAnsiComponents and createAnsiCommandString functions.

Usage: This struct uses the Fluent Builder pattern, so you can easily string together its various functions when creating your text.

Set the background colour with AnsiText.bg

Set the foreground/text colour with AnsiText.fg

AnsiText uses toString to provide the final output, making it easily used with the likes of writeln and format.

Constructors

this
this(const(char)[] text)

Members

Functions

bg
AnsiText bg(Ansi4BitColour fourBit)

Sets the foreground/background as a 4-bit colour. Widest supported option.

bg
AnsiText bg(ubyte eightBit)

Sets the foreground/background as an 8-bit colour. Please see this image for reference: https://i.stack.imgur.com/KTSQa.png

bg
AnsiText bg(ubyte r, ubyte g, ubyte b)

Sets the forground/background as an RGB colour.

bg
AnsiText bg(AnsiColour colour)

Sets the forground/background to an AnsiColour. Background colours will have their isBg flag set automatically.

bg
AnsiColour bg()

Gets the AnsiColour used as the background.

bold
AnsiText bold(bool isSet)

Sets whether the text is bold.

dim
AnsiText dim(bool isSet)

Sets whether the text is dimmed (opposite of bold).

fastBlink
AnsiText fastBlink(bool isSet)

Sets whether the text should blink rapidly.

fg
AnsiText fg(Ansi4BitColour fourBit)

Sets the foreground/background as a 4-bit colour. Widest supported option.

fg
AnsiText fg(ubyte eightBit)

Sets the foreground/background as an 8-bit colour. Please see this image for reference: https://i.stack.imgur.com/KTSQa.png

fg
AnsiText fg(ubyte r, ubyte g, ubyte b)

Sets the forground/background as an RGB colour.

fg
AnsiText fg(AnsiColour colour)

Sets the forground/background to an AnsiColour. Background colours will have their isBg flag set automatically.

fg
AnsiColour fg()

Gets the AnsiColour used as the foreground (text colour).

invert
AnsiText invert(bool isSet)

Sets whether the text should have its fg and bg colours inverted.

italic
AnsiText italic(bool isSet)

Sets whether the text should be displayed in italics.

setFlags
AnsiText setFlags(AnsiTextFlags flags)

Sets the AnsiTextFlags for this piece of text.

slowBlink
AnsiText slowBlink(bool isSet)

Sets whether the text should blink slowly.

strike
AnsiText strike(bool isSet)

Sets whether the text should have a strike through it.

toString
string toString()

Notes: If no ANSI escape codes are used, then this function will simply return a .idup of the text provided to this struct's constructor.

underline
AnsiText underline(bool isSet)

Sets whether the text has an underline.

Properties

flags
AnsiTextFlags flags [@property getter]

Gets the AnsiTextFlags for this piece of text.

rawText
const(char[]) rawText [@property getter]
rawText
char[] rawText [@property setter]

Sets the raw text used.

Static variables

RESET_COMMAND
auto RESET_COMMAND;

The ANSI command to reset all styling.

Meta