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..7a2df6a234 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,9 +497,11 @@ 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")) + using (Pipeline pipeline = nested + ? this.powershell.Runspace.CreateNestedPipeline("Get-History", true) + : this.powershell.Runspace.CreatePipeline("Get-History")) { historyResult = pipeline.Invoke(); }