Browse Source

Merge branch 'develop' into v_1_8_0

Tig Kindel 2 years ago
parent
commit
bbac50bb79
3 changed files with 109 additions and 105 deletions
  1. 1 1
      Example/Example.csproj
  2. 1 1
      Terminal.Gui/Terminal.Gui.csproj
  3. 107 103
      UnitTests/ClipboardTests.cs

+ 1 - 1
Example/Example.csproj

@@ -11,7 +11,7 @@
     <InformationalVersion>1.0</InformationalVersion>
   </PropertyGroup>
   <ItemGroup>
-    <PackageReference Include="NStack.Core" Version="0.17.1" />
+    <PackageReference Include="NStack.Core" Version="1.0.1" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Terminal.Gui\Terminal.Gui.csproj" />

+ 1 - 1
Terminal.Gui/Terminal.Gui.csproj

@@ -17,7 +17,7 @@
   </PropertyGroup>
   <ItemGroup>
     <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
-    <PackageReference Include="NStack.Core" Version="0.17.1" />
+    <PackageReference Include="NStack.Core" Version="1.0.1" />
     <InternalsVisibleTo Include="UnitTests" />
   </ItemGroup>
   <!-- Uncomment the RestoreSources element to have dotnet restore pull NStack from a local dir for testing -->

+ 107 - 103
UnitTests/ClipboardTests.cs

