Marmos
v juptune
v asn1
v lang
v ast
v Classes
v Enums
v ir
v parser
v Enums
v Structs
v core
v crypto
v keyexchange
v memory
v data
v alphabet
v buffer
v json
v builder
v parser
v Enums
v Structs
v serialise
v Structs
v Templates
v pem
v Enums
v Structs

Structs AnsiTextLite

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module 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;
}

Documentation

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.

Usage_(Manually)

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.

Usage_(Range)

Call AnsiTextLite.toRangeto get the range, please read its documentation as it is important (it'll return slices to stack-allocated memory).

See_Also

ansifor fluent creation of an AnsiTextLite.

This struct's unittest for an example of usage.

CONSTANTS

Constants

Name Description
MAX_CHARS_NEEDED

The maximum amount of chars required by the start sequence of an AnsiTextLite(`toFullStartSequence`).

Functions

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 AnsiTextLite, which is simply a statically allocated version of the ANSI_COLOUR_RESETconstant.

toFullStartSequence

Populates the given buffer with the full ANSI sequence needed to enable the styling defined within this AnsiTextLite

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 sink.

toString

The sink-based version of toString, which doesn't allocate by itself unless the sinkdecides to allocate.

Variables

Name Description
styleSet

The styling to apply to the text.

text

The text to output.