From ab3203916b5e51f4140a629c573990665d458f9d Mon Sep 17 00:00:00 2001 From: George Fleming Date: Mon, 29 Feb 2016 09:51:26 -0800 Subject: [PATCH 1/2] Clean up usage of pipes, as it causes crashes in debugger sub-prompt --- src/Microsoft.PowerShell.Linux.Host/main.cs | 13 ++++--- .../readline.cs | 35 ++++++++++++------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.PowerShell.Linux.Host/main.cs b/src/Microsoft.PowerShell.Linux.Host/main.cs index fde1f21928..be52ea0715 100644 --- a/src/Microsoft.PowerShell.Linux.Host/main.cs +++ b/src/Microsoft.PowerShell.Linux.Host/main.cs @@ -285,12 +285,15 @@ OPTIONS return ">> "; } - Pipeline pipeline = rs.CreatePipeline(); + Collection output; Command promptCommand = new Command("prompt"); - pipeline.Commands.Add(promptCommand); + using (Pipeline pipeline = rs.CreatePipeline()) + { + pipeline.Commands.Add(promptCommand); + output = pipeline.Invoke(); + } - Collection 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. diff --git a/src/Microsoft.PowerShell.Linux.Host/readline.cs b/src/Microsoft.PowerShell.Linux.Host/readline.cs index aff4f36abe..d69ebd457c 100644 --- a/src/Microsoft.PowerShell.Linux.Host/readline.cs +++ b/src/Microsoft.PowerShell.Linux.Host/readline.cs @@ -124,7 +124,7 @@ namespace Microsoft.PowerShell.Linux.Host /// Read a line of text, colorizing while typing. /// /// The command line read - 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 /// /// The down arrow was pressed to retrieve history /// - 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 /// /// Changes the history queue when the up arrow is pressed /// - 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,12 +497,23 @@ namespace Microsoft.PowerShell.Linux.Host /// /// Helper function to get command history /// - private void GetHistory() + private void GetHistory(bool nested) { - using (Pipeline pipeline = this.powershell.Runspace.CreatePipeline("Get-History")) + if (nested) { - historyResult = pipeline.Invoke(); + using (Pipeline pipelineNested = this.powershell.Runspace.CreateNestedPipeline("Get-History", true)) + { + historyResult = pipelineNested.Invoke(); + } } + else + { + using (Pipeline pipeline = this.powershell.Runspace.CreatePipeline("Get-History")) + { + historyResult = pipeline.Invoke(); + } + } + } /// From 95cea5155bb118ab5b4898fd453abe0e3c104426 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Tue, 1 Mar 2016 15:33:29 -0800 Subject: [PATCH 2/2] cleanup per andschwa comment --- src/Microsoft.PowerShell.Linux.Host/readline.cs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.PowerShell.Linux.Host/readline.cs b/src/Microsoft.PowerShell.Linux.Host/readline.cs index d69ebd457c..7a2df6a234 100644 --- a/src/Microsoft.PowerShell.Linux.Host/readline.cs +++ b/src/Microsoft.PowerShell.Linux.Host/readline.cs @@ -499,21 +499,12 @@ namespace Microsoft.PowerShell.Linux.Host /// private void GetHistory(bool nested) { - if (nested) + using (Pipeline pipeline = nested + ? this.powershell.Runspace.CreateNestedPipeline("Get-History", true) + : this.powershell.Runspace.CreatePipeline("Get-History")) { - using (Pipeline pipelineNested = this.powershell.Runspace.CreateNestedPipeline("Get-History", true)) - { - historyResult = pipelineNested.Invoke(); - } + historyResult = pipeline.Invoke(); } - else - { - using (Pipeline pipeline = this.powershell.Runspace.CreatePipeline("Get-History")) - { - historyResult = pipeline.Invoke(); - } - } - } ///