Example #1
0
        /// <summary>
        /// Shows the menu items and return the user's choice
        /// </summary>
        /// <returns>string with the user selected option</returns>
        public string Show()
        {
            var tokenizer = new AcceleratorCharTokenizer();
            int i         = 0;

            Keys.Clear();
            foreach (var item in Items)
            {
                if (Options.NumerationStyle == MenuNumeration.AcceleratorKey)
                {
                    Console.WriteLine(tokenizer.Parse(item));
                    Keys.Add(GetAcceleratorChar(item).ToString());
                }
                else
                {
                    (string key, IEnumerable <ColorToken> tokens) = ComposeMenuItem(i, item);
                    Console.WriteLine(tokens);
                    Keys.Add(key);
                }
                i++;
            }
            Console.Ask(BuildMessage());
            string value = Console.ReadLine <string>(x => IsDefaultValue(x) || Keys.Contains(x));

            return(IsDefaultValue(value) ? Options.DefaultItem : value);
        }
Example #2
0
        /// <summary>
        /// Prompts the question to the user and returns the user's choice
        /// </summary>
        /// <remarks>
        /// If the user press ENTER the default choice value is returned
        /// </remarks>
        /// <returns>String with the user selected option</returns>
        public string Show()
        {
            string value = Console
                           .Ask()
                           .Write(Options.Text)
                           .Write(FormatChoices())
                           .ReadLine <string>(x => x == String.Empty || Options.Choices.Contains(x, StringComparer.CurrentCultureIgnoreCase));

            return(value == string.Empty ? Options.Choices[Options.DefaultChoiceIndex] : value);
        }