1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253module juptune.core.util.ansi;
nothrow @nogc struct AnsiTextLite
{
/++ FUNCTIONS ++/
/// SETTERS
AnsiTextLite bg(AnsiColour colour);
/// SETTERS
AnsiTextLite bg(Ansi4BitColour colour);
/// SETTERS
AnsiTextLite bg(ubyte colour);
/// SETTERS
AnsiTextLite bg(AnsiRgbColour colour);
/// GETTERS
AnsiColour bg();
/// SETTERS
AnsiTextLite fg(AnsiColour colour);
/// SETTERS
AnsiTextLite fg(Ansi4BitColour colour);
/// SETTERS
AnsiTextLite fg(ubyte colour);
/// SETTERS
AnsiTextLite fg(AnsiRgbColour colour);
/// GETTERS
AnsiColour fg();
/// SETTERS
AnsiTextLite style(AnsiStyle style);
/// GETTERS
AnsiStyle style();
/// Returns: The end ANSI sequence for AnsiTextLite , which is simply a statically allocated version of the ANSI_COLOUR_RESET constant.
char[4LU] toFullEndSequence();
/// Populates the given buffer with the full ANSI sequence needed to enable the styling defined within this AnsiTextLite
char[] toFullStartSequence(char[53LU] buffer);
/// Provides a range that returns, in this order: The start sequence (`.toFullStartSequence`); the output text (`.text`), and finally the end sequence (`.toFullEndSequence`).
auto toRange();
/// Outputs in order: The start sequence (`.toFullStartSequence`), the output text (`.text`), and the end sequence (`.toFullEndSequence`) into the given sink .
void toSink(Sink)(Sink sink);
/// The sink-based version of toString , which doesn't allocate by itself unless the sink decides to allocate.
void toString(void function(const char[]) sink);
/++ MANIFEST CONSTANTS ++/
/// The maximum amount of chars required by the start sequence of an AnsiTextLite (`toFullStartSequence`).
enum ulong MAX_CHARS_NEEDED = 53LU;
/++ VARIABLES ++/
/// The styling to apply to the text.
AnsiStyleSet styleSet;
/// The text to output.
const char[] text;
}
A lightweight alternative to AnsiTextwhich only supports a singular coloured string, at the cost of removing most of the other complexity & dynamic allocation needs of AnsiText.
If you only need to style your string in one certain way, or want to avoid AnsiTextaltogether, then this struct is the way to go.
First, retrieve and the ANSI styling sequence via AnsiTextLite.toFullStartSequenceand output it.
Second, output AnsiTextLite.text.
Finally, and optionally, retrieve the ANSI reset sequence via AnsiTextLite.toFullEndSequenceand output it.
Call AnsiTextLite.toRangeto get the range, please read its documentation as it is important (it'll return slices to stack-allocated memory).
ansifor fluent creation of an AnsiTextLite.
This struct's unittest for an example of usage.
CONSTANTS
| Name | Description |
|---|---|
| MAX_CHARS_NEEDED |
The maximum amount of chars required by the start sequence of an |
| Name | Description |
|---|---|
| bg |
SETTERS |
| bg |
SETTERS |
| bg |
SETTERS |
| bg |
SETTERS |
| bg |
GETTERS |
| fg |
SETTERS |
| fg |
SETTERS |
| fg |
SETTERS |
| fg |
SETTERS |
| fg |
GETTERS |
| style |
SETTERS |
| style |
GETTERS |
| toFullEndSequence |
Returns: The end ANSI sequence for |
| toFullStartSequence |
Populates the given buffer with the full ANSI sequence needed to enable the styling defined within this |
| toRange |
Provides a range that returns, in this order: The start sequence (`.toFullStartSequence`); the output text (`.text`), and finally the end sequence (`.toFullEndSequence`). |
| toSink |
Outputs in order: The start sequence (`.toFullStartSequence`), the output text (`.text`), and the end sequence (`.toFullEndSequence`) into the given |
| toString |
The sink-based version of |
| Name | Description |
|---|---|
| styleSet |
The styling to apply to the text. |
| text |
The text to output. |