EscAsAltPattern.cs 641 B

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