Merge pull request #602 from PowerShell/pipes

Clean up usage of pipes, as it causes crashes in debugger sub-prompt
This commit is contained in:
Andy Schwartzmeyer
2016-03-01 15:53:15 -08:00
2 changed files with 21 additions and 16 deletions
+8 -5
View File
@@ -285,12 +285,15 @@ OPTIONS
return ">> ";
}
Pipeline pipeline = rs.CreatePipeline();
Collection<PSObject> output;
Command promptCommand = new Command("prompt");
pipeline.Commands.Add(promptCommand);
using (Pipeline pipeline = rs.CreatePipeline())
{
pipeline.Commands.Add(promptCommand);
output = pipeline.Invoke();
}
Collection<PSObject> output = pipeline.Invoke();
foreach (PSObject item in output)
{
returnVal = item.BaseObject.ToString();
@@ -556,7 +559,7 @@ OPTIONS
}
this.myHost.UI.Write(ConsoleColor.White, Console.BackgroundColor, prompt);
string cmd = consoleReadLine.Read(this.myHost.Runspace);
string cmd = consoleReadLine.Read(this.myHost.Runspace, false);
this.Execute(cmd);
}
}
@@ -577,7 +580,7 @@ OPTIONS
while (resumeAction == null)
{
Console.Write("[DBG] PS >> ");
string command = consoleReadLine.Read(this.myHost.Runspace);
string command = consoleReadLine.Read(this.myHost.Runspace, true);
Console.WriteLine();
// Stream output from command processing to console.
+13 -11
View File
@@ -124,7 +124,7 @@ namespace Microsoft.PowerShell.Linux.Host
/// Read a line of text, colorizing while typing.
/// </summary>
/// <returns>The command line read</returns>
public string Read(Runspace runspace)
public string Read(Runspace runspace, bool nested)
{
this.powershell.Runspace = runspace;
this.Initialize();
@@ -162,12 +162,12 @@ namespace Microsoft.PowerShell.Linux.Host
case ConsoleKey.P:
// TODO: incremental search
case ConsoleKey.R:
this.OnUpArrow();
this.OnUpArrow(nested);
break;
case ConsoleKey.N:
// TODO: incremental search
case ConsoleKey.S:
this.OnDownArrow();
this.OnDownArrow(nested);
break;
case ConsoleKey.J:
this.OnEnter();
@@ -228,10 +228,10 @@ namespace Microsoft.PowerShell.Linux.Host
this.OnTab();
break;
case ConsoleKey.UpArrow:
this.OnUpArrow();
this.OnUpArrow(nested);
break;
case ConsoleKey.DownArrow:
this.OnDownArrow();
this.OnDownArrow(nested);
break;
// TODO: case ConsoleKey.LeftWindows: not available in linux
@@ -434,11 +434,11 @@ namespace Microsoft.PowerShell.Linux.Host
/// <summary>
/// The down arrow was pressed to retrieve history
/// </summary>
private void OnDownArrow()
private void OnDownArrow(bool nested)
{
if (this.newHistory)
{
GetHistory();
GetHistory(nested);
OnEscape();
historyIndex = historyResult.Count;
}
@@ -468,11 +468,11 @@ namespace Microsoft.PowerShell.Linux.Host
/// <summary>
/// Changes the history queue when the up arrow is pressed
/// </summary>
private void OnUpArrow()
private void OnUpArrow(bool nested)
{
if (this.newHistory)
{
GetHistory();
GetHistory(nested);
historyIndex = historyResult.Count - 1;
BufferFromString(historyResult[historyIndex].Members["CommandLine"].Value.ToString());
@@ -497,9 +497,11 @@ namespace Microsoft.PowerShell.Linux.Host
/// <summary>
/// Helper function to get command history
/// </summary>
private void GetHistory()
private void GetHistory(bool nested)
{
using (Pipeline pipeline = this.powershell.Runspace.CreatePipeline("Get-History"))
using (Pipeline pipeline = nested
? this.powershell.Runspace.CreateNestedPipeline("Get-History", true)
: this.powershell.Runspace.CreatePipeline("Get-History"))
{
historyResult = pipeline.Invoke();
}