ditto.
[Not enabled with -betterC] Provides this AnsiText as a printable string.
[Not enabled with -betterC] Provides the sink-based version of the autogenerated toString.
While implementations can add whatever functions, operator overloads, constructors, etc. that they want, there is a small set of functions and value that each implmentation must define in order to be useable.
Every implementation must define an enum called Features who's value is one of the values of AnsiTextImplementationFeatures. For example: enum Features = AnsiTextImplementationFeatures.xxx
Builtin implementations consist of AnsiTextGC (not enabled with -betterC), AnsiTextStack, and AnsiTextMalloc, which are self-descriptive.
An implementation that doesn't require anything noteworthy from AnsiText itself should define their features as AnsiTextImplementationFeatures.basic.
This type of implementation must implement the following functions (expressed here as an interface for simplicity):
interface BasicImplementation { /// Provides `AnsiText` with a slice that is of at least `minLength` in size. /// /// This function is called `AnsiText` needs to insert more styled characters into the string. /// /// How this slice is stored and allocated and whatever else, is completely down to the implementation. /// Remember that because you're a mixin template, you can use referencing counting, disable the copy ctor, etc! /// /// The slice will never be escaped by `AnsiText` itself, and will not be stored beyond a single function call. char[] newSlice(size_t minLength); /// Outputs the styled string into the provided sink. /// /// Typically this is an OutputRange that can handle `char[]`s, but it can really be whatever the implementation wants to support. void toSink(Sink)(Sink sink); static if(NotCompilingUnderBetterC && ImplementationDoesntDefineToString) final string toString() { // Autogenerated GC-based implementation provided by `AnsiText`. // // For implementations where this can be generated, it just makes them a little easier for the user // to use with things like `writeln`. // // The `static if` shows the conditions for this to happen. } }
Contains a string that supports the ability for different parts of the string to be styled seperately.
This struct is highly flexible and dynamic, as it requires the use of external code to provide some of the implementation.
Because this is provided via a mixin template, implementations can also extend this struct to provide their own functionality, make things non-copyable if needed, allows data to be stored via ref-counting, etc.
This struct itself is mostly just a consistant user-facing interface that all implementations share, while the implementations themselves can transform this struct to any level it requires.