示例#1
0
        internal RawListBuilder(string message, IEnumerable <TResult> choices, IConsole console) : base(console)
        {
            Choices = choices.ToList();
            Console = console;

            this.RenderQuestion(message, this, this, console);
            this.Parse(value =>
            {
                return(Choices[value.To <int>() - 1]);
            });

            this.RenderRawChoices(Choices, this, Console);

            InputValidators.Add(value => { return(string.IsNullOrEmpty(value) == false || Default.HasDefault); }, "Empty line");
            InputValidators.Add(value => { return(value.ToN <int>().HasValue); }, value => { return($"Cannot parse {value} to {typeof(TResult)}"); });
            InputValidators.Add(
                value =>
            {
                var index = value.To <int>();
                return(index > 0 && index <= Choices.Count);
            },
                value =>
            {
                return($"Chosen number must be between 1 and {Choices.Count}");
            });

            this.Input(Console, value => { return(char.IsNumber(value)); });
        }
        internal InputStringBuilder(string message, IConsole console) : base(console)
        {
            this.RenderQuestion(message, this, this, Console);
            this.Parse(value => { return(value); });
            this.Input(Console, ConsoleKey.Escape);

            InputValidators.Add(value => { return(string.IsNullOrEmpty(value) == false || Default.HasDefault); }, "Empty line");
        }
        internal InputStructBuilder(string message, IConsole console) : base(console)
        {
            this.RenderQuestion(message, this, this, console);
            this.Parse(value => { return(value.To <TResult>()); });
            this.Input(Console, ConsoleKey.Escape);

            InputValidators.Add(value => { return(string.IsNullOrEmpty(value) == false || Default.HasDefault); }, "Empty line");
            InputValidators.Add(value => { return(value.ToN <TResult>().HasValue); }, value => { return($"Cannot parse {value} to {typeof(TResult)}"); });
        }
        internal PasswordBuilder(string message, IConsole console) : base(console)
        {
            this.Confirm();
            this.RenderQuestion(message, this, this, console);
            this.Parse(value => { return(value); });
            this.PasswordInput(Console);

            InputValidators.Add(value => { return(string.IsNullOrEmpty(value) == false || Default.HasDefault); }, "Empty line");
        }
示例#5
0
        internal ExtendedBuilder(string message, IConsole console, params ConsoleKey[] @params) : base(console)
        {
            this.RenderQuestion(message, this, this, Console);

            this.Parse(value => { return(value); });

            InputValidators.Add(
                value =>
            {
                return(@params.Any(p => p == value));
            },
                value =>
            {
                string keys = " Press : ";
                foreach (var key in @params)
                {
                    keys += $"[{(char)key}] ";
                }

                return(keys);
            });
        }
示例#6
0
        internal PagedRawListBuilder(RawListBuilder <TResult> listBuilder, int pageSize) : base(listBuilder.Console)
        {
            Choices = listBuilder.Choices;
            Console = listBuilder.Console;

            Confirm          = listBuilder.Confirm;
            Convert          = listBuilder.Convert;
            Default          = listBuilder.Default;
            ResultValidators = listBuilder.ResultValidators;
            RenderQuestion   = listBuilder.RenderQuestion;

            this.RenderRawChoices(this, this, Console);
            DisplayError = listBuilder.DisplayError;

            this.Input(Console, ConsoleKey.LeftArrow, ConsoleKey.RightArrow, ConsoleKey.Enter);
            Input.AllowTypeFn = value => { return(char.IsNumber(value)); };

            this.Parse(value =>
            {
                return(Paging.CurrentPage[value.To <int>() - 1]);
            });

            InputValidators.Add(value => { return(string.IsNullOrEmpty(value) == false || Default.HasDefault); }, "Empty line");
            InputValidators.Add(value => { return(value.ToN <int>().HasValue); }, value => { return($"Cannot parse {value} to {typeof(TResult)}"); });
            InputValidators.Add(
                value =>
            {
                var index = value.To <int>();
                return(index > 0 && index <= Paging.CurrentPage.Count);
            },
                value =>
            {
                return($"Chosen number must be between 1 and {Paging.CurrentPage.Count} ");
            });

            OnKey = listBuilder.OnKey;
            this.Paging(listBuilder.Choices, pageSize);
        }