mucking with xclip

This commit is contained in:
Charlie Kindel
2022-11-08 20:56:43 -07:00
parent aca4ab3eae
commit 601413f9ef
2 changed files with 10 additions and 6 deletions

View File

@@ -27,6 +27,7 @@ jobs:
- name: Test
run: |
xclip -version
dotnet test --no-restore --verbosity normal --collect:"XPlat Code Coverage" --settings UnitTests/coverlet.runsettings
mv -v UnitTests/TestResults/*/*.* UnitTests/TestResults/

View File

@@ -1294,13 +1294,15 @@ namespace Terminal.Gui {
protected override string GetClipboardDataImpl ()
{
var tempFileName = System.IO.Path.GetTempFileName ();
var xclipargs = "-selection clipboard -o";
try {
var (exitCode, result) = ClipboardProcessRunner.Bash ($"{xclipPath} -selection clipboard -o > {tempFileName}");
var (exitCode, result) = ClipboardProcessRunner.Bash ($"{xclipPath} {xclipargs} > {tempFileName}");
if (exitCode == 0) {
return System.IO.File.ReadAllText (tempFileName);
}
} catch (Exception e) {
throw new NotSupportedException ($"{xclipPath} -selection clipboard -o failed.", e);
throw new NotSupportedException ($"\"{xclipPath} {xclipargs}\" failed.", e);
} finally {
System.IO.File.Delete (tempFileName);
}
@@ -1309,22 +1311,23 @@ namespace Terminal.Gui {
protected override void SetClipboardDataImpl (string text)
{
var xclipargs = "-selection clipboard -i";
try {
ClipboardProcessRunner.Bash ($"{xclipPath} - selection clipboard -i", false, text);
ClipboardProcessRunner.Bash ($"{xclipPath} {xclipargs}", text);
} catch (Exception e) {
throw new NotSupportedException ($"{xclipPath} -selection clipboard -o failed", e);
throw new NotSupportedException ($"\"{xclipPath} {xclipargs} < {text}\" failed", e);
}
}
}
internal static class ClipboardProcessRunner {
public static (int exitCode, string result) Bash (string commandLine, bool output = true, string inputText = "", bool runCurses = true)
public static (int exitCode, string result) Bash (string commandLine, string inputText = "")
{
var arguments = $"-c \"{commandLine}\"";
var (exitCode, result) = Process ("bash", arguments, inputText);
if (exitCode == 0) {
if (runCurses && Application.Driver is CursesDriver) {
if (Application.Driver is CursesDriver) {
Curses.raw ();
Curses.noecho ();
}