Beispiel #1
0
        public static string GetText()
        {
            if (_clipboardSupported == false)
            {
                PSConsoleReadLine.Ding();
                return("");
            }

            string tool = "";
            string args = "";

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                string clipboardText = "";
                ExecuteOnStaThread(() => GetTextImpl(out clipboardText));
                return(clipboardText);
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                tool = "xclip";
                args = "-selection clipboard -out";
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                tool = "pbpaste";
            }
            else
            {
                _clipboardSupported = false;
                PSConsoleReadLine.Ding();
                return("");
            }

            return(StartProcess(tool, args));
        }
Beispiel #2
0
        public static string GetText()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                PSConsoleReadLine.Ding();
                return("");
            }

            string clipboardText = "";

            ExecuteOnStaThread(() => GetTextImpl(out clipboardText));

            return(clipboardText);
        }
Beispiel #3
0
        public static void SetText(string text)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                PSConsoleReadLine.Ding();
                return;
            }

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            ExecuteOnStaThread(() => SetClipboardData(Tuple.Create(text, CF_UNICODETEXT)));
        }
Beispiel #4
0
        public static void SetRtf(string plainText, string rtfText)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                PSConsoleReadLine.Ding();
                return;
            }

            if (CF_RTF == 0)
            {
                CF_RTF = RegisterClipboardFormat("Rich Text Format");
            }

            ExecuteOnStaThread(() => SetClipboardData(
                                   Tuple.Create(plainText, CF_UNICODETEXT),
                                   Tuple.Create(rtfText, CF_RTF)));
        }
Beispiel #5
0
        public static void SetText(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            if (_clipboardSupported == false)
            {
                _internalClipboard = text;
                PSConsoleReadLine.Ding();
                return;
            }

            string tool = "";
            string args = "";

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                ExecuteOnStaThread(() => SetClipboardData(Tuple.Create(text, CF_UNICODETEXT)));
                return;
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                tool = "xclip";
                args = "-selection clipboard -in";
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                tool = "pbcopy";
            }
            else
            {
                _clipboardSupported = false;
                PSConsoleReadLine.Ding();
                return;
            }

            StartProcess(tool, args, text);
            if (_clipboardSupported == false)
            {
                _internalClipboard = text;
            }
        }
Beispiel #6
0
        private static string StartProcess(
            string tool,
            string args,
            string stdin = ""
            )
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardInput  = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            startInfo.FileName  = tool;
            startInfo.Arguments = args;
            string stdout;

            using (Process process = new Process())
            {
                process.StartInfo = startInfo;
                try
                {
                    process.Start();
                }
                catch (System.ComponentModel.Win32Exception)
                {
                    _clipboardSupported = false;
                    PSConsoleReadLine.Ding();
                    return("");
                }

                if (stdin != "")
                {
                    process.StandardInput.Write(stdin);
                    process.StandardInput.Close();
                }
                stdout = process.StandardOutput.ReadToEnd();
                process.WaitForExit(250);

                _clipboardSupported = process.ExitCode == 0;
            }

            return(stdout);
        }