Merge pull request #834 from PowerShell/psreadline2
Host code to enable PSReadLine, and remove checking of .NET Framework
This commit is contained in:
commit
7048b5774c
|
@ -9,6 +9,7 @@ namespace Microsoft.PowerShell.CoreConsoleHost
|
|||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Linq;
|
||||
using PowerShell = System.Management.Automation.PowerShell;
|
||||
|
||||
public static class Program
|
||||
|
@ -562,27 +563,78 @@ OPTIONS
|
|||
|
||||
this.myHost.UI.Write(prompt);
|
||||
|
||||
ConsoleReadLine.ReadResult result = consoleReadLine.Read(false, initialCommand);
|
||||
|
||||
switch(result.state)
|
||||
string input;
|
||||
if (TryInvokeUserDefinedReadLine(out input, true))
|
||||
{
|
||||
case ConsoleReadLine.ReadResult.State.Abort:
|
||||
incompleteLine = false;
|
||||
partialLine = string.Empty;
|
||||
initialCommand = String.Empty;
|
||||
break;
|
||||
case ConsoleReadLine.ReadResult.State.Redraw:
|
||||
initialCommand = result.command;
|
||||
break;
|
||||
case ConsoleReadLine.ReadResult.State.Complete:
|
||||
default:
|
||||
this.Execute(result.command);
|
||||
initialCommand = String.Empty;
|
||||
break;
|
||||
this.Execute(input);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleReadLine.ReadResult result = consoleReadLine.Read(false, initialCommand);
|
||||
|
||||
switch(result.state)
|
||||
{
|
||||
case ConsoleReadLine.ReadResult.State.Abort:
|
||||
incompleteLine = false;
|
||||
partialLine = string.Empty;
|
||||
initialCommand = String.Empty;
|
||||
break;
|
||||
case ConsoleReadLine.ReadResult.State.Redraw:
|
||||
initialCommand = result.command;
|
||||
break;
|
||||
case ConsoleReadLine.ReadResult.State.Complete:
|
||||
default:
|
||||
this.Execute(result.command);
|
||||
initialCommand = String.Empty;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to test if PSReadLine or another alternate ReadLine has been loaded
|
||||
/// </summary>
|
||||
const string CustomReadlineCommand = "PSConsoleHostReadLine";
|
||||
private bool TryInvokeUserDefinedReadLine(out string input, bool useUserDefinedCustomReadLine)
|
||||
{
|
||||
if (useUserDefinedCustomReadLine)
|
||||
{
|
||||
var runspace = this.myHost.Runspace;
|
||||
if (runspace != null
|
||||
&& runspace.ExecutionContext.EngineIntrinsics.InvokeCommand.GetCommands(CustomReadlineCommand, CommandTypes.Function | CommandTypes.Cmdlet, nameIsPattern: false).Any())
|
||||
{
|
||||
try
|
||||
{
|
||||
PowerShell ps;
|
||||
if ((runspace.ExecutionContext.EngineHostInterface.NestedPromptCount > 0) && (Runspace.DefaultRunspace != null))
|
||||
{
|
||||
ps = PowerShell.Create(RunspaceMode.CurrentRunspace);
|
||||
}
|
||||
else
|
||||
{
|
||||
ps = PowerShell.Create();
|
||||
ps.Runspace = runspace;
|
||||
}
|
||||
|
||||
var result = ps.AddCommand(CustomReadlineCommand).Invoke();
|
||||
if (result.Count == 1)
|
||||
{
|
||||
input = PSObject.Base(result[0]) as string;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CommandProcessorBase.CheckForSevereException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
input = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to handle the Debugger DebuggerStop event.
|
||||
/// </summary>
|
||||
|
|
|
@ -2010,7 +2010,8 @@ namespace Microsoft.PowerShell.Commands
|
|||
}
|
||||
|
||||
// Test the required .NET Framework version
|
||||
Version requestedDotNetFrameworkVersion;
|
||||
Version requestedDotNetFrameworkVersion = new Version (0, 0, 0, 0);
|
||||
#if !CORECLR
|
||||
if (
|
||||
!GetScalarFromData(data, moduleManifestPath, "DotNetFrameworkVersion", manifestProcessingFlags,
|
||||
out requestedDotNetFrameworkVersion))
|
||||
|
@ -2044,6 +2045,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
WriteVerbose(cannotDetectNetFrameworkVersionMessage);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// HelpInfo URI
|
||||
string helpInfoUri = null;
|
||||
|
|
Loading…
Reference in a new issue