Table of Contents

Method Parse

Namespace
Terminal.Gui
Assembly
Terminal.Gui.dll

Parse(string?, IFormatProvider?)

Converts the provided string to a new Color value.

[Pure]
public static Color Parse(string? text, IFormatProvider? formatProvider = null)

Parameters

text string

The text to analyze. Formats supported are "#RGB", "#RRGGBB", "#ARGB", "#AARRGGBB", "rgb(r,g,b)", "rgb(r,g,b,a)", "rgba(r,g,b)", "rgba(r,g,b,a)", and any of the ColorName16 string values.

formatProvider IFormatProvider

If specified and not null, will be passed to Parse(ReadOnlySpan<char>, IFormatProvider?).

Returns

Color

A Color value equivalent to text, if parsing was successful.

Remarks

While Color supports the alpha channel A, Terminal.Gui does not.

Exceptions

ArgumentNullException

If text is null.

ArgumentException

If text is an empty string or consists of only whitespace characters.

ColorParseException

If thrown by Parse(ReadOnlySpan<char>, IFormatProvider?).

Parse(ReadOnlySpan<char>, IFormatProvider?)

Converts the provided ReadOnlySpan<T> of char to a new Color value.

[Pure]
public static Color Parse(ReadOnlySpan<char> text, IFormatProvider? formatProvider = null)

Parameters

text ReadOnlySpan<char>

The text to analyze. Formats supported are "#RGB", "#RRGGBB", "#RGBA", "#AARRGGBB", "rgb(r,g,b)", "rgb(r,g,b,a)", "rgba(r,g,b)", "rgba(r,g,b,a)", and any of the ColorName16 string values.

formatProvider IFormatProvider

Optional IFormatProvider to provide parsing services for the input text.
Defaults to InvariantCulture if null.
If not null, must implement ICustomColorFormatter or will be ignored and InvariantCulture will be used.

Returns

Color

A Color value equivalent to text, if parsing was successful.

Remarks

While Color supports the alpha channel A, Terminal.Gui does not.

Exceptions

ArgumentException

with an inner FormatException if text was unable to be successfully parsed as a Color, for any reason.

Parse(ReadOnlySpan<byte>, IFormatProvider?)

Parses a span of UTF-8 characters into a value.

[Pure]
public static Color Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider)

Parameters

utf8Text ReadOnlySpan<byte>

The span of UTF-8 characters to parse.

provider IFormatProvider

An object that provides culture-specific formatting information about utf8Text.

Returns

Color

The result of parsing utf8Text.

Exceptions

FormatException

utf8Text is not in the correct format.

OverflowException

utf8Text is not representable by Color.