PlatformDetection.cs 795 B

1234567891011121314151617181920212223242526
  1. using System.Runtime.InteropServices;
  2. namespace Terminal.Gui.Drivers;
  3. /// <summary>
  4. /// Helper class for detecting platform-specific features.
  5. /// </summary>
  6. internal static class PlatformDetection
  7. {
  8. /// <summary>
  9. /// Determines if the current platform is WSL (Windows Subsystem for Linux).
  10. /// </summary>
  11. /// <returns>True if running on WSL, false otherwise.</returns>
  12. public static bool IsWSLPlatform ()
  13. {
  14. // xclip does not work on WSL, so we need to use the Windows clipboard via Powershell
  15. (int exitCode, string result) = ClipboardProcessRunner.Bash ("uname -a", waitForOutput: true);
  16. if (exitCode == 0 && result.Contains ("microsoft") && result.Contains ("WSL"))
  17. {
  18. return true;
  19. }
  20. return false;
  21. }
  22. }