Table of Contents

Class SequenceHelper

Namespace
SharpConsoleUI.Helpers
Assembly
SharpConsoleUI.dll

Provides helper methods and constants for handling ANSI escape sequences, mouse input parsing, and keyboard input processing in console applications.

public static class SequenceHelper
Inheritance
SequenceHelper
Inherited Members

Remarks

This class contains functionality adapted from Terminal.Gui for parsing escape sequences and mouse events from console input.

Fields

CSI

The Control Sequence Introducer (CSI) escape sequence prefix.

public const string CSI = "\u001b["

Field Value

string

CSI_EnableAnyEventMouse

The CSI sequence to enable any-event mouse tracking mode.

public static readonly string CSI_EnableAnyEventMouse

Field Value

string

CSI_EnableMouseEvents

The combined CSI sequence to enable all mouse event tracking modes.

public static readonly string CSI_EnableMouseEvents

Field Value

string

CSI_EnableSgrExtModeMouse

The CSI sequence to enable SGR extended mouse mode.

public static readonly string CSI_EnableSgrExtModeMouse

Field Value

string

CSI_EnableUrxvtExtModeMouse

The CSI sequence to enable urxvt extended mouse mode.

public static readonly string CSI_EnableUrxvtExtModeMouse

Field Value

string

KeyEsc

The escape key character value.

public const char KeyEsc = '\u001b'

Field Value

char

Methods

GetC1ControlChar(in char)

Gets the C1 control character name for the specified character.

public static string GetC1ControlChar(in char c)

Parameters

c char

The character following an escape sequence to interpret.

Returns

string

The name of the C1 control character, or an empty string if not recognized.

Remarks

These control characters are used in vtXXX terminal emulation.

GetEscapeResult(char[])

Parses an escape sequence from a character array and extracts its components.

public static (string? c1Control, string? code, string[]? values, string? terminating) GetEscapeResult(char[] kChar)

Parameters

kChar char[]

The character array containing the escape sequence.

Returns

(string c1Control, string code, string[] values, string terminating)

A tuple containing:

  • c1Control: The C1 control character name (e.g., "CSI", "ESC").
  • code: Any additional code characters in the sequence.
  • values: The numeric parameter values separated by semicolons.
  • terminating: The terminating character(s) of the sequence.

GetKeyCharArray(ConsoleKeyInfo[])

Converts an array of ConsoleKeyInfo to a character array.

public static char[] GetKeyCharArray(ConsoleKeyInfo[] cki)

Parameters

cki ConsoleKeyInfo[]

The array of console key information.

Returns

char[]

An array of characters extracted from the key information.

GetMouse(ConsoleKeyInfo[], out List<MouseFlags>, out Point, Action<MouseFlags, Point>)

Parses mouse input from console key information and extracts mouse state.

public static void GetMouse(ConsoleKeyInfo[] cki, out List<MouseFlags> mouseFlags, out Point pos, Action<MouseFlags, Point> continuousButtonPressedHandler)

Parameters

cki ConsoleKeyInfo[]

The array of console key information containing mouse data.

mouseFlags List<MouseFlags>

Output list of mouse flags indicating the current mouse state.

pos Point

Output position of the mouse cursor.

continuousButtonPressedHandler Action<MouseFlags, Point>

Handler to invoke for continuous button press events.