NetKeyConverter.cs 903 B

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