2
0

EscAsAltPattern.cs 990 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Text.RegularExpressions;
  2. namespace Terminal.Gui.Drivers;
  3. internal class EscAsAltPattern : AnsiKeyboardParserPattern
  4. {
  5. public EscAsAltPattern () { IsLastMinute = true; }
  6. #pragma warning disable IDE1006 // Naming Styles
  7. private static readonly Regex _pattern = new (@"^\u001b([\u0001-\u001a\u001fa-zA-Z0-9_])$");
  8. #pragma warning restore IDE1006 // Naming Styles
  9. public override bool IsMatch (string? input) { return _pattern.IsMatch (input!); }
  10. protected override Key? GetKeyImpl (string? input)
  11. {
  12. Match match = _pattern.Match (input!);
  13. if (!match.Success)
  14. {
  15. return null;
  16. }
  17. char ch = match.Groups [1].Value [0];
  18. Key key = ch switch
  19. {
  20. >= '\u0001' and <= '\u001a' => ((Key)(ch + 96)).WithCtrl,
  21. '\u001f' => Key.D7.WithCtrl.WithShift,
  22. _ => ch
  23. };
  24. return new Key (key).WithAlt;
  25. }
  26. }