NetKeyConverter.cs 894 B

12345678910111213141516171819202122232425
  1. namespace Terminal.Gui;
  2. /// <summary>
  3. /// <see cref="IKeyConverter{T}"/> capable of converting the
  4. /// dotnet <see cref="ConsoleKeyInfo"/> class into Terminal.Gui
  5. /// shared <see cref="Key"/> representation (used by <see cref="View"/>
  6. /// etc).
  7. /// </summary>
  8. internal class NetKeyConverter : IKeyConverter<ConsoleKeyInfo>
  9. {
  10. /// <inheritdoc/>
  11. public Key ToKey (ConsoleKeyInfo input)
  12. {
  13. ConsoleKeyInfo adjustedInput = EscSeqUtils.MapConsoleKeyInfo (input);
  14. // TODO : EscSeqUtils.MapConsoleKeyInfo is wrong for e.g. '{' - it winds up clearing the Key
  15. // So if the method nuked it then we should just work with the original.
  16. if (adjustedInput.Key == ConsoleKey.None && input.Key != ConsoleKey.None)
  17. {
  18. return EscSeqUtils.MapKey (input);
  19. }
  20. return EscSeqUtils.MapKey (adjustedInput);
  21. }
  22. }