public override int PromptForChoice()

in dotNet/PsEdge/PsHostUI.cs [322:395]


        public override int PromptForChoice(string caption, string message, Collection<ChoiceDescription> choices, int defaultChoice)
        {
            var promptInput = new EdgePromptInput()
            {
                Caption = caption,
                Message = message,
                FieldDescriptions = new List<EdgeFieldDescription>()
            };

            // Convert the choice collection into something that is
            // easier to work with. See the BuildHotkeysAndPlainLabels 
            // method for details.
            string[,] promptData = BuildHotkeysAndPlainLabels(choices);

            // Format the overall choice prompt string to display.
            StringBuilder sb = new StringBuilder();
            for (int element = 0; element < choices.Count; element++)
            {
                sb.Append(String.Format(
                                        CultureInfo.CurrentCulture,
                                        "[{0}] {1}  ",
                                        promptData[0, element],
                                        promptData[1, element]));
            }

            sb.Append(String.Format(
                                    CultureInfo.CurrentCulture,
                                    "(Default is [\"{0}\"])",
                                    promptData[0, defaultChoice]));

            promptInput.FieldDescriptions.Add(new EdgeFieldDescription()
            {
                Name = "Choice",
                IsArray = false,
                IsSecureString = false,
                Type = sb.ToString()
            });

            // Read prompts until a match is made, the default is
            // chosen, or the loop is interrupted with ctrl-C.
            while (true)
            {
                var output = this.promptHandler(promptInput).Result;
                var outputDict = (IDictionary<string, object>) output;
                var choice = string.Empty;

                foreach (var entry in (object[]) outputDict["Results"])
                {
                    var entryDict = (IDictionary<string, object>) entry;

                    if (entryDict["Name"].Equals("Choice"))
                    {
                        choice = (string) entryDict["Value"];
                    }
                }

                // If the choice string was empty, use the default selection.
                if (choice.Length == 0)
                {
                    return defaultChoice;
                }

                // See if the selection matched and return the
                // corresponding index if it did.
                for (int i = 0; i < choices.Count; i++)
                {
                    if (promptData[0, i].Equals(choice, StringComparison.CurrentCultureIgnoreCase) ||
                        promptData[1, i].Equals(choice, StringComparison.CurrentCultureIgnoreCase))
                    {
                        return i;
                    }
                }
            }
        }