Skip to content

SgrToken ​

Namespace: Hex1b.Tokens

Assembly: Hex1b.dll

Represents a CSI Select Graphic Rendition command (SGR): ESC [ params m

csharp
public sealed record SgrToken : AnsiToken, IEquatable<AnsiToken>, IEquatable<SgrToken>

Inheritance ​

Object → AnsiToken → SgrToken

Implements ​

Constructors ​

SgrToken(string) ​

Represents a CSI Select Graphic Rendition command (SGR): ESC [ params m

Parameters:

  • Parameters (String): The raw SGR parameter string (e.g., "1;38;2;255;0;0" for bold red). Empty string or null represents reset (ESC[m or ESC[0m).
csharp
public SgrToken(string Parameters)

Properties ​

Parameters ​

The raw SGR parameter string (e.g., "1;38;2;255;0;0" for bold red). Empty string or null represents reset (ESC[m or ESC[0m).

Returns: String

csharp
public string Parameters { get; init; }

Methods ​

Equals(SgrToken?) ​

Indicates whether the current object is equal to another object of the same type.

Parameters:

  • other (SgrToken): An object to compare with this object.

Returns: Boolean

true if the current object is equal to the other parameter; otherwise, false.

csharp
public bool Equals(SgrToken? other)

GetHashCode() ​

Serves as the default hash function.

Returns: Int32

A hash code for the current object.

csharp
public override int GetHashCode()

Fields ​

Reset ​

SGR reset - clears all attributes and colors.

Returns: SgrToken

csharp
public static readonly SgrToken Reset

Remarks ​

We preserve the raw parameter string rather than interpreting it, because: SGR sequences can be complex (256-color, RGB, combined attributes)Filters may want to pass through unchangedPreserves the original encoding for faithful serialization

Common SGR codes: 0 = Reset all1 = Bold, 2 = Dim, 3 = Italic, 4 = Underline30-37 = Foreground colors, 40-47 = Background colors38;5;N = 256-color foreground, 38;2;R;G;B = RGB foreground

Released under the MIT License.