From 407dc9d3115979047d01752d5558e98a567a90a8 Mon Sep 17 00:00:00 2001 From: Tom Laird-McConenll Date: Thu, 9 Jan 2025 10:00:16 -0800 Subject: [PATCH] update for wsl --- .gitignore | 1 + .../PlatformSupportExtensions.cs | 33 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 1cff3edc..d2892cdd 100644 --- a/.gitignore +++ b/.gitignore @@ -767,3 +767,4 @@ fabric.properties *.sln.iml /src/Tools/Consolonia.PreviewHost/Properties/launchSettings.json +src/.vscode/launch.json diff --git a/src/Consolonia.PlatformSupport/PlatformSupportExtensions.cs b/src/Consolonia.PlatformSupport/PlatformSupportExtensions.cs index 0afdf253..2581a16f 100644 --- a/src/Consolonia.PlatformSupport/PlatformSupportExtensions.cs +++ b/src/Consolonia.PlatformSupport/PlatformSupportExtensions.cs @@ -60,11 +60,28 @@ public static AppBuilder UseAutoDectectedClipboard(this AppBuilder builder) } else if (OperatingSystem.IsLinux()) { - return builder.With(new X11Clipboard()); + if (IsWSLPlatform()) + return builder.With(new WSLClipboard()); + else + return builder.With(new XClipClipboard()); } else return builder.With(new NaiveClipboard()); } + + private static bool IsWSLPlatform() + { + // xclip does not work on WSL, so we need to use the Windows clipboard vis Powershell + (int exitCode, string result) = ClipboardProcessRunner.Bash("uname -a", waitForOutput: true); + + if (exitCode == 0 && result.Contains("microsoft") && result.Contains("WSL")) + { + return true; + } + + return false; + } + public static AppBuilder UseAutoDetectConsoleColorMode(this AppBuilder builder) { @@ -75,13 +92,13 @@ public static AppBuilder UseAutoDetectConsoleColorMode(this AppBuilder builder) switch (Environment.OSVersion.Platform) { case PlatformID.Win32S or PlatformID.Win32Windows or PlatformID.Win32NT: - { - // if output is redirected, or we are a windows terminal we use the win32 ANSI based console. - if (Console.IsOutputRedirected || IsWindowsTerminal()) - result = new RgbConsoleColorMode(); - else - result = new EgaConsoleColorMode(); - } + { + // if output is redirected, or we are a windows terminal we use the win32 ANSI based console. + if (Console.IsOutputRedirected || IsWindowsTerminal()) + result = new RgbConsoleColorMode(); + else + result = new EgaConsoleColorMode(); + } break; case PlatformID.MacOSX: result = new RgbConsoleColorMode();