PoshCode / Pansies

Powershell ANSI Escape Sequences, functions for colored output, etc.
MIT License
146 stars 14 forks source link

Create a TextSpan type #1

Closed Jaykul closed 7 years ago

Jaykul commented 7 years ago

We need a base class something like this, with constructor that optionally takes just the string

public class Text {
    public string Text;
    public Color? ForegroundColor;
    public Color? BackgroundColor;
    //  override to output VT ANSI escape sequence
    public override string ToString()
}

And then, a collection class which also has a constructor that optionally takes just the string, but also can cast from a that base Text class, or an array of them. It shouldn't just call the base Text object ToString(), because the key feature of this being an array is to optimize (not output extra escapes), and include a reset at the end of the output.

public class TextSpan {
    public Text[] Text;
    public Color? ForegroundColor;
    public Color? BackgroundColor;
    // this one includes a reset at the end, so text after it goes back to normal output
    public override string ToString()
}