AnsiSectionRange

An input range of AnsiSections that splits a piece of text up into ANSI sequence and plain text sections.

For example, the text "\033[37mABC\033[0m" has three sections: [ANSI "\033[37m", TEXT "ABC", ANSI "\033[0m"].

Constructors

this
this(const(char)[] input)

Members

Functions

empty
bool empty()
front
AnsiSection front()
popFront
void popFront()

Examples

assert(AnsiSectionRange.init.empty);
assert("".asAnsiSections.empty);

auto r = "No Ansi".asAnsiSections;
assert(!r.empty);
assert(!r.front.isAnsiSequence);
assert(r.front.slice == "No Ansi");

r = "\033[m".asAnsiSections;
assert(!r.empty);
assert(r.front.isAnsiSequence);
assert(r.front.slice == "\033[m");

r = "\033[38;2;255;128;64;1;4;48;5;2m".asAnsiSections;
assert(!r.empty);
assert(r.front.isAnsiSequence);
assert(r.front.slice == "\033[38;2;255;128;64;1;4;48;5;2m");

r = "\033[mABC\033[m".asAnsiSections;
assert(r.front.isAnsiSequence);
assert(r.front.slice == "\033[m", r.front.slice);
r.popFront();
assert(!r.empty);
assert(!r.front.isAnsiSequence);
assert(r.front.slice == "ABC", r.front.slice);
r.popFront();
assert(!r.empty);
assert(r.front.isAnsiSequence);
assert(r.front.slice == "\033[m");
r.popFront();
assert(r.empty);

r = "ABC\033[mDEF".asAnsiSections;
assert(!r.front.isAnsiSequence);
assert(r.front.slice == "ABC");
r.popFront();
assert(r.front.isAnsiSequence);
assert(r.front.slice == "\033[m");
r.popFront();
assert(!r.front.isAnsiSequence);
assert(r.front.slice == "DEF");
r.popFront();
assert(r.empty);

Meta