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.Text;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Linq;
|
||||||
using PowerShell = System.Management.Automation.PowerShell;
|
using PowerShell = System.Management.Automation.PowerShell;
|
||||||
|
|
||||||
public static class Program
|
public static class Program
|
||||||
|
@ -562,27 +563,78 @@ OPTIONS
|
||||||
|
|
||||||
this.myHost.UI.Write(prompt);
|
this.myHost.UI.Write(prompt);
|
||||||
|
|
||||||
ConsoleReadLine.ReadResult result = consoleReadLine.Read(false, initialCommand);
|
string input;
|
||||||
|
if (TryInvokeUserDefinedReadLine(out input, true))
|
||||||
switch(result.state)
|
|
||||||
{
|
{
|
||||||
case ConsoleReadLine.ReadResult.State.Abort:
|
this.Execute(input);
|
||||||
incompleteLine = false;
|
}
|
||||||
partialLine = string.Empty;
|
else
|
||||||
initialCommand = String.Empty;
|
{
|
||||||
break;
|
ConsoleReadLine.ReadResult result = consoleReadLine.Read(false, initialCommand);
|
||||||
case ConsoleReadLine.ReadResult.State.Redraw:
|
|
||||||
initialCommand = result.command;
|
switch(result.state)
|
||||||
break;
|
{
|
||||||
case ConsoleReadLine.ReadResult.State.Complete:
|
case ConsoleReadLine.ReadResult.State.Abort:
|
||||||
default:
|
incompleteLine = false;
|
||||||
this.Execute(result.command);
|
partialLine = string.Empty;
|
||||||
initialCommand = String.Empty;
|
initialCommand = String.Empty;
|
||||||
break;
|
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>
|
/// <summary>
|
||||||
/// Method to handle the Debugger DebuggerStop event.
|
/// Method to handle the Debugger DebuggerStop event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -2010,7 +2010,8 @@ namespace Microsoft.PowerShell.Commands
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test the required .NET Framework version
|
// Test the required .NET Framework version
|
||||||
Version requestedDotNetFrameworkVersion;
|
Version requestedDotNetFrameworkVersion = new Version (0, 0, 0, 0);
|
||||||
|
#if !CORECLR
|
||||||
if (
|
if (
|
||||||
!GetScalarFromData(data, moduleManifestPath, "DotNetFrameworkVersion", manifestProcessingFlags,
|
!GetScalarFromData(data, moduleManifestPath, "DotNetFrameworkVersion", manifestProcessingFlags,
|
||||||
out requestedDotNetFrameworkVersion))
|
out requestedDotNetFrameworkVersion))
|
||||||
|
@ -2044,6 +2045,7 @@ namespace Microsoft.PowerShell.Commands
|
||||||
WriteVerbose(cannotDetectNetFrameworkVersionMessage);
|
WriteVerbose(cannotDetectNetFrameworkVersionMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// HelpInfo URI
|
// HelpInfo URI
|
||||||
string helpInfoUri = null;
|
string helpInfoUri = null;
|
||||||
|
|
Loading…
Reference in a new issue