Show / Hide Table of Contents

Class ColoredString

Represents a string that has foreground and background colors for each character in the string.

Inheritance
object
ColoredString
Implements
IEnumerable<ColoredGlyphAndEffect>
IEnumerable
Inherited Members
object.GetType()
object.MemberwiseClone()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: SadConsole
Assembly: SadConsole.dll
Syntax
[DataContract]
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class ColoredString : IEnumerable<ColoredGlyphAndEffect>, IEnumerable

Constructors

ColoredString()

Default constructor.

Declaration
public ColoredString()

ColoredString(params ColoredGlyphAndEffect[])

Combines a ColoredGlyphAndEffect array into a ColoredString.

Declaration
public ColoredString(params ColoredGlyphAndEffect[] glyphs)
Parameters
Type Name Description
ColoredGlyphAndEffect[] glyphs

The glyphs to combine.

ColoredString(params ColoredGlyphBase[])

Combines a ColoredGlyphBase array into a ColoredString.

Declaration
public ColoredString(params ColoredGlyphBase[] glyphs)
Parameters
Type Name Description
ColoredGlyphBase[] glyphs

The glyphs to combine.

ColoredString(int)

Creates a new instance of the ColoredString class with the specified blank characters.

Declaration
public ColoredString(int capacity)
Parameters
Type Name Description
int capacity

The number of blank characters.

ColoredString(string, ColoredGlyphAndEffect)

Creates a new instance of the ColoredString class with the specified string value, foreground and background colors, and a cell effect.

Declaration
public ColoredString(string value, ColoredGlyphAndEffect appearance)
Parameters
Type Name Description
string value

The backing string.

ColoredGlyphAndEffect appearance

The appearance to use for each character.

ColoredString(string, Color, Color, Mirror, CellDecorator[]?)

Creates a new instance of the ColoredString class with the specified string value, foreground and background colors, and a cell effect.

Declaration
public ColoredString(string value, Color foreground, Color background, Mirror mirror = Mirror.None, CellDecorator[]? decorators = null)
Parameters
Type Name Description
string value

The backing string.

Color foreground

The foreground color for each character.

Color background

The background color for each character.

Mirror mirror

The mirror for each character.

CellDecorator[] decorators

The decorators to apply to each character.

ColoredString(string, bool)

Creates a new instance of this class with the specified string value.

Declaration
public ColoredString(string value, bool treatAsString = false)
Parameters
Type Name Description
string value

The backing string.

bool treatAsString

When true, sets all of the Ignore properties to false, treating this instance as a normal string.

Properties

IgnoreBackground

When true, instructs a caller to not render the background color.

Declaration
[DataMember]
public bool IgnoreBackground { get; set; }
Property Value
Type Description
bool

IgnoreDecorators

When true, instructs a caller to not render the mirror state.

Declaration
[DataMember]
public bool IgnoreDecorators { get; set; }
Property Value
Type Description
bool

IgnoreEffect

When true, instructs a caller to not render the effect.

Declaration
[DataMember]
public bool IgnoreEffect { get; set; }
Property Value
Type Description
bool

IgnoreForeground

When true, instructs a caller to not render the foreground color.

Declaration
[DataMember]
public bool IgnoreForeground { get; set; }
Property Value
Type Description
bool

IgnoreGlyph

When true, instructs a caller to not render the glyphs of the string.

Declaration
[DataMember]
public bool IgnoreGlyph { get; set; }
Property Value
Type Description
bool

IgnoreMirror

When true, instructs a caller to not render the mirror state.

Declaration
[DataMember]
public bool IgnoreMirror { get; set; }
Property Value
Type Description
bool

this[int]

Gets a ColoredGlyphAndEffect from the string.

Declaration
public ColoredGlyphAndEffect this[int index] { get; set; }
Parameters
Type Name Description
int index

The index in the string of the ColoredGlyphAndEffect.

Property Value
Type Description
ColoredGlyphAndEffect

The colored glyph representing the character in the string.

Length

The total number of ColoredGlyphAndEffect characters in the string.

Declaration
public int Length { get; }
Property Value
Type Description
int

Parser

The string parser to use for transforming strings into ColoredString.

Declaration
public static IParser Parser { get; set; }
Property Value
Type Description
IParser

String

Gets or sets the characters representing this string. When set, first processes the string through Parse(ReadOnlySpan<char>, int, ICellSurface?, ParseCommandStacks?) method from Parser.

