Ss3Pattern.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Text.RegularExpressions;
  2. namespace Terminal.Gui.Drivers;
  3. /// <summary>
  4. /// Parser for SS3 terminal escape sequences. These describe specific keys e.g.
  5. /// <c>EscOP</c> is F1.
  6. /// </summary>
  7. public class Ss3Pattern : AnsiKeyboardParserPattern
  8. {
  9. #pragma warning disable IDE1006 // Naming Styles
  10. private static readonly Regex _pattern = new (@"^\u001bO([PQRStDCABOHFwqysu])$");
  11. #pragma warning restore IDE1006 // Naming Styles
  12. /// <inheritdoc/>
  13. public override bool IsMatch (string? input) { return _pattern.IsMatch (input!); }
  14. /// <summary>
  15. /// Returns the ss3 key that corresponds to the provided input escape sequence
  16. /// </summary>
  17. /// <param name="input"></param>
  18. /// <returns></returns>
  19. protected override Key? GetKeyImpl (string? input)
  20. {
  21. Match match = _pattern.Match (input!);
  22. if (!match.Success)
  23. {
  24. return null;
  25. }
  26. return match.Groups [1].Value.Single () switch
  27. {
  28. 'P' => Key.F1,
  29. 'Q' => Key.F2,
  30. 'R' => Key.F3,
  31. 'S' => Key.F4,
  32. 't' => Key.F5,
  33. 'D' => Key.CursorLeft,
  34. 'C' => Key.CursorRight,
  35. 'A' => Key.CursorUp,
  36. 'B' => Key.CursorDown,
  37. 'H' => Key.Home,
  38. 'F' => Key.End,
  39. 'w' => Key.Home,
  40. 'q' => Key.End,
  41. 'y' => Key.PageUp,
  42. 's' => Key.PageDown,
  43. 'u' => Key.Clear,
  44. _ => null
  45. };
  46. }
  47. }