Class ANSIAttributeParser
Splits a line of text that carries ANSI style markup into the plain characters to display and the attribute runs that describe how to display them.
Inherited Members
Namespace: Scylla.TextMode
Assembly: ScyllaTextMode.dll
Syntax
public static class ANSIAttributeParser
Remarks
This is the lightweight counterpart to TerminalEmulator. The emulator maintains a live screen and understands the full escape repertoire; this parser handles a single finished line on its way into the scrollback, where the only thing that can vary within the line is its style. Both share one style table, in ANSISGRAttributes.
Escape sequences are removed rather than displayed, so the returned text measures and wraps exactly as the reader sees it, and a copy of the line to the clipboard carries no control characters. Sequences that are not SGR are dropped without effect.
Marking a word for inverse display, where ESC stands for the escape character:
var runs = new List<ScrollbackAttributeRun>();
var plain = ANSIAttributeParser.Parse("Status: ESC[7mACTIVEESC[27m", runs);
/* plain is "Status: ACTIVE", runs holds one Inverse run at 8 for 6 characters. */
Methods
ContainsMarkup(string)
Determines whether a string contains anything this parser would act on.
Declaration
public static bool ContainsMarkup(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to test; may be null. |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
Use this to skip the parser entirely for ordinary text, which is the common case.
Parse(string, List<ScrollbackAttributeRun>)
Removes the escape sequences from a line and reports the attribute runs they describe.
Declaration
public static string Parse(string text, List<ScrollbackAttributeRun> runs)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to parse; may be null. |
| List<ScrollbackAttributeRun> | runs | A list that receives one entry per styled span, in ascending order and without
overlaps. The list is cleared first. Spans with no attributes are not recorded, so an
unstyled line leaves the list empty. May be |
Returns
| Type | Description |
|---|---|
| string | The text with every escape sequence removed, or an empty string when
|
Remarks
Attributes carry across the whole line from the point they are switched on, so a line that never switches them off stays styled to its end. Each line is parsed on its own and starts unstyled.
Slice(List<ScrollbackAttributeRun>, int, int)
Rebases a set of attribute runs onto a substring of the text they were parsed from.
Declaration
public static ScrollbackAttributeRun[] Slice(List<ScrollbackAttributeRun> runs, int start, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| List<ScrollbackAttributeRun> | runs | The runs covering the whole text. |
| int | start | The index at which the substring begins. |
| int | length | The length of the substring. |
Returns
| Type | Description |
|---|---|
| ScrollbackAttributeRun[] | A new array holding the portions of |
Remarks
A multi-line message is stored as one scrollback line per linebreak, and each of those lines needs the runs that cover it expressed in its own coordinates.