/// <summary> /// Writes a newline character (carriage return) /// to the output display of the host. /// </summary> public override void WriteLine() { PowerShellConsolePrinter.RemoveLines(new List <string>() { ConsolePromptDefinator }); PowerShellConsolePrinter.WriteDelayedMessage("\n"); }
/// <summary> /// Writes a line of characters to the output display of the host /// and appends a newline character(carriage return). /// </summary> /// <param name="value">The line to be written.</param> public override void WriteLine(string value) { if (!m_SkipRemoveLines) { PowerShellConsolePrinter.RemoveLines(new List <string>() { ConsolePromptDefinator }); } PowerShellConsolePrinter.WriteDelayedMessage(value + "\n"); }
/// <summary> /// Writes a line of characters to the output display of the host /// with foreground and background colors and appends a newline (carriage return). /// </summary> /// <param name="foregroundColor">The forground color of the display. </param> /// <param name="backgroundColor">The background color of the display. </param> /// <param name="value">The line to be written.</param> public override void WriteLine( ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value) { ConsoleColor oldFg = ColorExtension.GetConsoleColor(PowerShellConsolePrinter.TextColor); ConsoleColor oldBg = ColorExtension.GetConsoleColor(PowerShellConsolePrinter.BackgroundColor); PowerShellConsolePrinter.RemoveLines(new List <string>() { ConsolePromptDefinator }); PowerShellConsolePrinter.TextColor = ColorExtension.GetColor(foregroundColor); PowerShellConsolePrinter.BackgroundColor = ColorExtension.GetColor(backgroundColor); PowerShellConsolePrinter.WriteDelayedMessage(value + "\n"); PowerShellConsolePrinter.TextColor = ColorExtension.GetColor(oldFg); PowerShellConsolePrinter.BackgroundColor = ColorExtension.GetColor(oldBg); }
/// <summary> /// Prompts the user for input. /// </summary> /// <param name="caption">Text that preceeds the prompt (a title).</param> /// <param name="message">Text of the prompt.</param> /// <param name="descriptions">A collection of FieldDescription objects /// that contains the user input.</param> /// <returns>A dictionary object that contains the results of the user prompts.</returns> public override Dictionary <string, PSObject> Prompt( string caption, string message, Collection <FieldDescription> descriptions) { this.Write(ConsoleColor.Blue, ConsoleColor.Black, caption + "\n" + message + " "); Dictionary <string, PSObject> results = new Dictionary <string, PSObject>(); foreach (FieldDescription fd in descriptions) { string[] label = GetHotkeyAndLabel(fd.Label); SecureString secureStr = new SecureString(); this.WriteLine(label[1]); string userData = null; if (String.IsNullOrEmpty(caption) && String.IsNullOrEmpty(message)) { userData = null; this.Write(ConsoleColor.Blue, ConsoleColor.Black, fd.Name + ":>"); //PowerShellConsolePrinter.WriteDelayedMessage(ConsolePromptDefinator); while (userData == null) { System.Threading.Thread.Sleep(100); userData = PowerShellConsolePrinter.ReadLine(":>"); if (String.IsNullOrEmpty(userData)) { userData = null; } } if (!String.IsNullOrEmpty(userData)) { userData = userData.Trim(Environment.NewLine.ToCharArray()); } PowerShellConsolePrinter.RemoveLines(new List <string>() { ConsolePromptDefinator }); if (fd.ParameterTypeName == "SecureString" && !String.IsNullOrEmpty(userData)) { foreach (char c in userData.ToCharArray()) { secureStr.AppendChar(c); } results[fd.Name] = PSObject.AsPSObject(secureStr); } } if (userData == null) { return(null); } if (fd.ParameterTypeName != "SecureString") { results[fd.Name] = PSObject.AsPSObject(userData); } } return(results); }