diff --git a/test/PSReadLine/App.config b/test/PSReadLine/App.config new file mode 100644 index 000000000..8e1564635 --- /dev/null +++ b/test/PSReadLine/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/test/PSReadLine/AssemblyInfo.cs b/test/PSReadLine/AssemblyInfo.cs new file mode 100644 index 000000000..694177ab7 --- /dev/null +++ b/test/PSReadLine/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TestPSReadLine")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TestPSReadLine")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("2892ed9f-6820-48a0-819b-0452c3b5401b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/test/PSReadLine/Program.cs b/test/PSReadLine/Program.cs new file mode 100644 index 000000000..0c602c8a4 --- /dev/null +++ b/test/PSReadLine/Program.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; +using System.Management.Automation.Runspaces; +using Microsoft.PowerShell; + +namespace TestPSReadLine +{ + class Program + { + static void CauseCrash(ConsoleKeyInfo? key = null, object arg = null) + { + throw new Exception("intentional crash for test purposes"); + } + + [STAThread] + static void Main() + { + //Box(new List {"abc", " def", "this is something coo"}); + + var iss = InitialSessionState.CreateDefault2(); + var rs = RunspaceFactory.CreateRunspace(iss); + rs.Open(); + Runspace.DefaultRunspace = rs; + + PSConsoleReadLine.SetOptions(new SetPSReadlineOption + { + EditMode = EditMode.Emacs, + HistoryNoDuplicates = true, + }); + PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+LeftArrow"}, PSConsoleReadLine.ShellBackwardWord, "", ""); + PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+RightArrow"}, PSConsoleReadLine.ShellNextWord, "", ""); + PSConsoleReadLine.SetKeyHandler(new[] {"F4"}, PSConsoleReadLine.HistorySearchBackward, "", ""); + PSConsoleReadLine.SetKeyHandler(new[] {"F5"}, PSConsoleReadLine.HistorySearchForward, "", ""); + //PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+E"}, PSConsoleReadLine.EnableDemoMode, "", ""); + //PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+D"}, PSConsoleReadLine.DisableDemoMode, "", ""); + // PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+C"}, PSConsoleReadLine.CaptureScreen, "", ""); + PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+P"}, PSConsoleReadLine.InvokePrompt, "", ""); + PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+X"}, CauseCrash, "", ""); + PSConsoleReadLine.SetKeyHandler(new[] {"F6"}, PSConsoleReadLine.PreviousLine, "", ""); + PSConsoleReadLine.SetKeyHandler(new[] {"F7"}, PSConsoleReadLine.NextLine, "", ""); + PSConsoleReadLine.SetKeyHandler(new[] {"F2"}, PSConsoleReadLine.ValidateAndAcceptLine, "", ""); + PSConsoleReadLine.SetKeyHandler(new[] {"Enter"}, PSConsoleReadLine.AcceptLine, "", ""); + + + EngineIntrinsics executionContext; + using (var ps = PowerShell.Create(RunspaceMode.CurrentRunspace)) + { + executionContext = + ps.AddScript("$ExecutionContext").Invoke().FirstOrDefault(); + + // This is a workaround to ensure the command analysis cache has been created before + // we enter into ReadLine. It's a little slow and infrequently needed, so just + // uncomment if you hit a hang, run it once, then comment it out again. + //ps.Commands.Clear(); + //ps.AddCommand("Get-Command").Invoke(); + } + + while (true) + { + Console.Write("TestHostPS> "); + + var line = PSConsoleReadLine.ReadLine(null, executionContext); + Console.WriteLine(line); + line = line.Trim(); + if (line.Equals("exit")) + Environment.Exit(0); + if (line.Equals("cmd")) + PSConsoleReadLine.SetOptions(new SetPSReadlineOption {EditMode = EditMode.Windows}); + if (line.Equals("emacs")) + PSConsoleReadLine.SetOptions(new SetPSReadlineOption {EditMode = EditMode.Emacs}); + if (line.Equals("vi")) + PSConsoleReadLine.SetOptions(new SetPSReadlineOption {EditMode = EditMode.Vi}); + if (line.Equals("nodupes")) + PSConsoleReadLine.SetOptions(new SetPSReadlineOption {HistoryNoDuplicates = true}); + } + } + } +} diff --git a/test/PSReadLine/TestPSReadLine.csproj b/test/PSReadLine/TestPSReadLine.csproj new file mode 100644 index 000000000..2606687ae --- /dev/null +++ b/test/PSReadLine/TestPSReadLine.csproj @@ -0,0 +1,74 @@ + + + + + Debug + AnyCPU + {08218B1A-8B85-4722-9E3F-4D6C0BF58AD8} + Exe + Properties + TestPSReadLine + TestPSReadLine + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + true + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + true + + + + + + ..\PSReadLine\packages\Microsoft.PowerShell.3.ReferenceAssemblies.1.0.0\lib\net4\System.Management.Automation.dll + True + + + + + + + + + + + + + + + + + + {615788cb-1b9a-4b34-97b3-4608686e59ca} + PSReadLine + + + + + + + + \ No newline at end of file diff --git a/test/PSReadLine/packages.config b/test/PSReadLine/packages.config new file mode 100644 index 000000000..cae6c6db8 --- /dev/null +++ b/test/PSReadLine/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/test/PSReadLine/project.json b/test/PSReadLine/project.json new file mode 100644 index 000000000..80263abfb --- /dev/null +++ b/test/PSReadLine/project.json @@ -0,0 +1,32 @@ +{ + "name": "TestPSReadLine", + "version": "1.0.0-*", + "description": "PSReadLine basic tests", + + "compilationOptions": { + "warningsAsErrors": true, + "emitEntryPoint": true + }, + + "dependencies": { + "Microsoft.PowerShell.PSReadLine": "1.0.0-*" + }, + + "frameworks": { + "netcoreapp1.0": { + "imports": [ "dnxcore50", "portable-net45+win8" ], + "dependencies": { + "Microsoft.NETCore.App": "1.0.0-rc2-3002485" + } + } + }, + + "runtimes": { + "ubuntu.14.04-x64": { }, + "centos.7.1-x64": { }, + "win7-x64": { }, + "win10-x64": { }, + "osx.10.10-x64": { }, + "osx.10.11-x64": { } + } +}