@@ -53,21 +53,23 @@ namespace Terminal.Gui.Core {
 		[AutoInitShutdown]
 		public void TrySetClipboardData_Sets_The_OS_Clipboard ()
 		{
-			var clipText = "Trying to set the OS clipboard.";
-			if (Clipboard.IsSupported) {
-				Assert.True (Clipboard.TrySetClipboardData (clipText));
-			} else {
-				Assert.False (Clipboard.TrySetClipboardData (clipText));
-			}
+			lock (Clipboard.Contents) {
+				var clipText = "Trying to set the OS clipboard.";
+				if (Clipboard.IsSupported) {
+					Assert.True (Clipboard.TrySetClipboardData (clipText));
+				} else {
+					Assert.False (Clipboard.TrySetClipboardData (clipText));
+				}
 
-			Application.Iteration += () => Application.RequestStop ();
+				Application.Iteration += () => Application.RequestStop ();
 
-			Application.Run ();
+				Application.Run ();
 
-			if (Clipboard.IsSupported) {
-				Assert.Equal (clipText, Clipboard.Contents);
-			} else {
-				Assert.NotEqual (clipText, Clipboard.Contents);
+				if (Clipboard.IsSupported) {
+					Assert.Equal (clipText, Clipboard.Contents);
+				} else {
+					Assert.NotEqual (clipText, Clipboard.Contents);
+				}
 			}
 		}
 
@@ -79,110 +81,112 @@ namespace Terminal.Gui.Core {
 			var exit = false;
 			var getClipText = "";
 
-			Application.Iteration += () => {
-				if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
-					// using (Process clipExe = new Process {
-					// 	StartInfo = new ProcessStartInfo {
-					// 		RedirectStandardInput = true,
-					// 		FileName = "clip"
-					// 	}
-					// }) {
-					// 	clipExe.Start ();
-					// 	clipExe.StandardInput.Write (clipText);
-					// 	clipExe.StandardInput.Close ();
-					// 	var result = clipExe.WaitForExit (500);
-					// 	if (result) {
-					// 		clipExe.WaitForExit ();
-					// 	}
-					// }
-
-					using (Process pwsh = new Process {
-						StartInfo = new ProcessStartInfo {
-							FileName = "powershell",
-							Arguments = $"-command \"Set-Clipboard -Value \\\"{clipText}\\\"\""
+			lock (Clipboard.Contents) {
+				Application.Iteration += () => {
+					if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
+						// using (Process clipExe = new Process {
+						// 	StartInfo = new ProcessStartInfo {
+						// 		RedirectStandardInput = true,
+						// 		FileName = "clip"
+						// 	}
+						// }) {
+						// 	clipExe.Start ();
+						// 	clipExe.StandardInput.Write (clipText);
+						// 	clipExe.StandardInput.Close ();
+						// 	var result = clipExe.WaitForExit (500);
+						// 	if (result) {
+						// 		clipExe.WaitForExit ();
+						// 	}
+						// }
+
+						using (Process pwsh = new Process {
+							StartInfo = new ProcessStartInfo {
+								FileName = "powershell",
+								Arguments = $"-command \"Set-Clipboard -Value \\\"{clipText}\\\"\""
+							}
+						}) {
+							pwsh.Start ();
+							pwsh.WaitForExit ();
 						}
-					}) {
-						pwsh.Start ();
-						pwsh.WaitForExit ();
-					}
-					getClipText = Clipboard.Contents.ToString ();
+						getClipText = Clipboard.Contents.ToString ();
 
-				} else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) {
-					using (Process copy = new Process {
-						StartInfo = new ProcessStartInfo {
-							RedirectStandardInput = true,
-							FileName = "pbcopy"
+					} else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) {
+						using (Process copy = new Process {
+							StartInfo = new ProcessStartInfo {
+								RedirectStandardInput = true,
+								FileName = "pbcopy"
+							}
+						}) {
+							copy.Start ();
+							copy.StandardInput.Write (clipText);
+							copy.StandardInput.Close ();
+							copy.WaitForExit ();
 						}
-					}) {
-						copy.Start ();
-						copy.StandardInput.Write (clipText);
-						copy.StandardInput.Close ();
-						copy.WaitForExit ();
-					}
-					getClipText = Clipboard.Contents.ToString ();
+						getClipText = Clipboard.Contents.ToString ();
 
-				} else if (RuntimeInformation.IsOSPlatform (OSPlatform.Linux)) {
-					if (Is_WSL_Platform ()) {
-						try {
-							using (Process bash = new Process {
-								StartInfo = new ProcessStartInfo {
-									FileName = "powershell.exe",
-									Arguments = $"-noprofile -command \"Set-Clipboard -Value \\\"{clipText}\\\"\""
+					} else if (RuntimeInformation.IsOSPlatform (OSPlatform.Linux)) {
+						if (Is_WSL_Platform ()) {
+							try {
+								using (Process bash = new Process {
+									StartInfo = new ProcessStartInfo {
+										FileName = "powershell.exe",
+										Arguments = $"-noprofile -command \"Set-Clipboard -Value \\\"{clipText}\\\"\""
+									}
+								}) {
+									bash.Start ();
+									bash.WaitForExit ();
 								}
-							}) {
-								bash.Start ();
-								bash.WaitForExit ();
+
+								//using (Process clipExe = new Process {
+								//	StartInfo = new ProcessStartInfo {
+								//		RedirectStandardInput = true,
+								//		FileName = "clip.exe"
+								//	}
+								//}) {
+								//	clipExe.Start ();
+								//	clipExe.StandardInput.Write (clipText);
+								//	clipExe.StandardInput.Close ();
+								//	clipExe.WaitForExit ();
+								//	//var result = clipExe.WaitForExit (500);
+								//	//if (result) {
+								//	//	clipExe.WaitForExit ();
+								//	//}
+								//}
+							} catch {
+								exit = true;
+							}
+							if (!exit) {
+								getClipText = Clipboard.Contents.ToString ();
 							}
+							Application.RequestStop ();
+							return;
+						}
+						if (exit = xclipExists () == false) {
+							// xclip doesn't exist then exit.
+							Application.RequestStop ();
+							return;
+						}
 
-							//using (Process clipExe = new Process {
-							//	StartInfo = new ProcessStartInfo {
-							//		RedirectStandardInput = true,
-							//		FileName = "clip.exe"
-							//	}
-							//}) {
-							//	clipExe.Start ();
-							//	clipExe.StandardInput.Write (clipText);
-							//	clipExe.StandardInput.Close ();
-							//	clipExe.WaitForExit ();
-							//	//var result = clipExe.WaitForExit (500);
-							//	//if (result) {
-							//	//	clipExe.WaitForExit ();
-							//	//}
-							//}
-						} catch {
-							exit = true;
+						using (Process bash = new Process {
+							StartInfo = new ProcessStartInfo {
+								FileName = "bash",
+								Arguments = $"-c \"xclip -sel clip -i\"",
+								RedirectStandardInput = true,
+							}
+						}) {
+							bash.Start ();
+							bash.StandardInput.Write (clipText);
+							bash.StandardInput.Close ();
+							bash.WaitForExit ();
 						}
 						if (!exit) {
 							getClipText = Clipboard.Contents.ToString ();
 						}
-						Application.RequestStop ();
-						return;
-					}
-					if (exit = xclipExists () == false) {
-						// xclip doesn't exist then exit.
-						Application.RequestStop ();
-						return;
 					}
 
-					using (Process bash = new Process {
-						StartInfo = new ProcessStartInfo {
-							FileName = "bash",
-							Arguments = $"-c \"xclip -sel clip -i\"",
-							RedirectStandardInput = true,
-						}
-					}) {
-						bash.Start ();
-						bash.StandardInput.Write (clipText);
-						bash.StandardInput.Close ();
-						bash.WaitForExit ();
-					}
-					if (!exit) {
-						getClipText = Clipboard.Contents.ToString ();
-					}
-				}
-
-				Application.RequestStop ();
-			};
+					Application.RequestStop ();
+				};
+			}
 
 			Application.Run ();