mirror of
https://github.com/PowerShell/PowerShell.git
synced 2024-11-24 02:04:07 +08:00
Import TestPSReadLine app
This app is used for basic PSReadLine functionality testing. Squashed commit of the following: commit 3c1ac0aa87df663d0cfb1346352fd240a6ad1fa4 Author: jason@truewheels.net <jason@truewheels.net> Date: Sun Dec 13 09:23:31 2015 -0800 Use nuget packages for PowerShell SDK. commit 0fe7731a68d62af9508200a067aa162cb5154f68 Author: jason@truewheels.net <jason@truewheels.net> Date: Sat Nov 14 20:11:50 2015 -0800 Merge branch 'master' of https://github.com/srdubya/PSReadLine into vimode commit aa6510e19887dd2cb1ed7fa06b172dc456b0cede Author: Jason Shirk (POWERSHELL) <jasonsh@microsoft.com> Date: Thu Jun 18 18:24:23 2015 -0700 Fix/suppress various FxCop errors commit d59a997c3a2b4d18b91e0f937fc4ff76e58929f1 Author: Jason Shirk (POWERSHELL) <jasonsh@microsoft.com> Date: Thu Jun 18 15:32:20 2015 -0700 Rename namespace PSConsoleUtilities to Microsoft.PowerShell commit 258a8f28db90d98b8785487516544836ce42bb4e Author: jason@truewheels.net <jason@truewheels.net> Date: Fri Sep 26 18:15:19 2014 -0700 Fix exception after AcceptAndGetNext The "current" line cleared after accepting via AcceptAndGetNext and we would crash trying to recall this current line. I've changed how history search works after AcceptAndGetNext to work in a more natural way so that arrow keys can be used to recall commands near the accepted command instead of searching for other commands with the same prefix. Fixes #152. commit e069ed088a9ea970d8b0e9cdb990da5ad4d20f01 Author: jason@truewheels.net <jason@truewheels.net> Date: Tue Sep 9 17:36:59 2014 -0700 Add ValidateAndAcceptLine function To avoid cluttering the screen and history with command lines that don't work because of stupid errors like "command not found", you can bind enter to ValidateAndAcceptLine. commit cb81fa2cc4708ee54214320dc6ce8564e38a1642 Author: jason@truewheels.net <jason@truewheels.net> Date: Fri Jun 27 20:58:57 2014 -0700 Fix prompt error highlight characters When deciding what character to color red for errors, we were using IsSymbol - that was a bit too restrictive so it was changed to be any non-whitespace and non-alphanumeric characters. Fixes #127 commit 0ecd15d909ea31ccd9390c15d295af2f750d0d68 Author: Jason Shirk <jason@truewheels.net> Date: Thu Jun 12 14:09:17 2014 -0700 Attempt better recovery from an exception If an exception occurs when editing the command line, display some diagnostic information so that I might get a bug report. Also attempt to restore the command line so they can continue editing. commit 079d18223c7e49638c96f4533d27198b47a5d2bb Author: jason@truewheels.net <jason@truewheels.net> Date: Thu Apr 17 09:28:04 2014 -0700 Tweak for easier testing commit d79bf5056bdef0a165ee453c5f7b45e528cc0681 Author: jason@truewheels.net <jason@truewheels.net> Date: Sun Apr 13 11:21:30 2014 -0700 Cleanup some Resharper issues commit 1258dd12cab81d07aa52d388468ee9ef99063664 Author: jason@truewheels.net <jason@truewheels.net> Date: Sun Jan 26 20:21:22 2014 -0800 InvokePrompt tests Removed Console.WriteLine replacement as it didn't work for InvokePrompt. Changed test harness to override VS and actually write stdout to the screen. commit 526b0b5123c88cd8f47a166f376f34356976edb5 Author: jason@truewheels.net <jason@truewheels.net> Date: Fri Jan 24 23:00:48 2014 -0800 Remove custom bindings commit fd0679c0da99da5ae4e1d5a59842b1fb0a9af6c2 Author: jason@truewheels.net <jason@truewheels.net> Date: Fri Jan 3 00:09:49 2014 -0800 Add CaptureScreen function CaputureScreen is used to copy lines from the screen to the clipboard. Text is copied in plain text as well as rtf with colors. Rtf looks best in Outlook - which is my primary reason for adding the feature. commit e2a0b53f72a0e6a39a9736a3c1a3d2a6b1b81184 Author: Jason Shirk <jason@truewheels.net> Date: Fri Nov 15 07:29:12 2013 -0800 Fix Undo after Paste commit 8453eca0dd9ffe0cb160fefb12d0be935e64ec85 Author: Jason Shirk <jason@truewheels.net> Date: Fri Nov 15 00:30:50 2013 -0800 Ctrl-R support commit 0b058c2aaee18b33d97dd8d375fac7bbf4d07ce9 Author: Jason Shirk <jason@truewheels.net> Date: Sat Nov 2 08:49:48 2013 -0700 Really exit from test program when typing exit Exit wasn't exiting anymore because the thread that reads keys was blocked. commit e9d5203346f62dacc6315c8e8cb4dc227a6477df Author: Jason Shirk <jason@truewheels.net> Date: Mon Sep 23 09:03:59 2013 -0700 Comment out history search in test program commit 674f90a64c5c627d50f6b018511eb9585640d65a Author: Jason Shirk <jason@truewheels.net> Date: Thu Sep 19 09:18:19 2013 -0700 Add demo mode and ETW trace Added ETW tracing for key presses (a key logger!) so it can be used in a variety of ways, e.g. when doing performance profiling, you can add a message of sorts via key presses if you turn on the provider. The ETW tracing code depends on CLR 4.5, this might force some folks to upgrade. Added PSReadline.EnableDemoMode which uses the ETW trace to display key presses while you type. This is useful for talks and producing screen captures to show the editing experience. commit 222a5efea732d6c34e5263b638d5d3fc04407355 Author: Jason Shirk <jason@truewheels.net> Date: Wed Sep 11 17:55:30 2013 -0700 Support 2 key chords Support for 2 key chords has been added. There is a small breaking change in Set-PSReadlineKeyHandler because the -CtrlX switch is no longer needed. It could have been left in, but it's better to just remove it - not very many people use this module yet. The signature of key handlers was also changed to better support features that have not yet been implemented. The signature change shouldn't affect any existing key handlers because default arguments should cover those cases. commit 3121bcbf6c57b98ead2cc525f8d3d40cbc54c49e Author: Jason Shirk <jason@truewheels.net> Date: Fri May 24 19:56:34 2013 -0700 Add Get-PSReadlineKeyHandler To make it easier to see what keys are bound, you can use the command Get-PSReadlineKeyHandler. The command Set-PSReadlineKeyHandler also adds support for binding Ctrl-X prefixed commands in Emacs mode. commit ed78159f1a27f7a78a26fbad555203dcee94a05c Author: Jason Shirk <jason@truewheels.net> Date: Sun May 12 23:52:15 2013 -0700 Initial checkin.
This commit is contained in:
parent
962aeed560
commit
9c15c6ccd0
6
test/PSReadLine/App.config
Normal file
6
test/PSReadLine/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
35
test/PSReadLine/AssemblyInfo.cs
Normal file
35
test/PSReadLine/AssemblyInfo.cs
Normal file
@ -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")]
|
80
test/PSReadLine/Program.cs
Normal file
80
test/PSReadLine/Program.cs
Normal file
@ -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<string> {"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<EngineIntrinsics>().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});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
74
test/PSReadLine/TestPSReadLine.csproj
Normal file
74
test/PSReadLine/TestPSReadLine.csproj
Normal file
@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{08218B1A-8B85-4722-9E3F-4D6C0BF58AD8}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>TestPSReadLine</RootNamespace>
|
||||
<AssemblyName>TestPSReadLine</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\PSReadLine\packages\Microsoft.PowerShell.3.ReferenceAssemblies.1.0.0\lib\net4\System.Management.Automation.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PSReadLine\PSReadLine.csproj">
|
||||
<Project>{615788cb-1b9a-4b34-97b3-4608686e59ca}</Project>
|
||||
<Name>PSReadLine</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
4
test/PSReadLine/packages.config
Normal file
4
test/PSReadLine/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.PowerShell.3.ReferenceAssemblies" version="1.0.0" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user