UnixKeyConverter.cs 960 B

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