EscAsAltPattern.cs 743 B

1234567891011121314151617181920212223242526272829
  1. #nullable enable
  2. using System.Text.RegularExpressions;
  3. namespace Terminal.Gui;
  4. internal class EscAsAltPattern : AnsiKeyboardParserPattern
  5. {
  6. public EscAsAltPattern () { IsLastMinute = true; }
  7. #pragma warning disable IDE1006 // Naming Styles
  8. private static readonly Regex _pattern = new (@"^\u001b([a-zA-Z0-9_])$");
  9. #pragma warning restore IDE1006 // Naming Styles
  10. public override bool IsMatch (string? input) { return _pattern.IsMatch (input!); }
  11. protected override Key? GetKeyImpl (string? input)
  12. {
  13. Match match = _pattern.Match (input!);
  14. if (!match.Success)
  15. {
  16. return null;
  17. }
  18. char key = match.Groups [1].Value [0];
  19. return new Key (key).WithAlt;
  20. }
  21. }