namespace Terminal.Gui.App; /// Provides cut, copy, and paste support for the OS clipboard. /// /// /// DEPRECATED: This static class is obsolete. Use instead. /// /// On Windows, the class uses the Windows Clipboard APIs via P/Invoke. /// /// On Linux, when not running under Windows Subsystem for Linux (WSL), the class uses /// the xclip command line tool. If xclip is not installed, the clipboard will not work. /// /// /// On Linux, when running under Windows Subsystem for Linux (WSL), the class launches /// Windows' powershell.exe via WSL interop and uses the "Set-Clipboard" and "Get-Clipboard" Powershell CmdLets. /// /// /// On the Mac, the class uses the MacO OS X pbcopy and pbpaste command line tools and /// the Mac clipboard APIs vai P/Invoke. /// /// [Obsolete ("Use IApplication.Clipboard instead. The static Clipboard class will be removed in a future release.")] public static class Clipboard { private static string? _contents = string.Empty; /// Gets (copies from) or sets (pastes to) the contents of the OS clipboard. public static string? Contents { get { try { if (IsSupported) { // throw new InvalidOperationException ($"{Application.Driver?.GetType ().Name}.GetClipboardData returned null instead of string.Empty"); string clipData = Application.Driver?.Clipboard?.GetClipboardData () ?? string.Empty; _contents = clipData; } } catch (Exception) { _contents = string.Empty; } return _contents; } set { try { if (IsSupported) { value ??= string.Empty; Application.Driver?.Clipboard?.SetClipboardData (value); } _contents = value; } catch (Exception) { _contents = value; } } } /// Returns true if the environmental dependencies are in place to interact with the OS clipboard. /// public static bool IsSupported => Application.Driver?.Clipboard?.IsSupported ?? false; /// Gets the OS clipboard data if possible. /// The clipboard data if successful. /// if the clipboard data was retrieved successfully; otherwise, . public static bool TryGetClipboardData (out string result) { result = string.Empty; if (IsSupported && Application.Driver?.Clipboard is { }) { return Application.Driver.Clipboard.TryGetClipboardData (out result); } return false; } /// Sets the OS clipboard data if possible. /// The text to set. /// if the clipboard data was set successfully; otherwise, . public static bool TrySetClipboardData (string text) { if (IsSupported && Application.Driver?.Clipboard is { }) { return Application.Driver.Clipboard.TrySetClipboardData (text); } return false; } }