Declaration
public string String { get; set; }
Property Value
Type Description
string

Methods

Clone()

Returns a new ColoredString object by cloning this instance.

Declaration
public ColoredString Clone()
Returns
Type Description
ColoredString

A new ColoredString object.

FromGradient(Gradient, string)

Creates a new colored string from the specified gradient and text.

Declaration
public static ColoredString FromGradient(Gradient colors, string text)
Parameters
Type Name Description
Gradient colors

The gradient of colors to apply to the text.

string text

The text the colored string contains.

Returns
Type Description
ColoredString

A colored string.

GetEnumerator()

Gets an enumerator for the ColoredGlyphAndEffect objects in this string.

Declaration
public IEnumerator<ColoredGlyphAndEffect> GetEnumerator()
Returns
Type Description
IEnumerator<ColoredGlyphAndEffect>

The enumerator in the string.

SetBackground(Color)

Applies the referenced color to every character background in the colored string.

Declaration
public void SetBackground(Color color)
Parameters
Type Name Description
Color color

The color to apply.

SetDecorators(params CellDecorator[])

Applies the decorators to each character in the colored string.

Declaration
public void SetDecorators(params CellDecorator[] decorators)
Parameters
Type Name Description
CellDecorator[] decorators

The decorators.

SetDecorators(IEnumerable<CellDecorator>)

Applies the decorators to each character in the colored string.

Declaration
public void SetDecorators(IEnumerable<CellDecorator> decorators)
Parameters
Type Name Description
IEnumerable<CellDecorator> decorators

The decorators.

SetEffect(ICellEffect?)

Applies the referenced cell effect to every character in the colored string.

Declaration
public void SetEffect(ICellEffect? effect)
Parameters
Type Name Description
ICellEffect effect

The effect to apply.

SetForeground(Color)

Applies the referenced color to every character foreground in the colored string.

Declaration
public void SetForeground(Color color)
Parameters
Type Name Description
Color color

The color to apply.

SetGlyph(int)

Applies the referenced glyph to every character in the colored string.

Declaration
public void SetGlyph(int glyph)
Parameters
Type Name Description
int glyph

The glyph to apply.

SetMirror(Mirror)

Applies the mirror value to each character in the colored string.

Declaration
public void SetMirror(Mirror mirror)
Parameters
Type Name Description
Mirror mirror

The mirror mode.

SubString(int)

Returns a new ColoredString object using a substring of this instance from the index to the end.

Declaration
public ColoredString SubString(int index)
Parameters
Type Name Description
int index

The index to copy the contents from.

Returns
Type Description
ColoredString

A new ColoredString object.

SubString(int, int)

Returns a new ColoredString object using a substring of this instance.

Declaration
public ColoredString SubString(int index, int count)
Parameters
Type Name Description
int index

The index to copy the contents from.

int count

The count of ColoredGlyphAndEffect objects to copy.

Returns
Type Description
ColoredString

A new ColoredString object.

ToString()

Returns a string representing the glyphs in this object.

Declaration
public override string ToString()
Returns
Type Description
string

A string composed of each glyph in this object.

Overrides
object.ToString()

Operators

operator +(ColoredString, ColoredString)

Combines two ColoredString objects into a single ColoredString object. Ignore* values are only copied when both strings Ignore* values match.

Declaration
public static ColoredString operator +(ColoredString string1, ColoredString string2)
Parameters
Type Name Description
ColoredString string1

The left-side of the string.

ColoredString string2

The right-side of the string.

Returns
Type Description
ColoredString

operator +(ColoredString, string)

Combines a colored string and string. The last colored glyph in the colored string is used for all of the characters in the added string.

Declaration
public static ColoredString operator +(ColoredString string1, string string2)
Parameters
Type Name Description
ColoredString string1

The colored string.

string string2

The string.

Returns
Type Description
ColoredString

A new colored string instance.

operator +(string, ColoredString)

Combines a string and a colored string. The first colored glyph in the colored string is used for all of the characters in the added string.

Declaration
public static ColoredString operator +(string string1, ColoredString string2)
Parameters
Type Name Description
string string1

The string.

ColoredString string2

The colored string.

Returns
Type Description
ColoredString

A new colored string instance.

Implements

IEnumerable<T>
IEnumerable

Extension Methods

ExtensionsSystem.GetDebuggerDisplayValue(object)
In this article

Back to top

Back to top Generated by DocFX