/// <summary>
            /// Initializes a new instance of the <see cref="OptionsManager"/> class.
            /// </summary>
            /// <param name="prompt"></param>
            /// <param name="options">The options.</param>
            /// <param name="boxes">The boxes.</param>
            public OptionsManager(string prompt, OptionsManagerOptions options, IEnumerable <string> boxes)
            {
                if (boxes == null)
                {
                    throw new ArgumentNullException(nameof(boxes));
                }

                if (boxes.Any())
                {
                    this.boxes =
                        new ObservableCollection <OptionsOption>(boxes.Select(i => new OptionsOption(i)));
                }

                Options = options ?? new OptionsManagerOptions();

                if (!string.IsNullOrEmpty(prompt))
                {
                    Console.WriteLine(prompt);
                }

                if (Options.DisplayHelpText)
                {
                    Console.WriteLine(Options.HelpText);
                }

                StartPosition = Console.CursorTop;
                Draw();
            }
Exemple #2
0
        /// <summary>
        /// Display a options list.
        /// </summary>
        /// <param name="prompt"></param>
        /// <param name="model"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static T GetOptions <T>(string prompt, T model, OptionsManagerOptions options)
        {
            var manager = new OptionsManager(prompt, model, options);

            manager.Show();
            return((T)manager.Model);
        }
Exemple #3
0
        /// <summary>
        /// Display a options list.
        /// </summary>
        /// <param name="prompt"></param>
        /// <param name="options">The options.</param>
        /// <param name="possibleSelections">The possible selections.</param>
        /// <returns></returns>
        public static string[] GetOptions(string prompt, OptionsManagerOptions options,
                                          params string[] possibleSelections)
        {
            var manager = new OptionsManager(prompt, options, possibleSelections);

            manager.Show();
            return(manager.Boxes.Where(i => i.IsSelected).Select(i => i.Title).ToArray());
        }
Exemple #4
0
        /// <summary>
        /// Display a options list and returns a single one.
        /// </summary>
        /// <param name="prompt">The prompt.</param>
        /// <param name="option">The option.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public static string GetOption(string prompt, OptionsManagerOptions option, params string[] options)
        {
            option                     = option ?? new OptionsManagerOptions();
            option.IsRadio             = true;
            option.IsSelectionRequired = true;

            var manager = new OptionsManager(prompt, option, options);

            manager.Show();
            return(manager.Boxes.First(i => i.IsSelected).Title);
        }
Exemple #5
0
        /// <summary>
        /// Display a options list and returns a single one.
        /// </summary>
        /// <param name="prompt">The prompt.</param>
        /// <param name="isUnicode">if set to <c>true</c> [is Unicode].</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public static string GetOption(string prompt, bool isUnicode, params string[] options)
        {
            var option = new OptionsManagerOptions
            {
                IsRadio             = true,
                IsSelectionRequired = true,
                IsUnicode           = isUnicode
            };

            return(GetOption(prompt, option, options));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OptionsManager"/> class.
 /// </summary>
 /// <param name="prompt"></param>
 /// <param name="type">The type.</param>
 /// <param name="options">The options.</param>
 public OptionsManager(string prompt, Type type, OptionsManagerOptions options = null) : this(prompt,
                                                                                              options, null)
 {
     FillBoxes(type);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OptionsManager"/> class.
 /// </summary>
 /// <param name="prompt"></param>
 /// <param name="model">The model.</param>
 /// <param name="options">The options.</param>
 public OptionsManager(string prompt, object model, OptionsManagerOptions options = null) : this(prompt,
                                                                                                 options, null)
 {
     Model = model;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OptionsManager"/> class.
 /// </summary>
 /// <param name="prompt"></param>
 /// <param name="options">The options.</param>
 /// <param name="boxes">The boxes.</param>
 public OptionsManager(string prompt, OptionsManagerOptions options, params string[] boxes) : this(prompt,
                                                                                                   options,
                                                                                                   boxes?.ToList())
 {
 }