From 80f879e33f673143c082df4e04b7d35774b740f7 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 20 Oct 2015 05:56:06 -0700 Subject: [PATCH 1/3] added functionality to get standard default command prompt --- src/powershell-run/main.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/powershell-run/main.cs b/src/powershell-run/main.cs index f0b212285..f530643da 100644 --- a/src/powershell-run/main.cs +++ b/src/powershell-run/main.cs @@ -161,6 +161,25 @@ namespace Microsoft.Samples.PowerShell.Host executeHelper(initialScript,null); } + private string _prompt; + + /// Sets the prompt equal to the output of the prompt function + public string Prompt(Runspace rs) + { + string returnVal = string.Empty; + Pipeline pipeline = rs.CreatePipeline(); + Command promptCommand = new Command("prompt"); + + pipeline.Commands.Add(promptCommand); + + Collection output = pipeline.Invoke(); + foreach (PSObject item in output) + { + returnVal = item.BaseObject.ToString(); + } + + return returnVal; + } /// /// A helper class that builds and executes a pipeline that writes /// to the default output path. Any exceptions that are thrown are @@ -362,7 +381,7 @@ namespace Microsoft.Samples.PowerShell.Host } else { - prompt = "\nPSL> "; + prompt = Prompt(this.myHost.Runspace); } this.myHost.UI.Write(ConsoleColor.White, ConsoleColor.Black, prompt); From 76ed6fa106cc0b9c5d2b6afd961c32c340d9dffc Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 20 Oct 2015 06:00:36 -0700 Subject: [PATCH 2/3] removed dangling variable --- src/powershell-run/main.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/powershell-run/main.cs b/src/powershell-run/main.cs index f530643da..25db596c1 100644 --- a/src/powershell-run/main.cs +++ b/src/powershell-run/main.cs @@ -161,8 +161,6 @@ namespace Microsoft.Samples.PowerShell.Host executeHelper(initialScript,null); } - private string _prompt; - /// Sets the prompt equal to the output of the prompt function public string Prompt(Runspace rs) { From ef1a397dfce6340684fe7d2f923d9ee772b7dbbc Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 20 Oct 2015 06:00:36 -0700 Subject: [PATCH 3/3] removed dangling variable and cleaned up space --- src/powershell-run/main.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/powershell-run/main.cs b/src/powershell-run/main.cs index f530643da..6f12daaa3 100644 --- a/src/powershell-run/main.cs +++ b/src/powershell-run/main.cs @@ -161,13 +161,11 @@ namespace Microsoft.Samples.PowerShell.Host executeHelper(initialScript,null); } - private string _prompt; - /// Sets the prompt equal to the output of the prompt function public string Prompt(Runspace rs) { - string returnVal = string.Empty; - Pipeline pipeline = rs.CreatePipeline(); + string returnVal = string.Empty; + Pipeline pipeline = rs.CreatePipeline(); Command promptCommand = new Command("prompt"); pipeline.Commands.Add(promptCommand);