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
CSI_EnableAnyEventMouse
The CSI sequence to enable any-event mouse tracking mode.
public static readonly string CSI_EnableAnyEventMouse
Field Value
CSI_EnableMouseEvents
The combined CSI sequence to enable all mouse event tracking modes.
public static readonly string CSI_EnableMouseEvents
Field Value
CSI_EnableSgrExtModeMouse
The CSI sequence to enable SGR extended mouse mode.
public static readonly string CSI_EnableSgrExtModeMouse
Field Value
CSI_EnableUrxvtExtModeMouse
The CSI sequence to enable urxvt extended mouse mode.
public static readonly string CSI_EnableUrxvtExtModeMouse
Field Value
KeyEsc
The escape key character value.
public const char KeyEsc = '\u001b'
Field Value
Methods
GetC1ControlChar(in char)
Gets the C1 control character name for the specified character.
public static string GetC1ControlChar(in char c)
Parameters
ccharThe 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
kCharchar[]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
ckiConsoleKeyInfo[]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
ckiConsoleKeyInfo[]The array of console key information containing mouse data.
mouseFlagsList<MouseFlags>Output list of mouse flags indicating the current mouse state.
posPointOutput position of the mouse cursor.
continuousButtonPressedHandlerAction<MouseFlags, Point>Handler to invoke for continuous button press events.