UnixKeyConverter.cs 981 B

12345678910111213141516171819202122232425262728293031
  1. #nullable enable
  2. namespace Terminal.Gui.Drivers;
  3. /// <summary>
  4. /// <see cref="IKeyConverter{T}"/> capable of converting the
  5. /// unix native <see cref="char"/> class
  6. /// into Terminal.Gui shared <see cref="Key"/> representation
  7. /// (used by <see cref="View"/> etc).
  8. /// </summary>
  9. internal class UnixKeyConverter : IKeyConverter<char>
  10. {
  11. /// <inheritdoc/>
  12. public Key ToKey (char value)
  13. {
  14. ConsoleKeyInfo adjustedInput = EscSeqUtils.MapChar (value);
  15. return EscSeqUtils.MapKey (adjustedInput);
  16. }
  17. /// <inheritdoc/>
  18. public char ToKeyInfo (Key key)
  19. {
  20. // Convert Key to ConsoleKeyInfo using the cross-platform mapping utility
  21. ConsoleKeyInfo consoleKeyInfo = ConsoleKeyMapping.GetConsoleKeyInfoFromKeyCode (key.KeyCode);
  22. // Return the character representation
  23. // For Unix, we primarily care about the KeyChar as Unix deals with character input
  24. return consoleKeyInfo.KeyChar;
  25. }
  26. }