#nullable enable using System.Text.RegularExpressions; namespace Terminal.Gui; /// /// Parser for SS3 terminal escape sequences. These describe specific keys e.g. /// EscOP is F1. /// public class Ss3Pattern : AnsiKeyboardParserPattern { #pragma warning disable IDE1006 // Naming Styles private static readonly Regex _pattern = new (@"^\u001bO([PQRStDCAB])$"); #pragma warning restore IDE1006 // Naming Styles /// public override bool IsMatch (string? input) { return _pattern.IsMatch (input!); } /// /// Returns the ss3 key that corresponds to the provided input escape sequence /// /// /// protected override Key? GetKeyImpl (string? input) { Match match = _pattern.Match (input!); if (!match.Success) { return null; } return match.Groups [1].Value.Single () switch { 'P' => Key.F1, 'Q' => Key.F2, 'R' => Key.F3, 'S' => Key.F4, 't' => Key.F5, 'D' => Key.CursorLeft, 'C' => Key.CursorRight, 'A' => Key.CursorUp, 'B' => Key.CursorDown, _ => null }; } }