mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
inital impl
This commit is contained in:
@@ -57,17 +57,21 @@ namespace Terminal.Gui {
|
|||||||
|
|
||||||
static bool sync = false;
|
static bool sync = false;
|
||||||
|
|
||||||
public FakeDriver ()
|
public FakeDriver (bool useFakeClipboard = true)
|
||||||
{
|
{
|
||||||
if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
|
if (useFakeClipboard) {
|
||||||
Clipboard = new WindowsClipboard ();
|
Clipboard = new FakeClipboard ();
|
||||||
} else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) {
|
|
||||||
Clipboard = new MacOSXClipboard ();
|
|
||||||
} else {
|
} else {
|
||||||
if (CursesDriver.Is_WSL_Platform ()) {
|
if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
|
||||||
Clipboard = new WSLClipboard ();
|
Clipboard = new WindowsClipboard ();
|
||||||
|
} else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) {
|
||||||
|
Clipboard = new MacOSXClipboard ();
|
||||||
} else {
|
} else {
|
||||||
Clipboard = new CursesClipboard ();
|
if (CursesDriver.Is_WSL_Platform ()) {
|
||||||
|
Clipboard = new WSLClipboard ();
|
||||||
|
} else {
|
||||||
|
Clipboard = new CursesClipboard ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -641,6 +645,23 @@ namespace Terminal.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public class FakeClipboard : ClipboardBase {
|
||||||
|
public override bool IsSupported => true;
|
||||||
|
|
||||||
|
string contents = string.Empty;
|
||||||
|
|
||||||
|
protected override string GetClipboardDataImpl ()
|
||||||
|
{
|
||||||
|
return contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void SetClipboardDataImpl (string text)
|
||||||
|
{
|
||||||
|
contents = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,9 +5,9 @@ using Xunit;
|
|||||||
namespace Terminal.Gui.Core {
|
namespace Terminal.Gui.Core {
|
||||||
public class ClipboardTests {
|
public class ClipboardTests {
|
||||||
[Fact]
|
[Fact]
|
||||||
[AutoInitShutdown]
|
|
||||||
public void Contents_Gets_Sets ()
|
public void Contents_Gets_Sets ()
|
||||||
{
|
{
|
||||||
|
Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
||||||
var clipText = "This is a clipboard unit test.";
|
var clipText = "This is a clipboard unit test.";
|
||||||
Clipboard.Contents = clipText;
|
Clipboard.Contents = clipText;
|
||||||
|
|
||||||
@@ -16,23 +16,25 @@ namespace Terminal.Gui.Core {
|
|||||||
Application.Run ();
|
Application.Run ();
|
||||||
|
|
||||||
Assert.Equal (clipText, Clipboard.Contents);
|
Assert.Equal (clipText, Clipboard.Contents);
|
||||||
|
Application.Shutdown ();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[AutoInitShutdown]
|
|
||||||
public void IsSupported_Get ()
|
public void IsSupported_Get ()
|
||||||
{
|
{
|
||||||
|
Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
||||||
if (Clipboard.IsSupported) {
|
if (Clipboard.IsSupported) {
|
||||||
Assert.True (Clipboard.IsSupported);
|
Assert.True (Clipboard.IsSupported);
|
||||||
} else {
|
} else {
|
||||||
Assert.False (Clipboard.IsSupported);
|
Assert.False (Clipboard.IsSupported);
|
||||||
}
|
}
|
||||||
|
Application.Shutdown ();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[AutoInitShutdown]
|
|
||||||
public void TryGetClipboardData_Gets_From_OS_Clipboard ()
|
public void TryGetClipboardData_Gets_From_OS_Clipboard ()
|
||||||
{
|
{
|
||||||
|
Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
||||||
var clipText = "Trying to get from the OS clipboard.";
|
var clipText = "Trying to get from the OS clipboard.";
|
||||||
Clipboard.Contents = clipText;
|
Clipboard.Contents = clipText;
|
||||||
|
|
||||||
@@ -47,12 +49,13 @@ namespace Terminal.Gui.Core {
|
|||||||
Assert.False (Clipboard.TryGetClipboardData (out string result));
|
Assert.False (Clipboard.TryGetClipboardData (out string result));
|
||||||
Assert.NotEqual (clipText, result);
|
Assert.NotEqual (clipText, result);
|
||||||
}
|
}
|
||||||
|
Application.Shutdown ();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[AutoInitShutdown]
|
|
||||||
public void TrySetClipboardData_Sets_The_OS_Clipboard ()
|
public void TrySetClipboardData_Sets_The_OS_Clipboard ()
|
||||||
{
|
{
|
||||||
|
Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
||||||
var clipText = "Trying to set the OS clipboard.";
|
var clipText = "Trying to set the OS clipboard.";
|
||||||
if (Clipboard.IsSupported) {
|
if (Clipboard.IsSupported) {
|
||||||
Assert.True (Clipboard.TrySetClipboardData (clipText));
|
Assert.True (Clipboard.TrySetClipboardData (clipText));
|
||||||
@@ -69,12 +72,13 @@ namespace Terminal.Gui.Core {
|
|||||||
} else {
|
} else {
|
||||||
Assert.NotEqual (clipText, Clipboard.Contents);
|
Assert.NotEqual (clipText, Clipboard.Contents);
|
||||||
}
|
}
|
||||||
|
Application.Shutdown ();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[AutoInitShutdown]
|
|
||||||
public void Contents_Gets_From_OS_Clipboard ()
|
public void Contents_Gets_From_OS_Clipboard ()
|
||||||
{
|
{
|
||||||
|
Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
||||||
var clipText = "This is a clipboard unit test to get clipboard from OS.";
|
var clipText = "This is a clipboard unit test to get clipboard from OS.";
|
||||||
var exit = false;
|
var exit = false;
|
||||||
var getClipText = "";
|
var getClipText = "";
|
||||||
@@ -189,12 +193,13 @@ namespace Terminal.Gui.Core {
|
|||||||
if (!exit) {
|
if (!exit) {
|
||||||
Assert.Equal (clipText, getClipText);
|
Assert.Equal (clipText, getClipText);
|
||||||
}
|
}
|
||||||
|
Application.Shutdown ();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[AutoInitShutdown]
|
|
||||||
public void Contents_Sets_The_OS_Clipboard ()
|
public void Contents_Sets_The_OS_Clipboard ()
|
||||||
{
|
{
|
||||||
|
Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
||||||
var clipText = "This is a clipboard unit test to set the OS clipboard.";
|
var clipText = "This is a clipboard unit test to set the OS clipboard.";
|
||||||
var clipReadText = "";
|
var clipReadText = "";
|
||||||
var exit = false;
|
var exit = false;
|
||||||
@@ -274,6 +279,7 @@ namespace Terminal.Gui.Core {
|
|||||||
if (!exit) {
|
if (!exit) {
|
||||||
Assert.Equal (clipText, clipReadText);
|
Assert.Equal (clipText, clipReadText);
|
||||||
}
|
}
|
||||||
|
Application.Shutdown ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Is_WSL_Platform ()
|
bool Is_WSL_Platform ()
|
||||||
|
|||||||
Reference in New Issue
Block a user