EscAsAltPattern.cs 1010 B

123456789101112131415161718192021222324252627282930313233343536
  1. #nullable enable
  2. using System.Text.RegularExpressions;
  3. namespace Terminal.Gui.Drivers;
  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([\u0001-\u001a\u001fa-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 ch = match.Groups [1].Value [0];
  19. Key key = ch switch
  20. {
  21. >= '\u0001' and <= '\u001a' => ((Key)(ch + 96)).WithCtrl,
  22. '\u001f' => Key.D7.WithCtrl.WithShift,
  23. _ => ch
  24. };
  25. return new Key (key).WithAlt;
  26. }
  27. }