示例#1
0
        internal InputQuestion(string name, FunctionOrColorString message)
            : base(name, message)
        {
            _askerFn = (q, ans) =>
            {
                bool Validator(string str)
                {
                    var question = (InputQuestion <TValue>)q;

                    if (string.IsNullOrEmpty(str))
                    {
                        str = question.DefaultValue.Resolve(ans);
                    }
                    bool valid = (question.RawValueValidator is null) || question.RawValueValidator(str, ans).Valid;
                    var  teq   = (TextEntryQuestion <TValue>)q;

                    if (valid && teq.IsRequired)
                    {
                        return(teq.AllowWhitespaceOnly
                            ? !string.IsNullOrEmpty(str)
                            : !string.IsNullOrWhiteSpace(str));
                    }

                    return(valid);
                }

                return(ConsoleEx.Prompt(new ColorString(q.Message.Resolve(ans),
                                                        Prompter.Style.Question.ForeColor, Prompter.Style.Question.BackColor).ToString(),
                                        Validator));
            };
        }
示例#2
0
 public MultiLineQuestion(string name, FunctionOrColorString message)
     : base(name, message)
 {
     _askerFn = (q, ans) =>
     {
         ConsoleEx.PrintLine(new ColorString(q.Message.Resolve(ans),
                                             Prompter.Style.Question.ForeColor, Prompter.Style.Question.BackColor));
         return(string.Empty);
     };
 }
示例#3
0
 internal PasswordQuestion(string name, FunctionOrColorString message)
     : base(name, message)
 {
     _askerFn = (q, ans) =>
     {
         var pq = (PasswordQuestion <TValue>)q;
         return(ConsoleEx.ReadSecret(new ColorString(q.Message.Resolve(ans),
                                                     Prompter.Style.Question.ForeColor, Prompter.Style.Question.BackColor),
                                     hideCursor: pq._hideCursor, hideMask: pq._hideMask));
     };
 }
示例#4
0
        public CheckboxQuestion(string name, FunctionOrColorString message, IEnumerable <string> choices)
            : base(name, message)
        {
            if (choices is null)
            {
                throw new ArgumentNullException(nameof(choices));
            }
            _choices = choices.ToList();

            _askerFn = (q, ans) =>
            {
                var cq = (CheckboxQuestion)q;
                ConsoleEx.PrintLine(new ColorString(q.Message.Resolve(ans),
                                                    Prompter.Style.Question.ForeColor, Prompter.Style.Question.BackColor));
                return(ConsoleEx.SelectMultiple(cq._choices));
            };
        }
示例#5
0
        internal ConfirmQuestion(string name, FunctionOrColorString message, bool @default)
            : base(name, message)
        {
            _askerFn = (q, ans) =>
            {
                ConsoleEx.Print(new ColorString(q.Message.Resolve(ans),
                                                Prompter.Style.Question.ForeColor, Prompter.Style.Question.BackColor));

                var cq = (ConfirmQuestion)q;
                ConsoleEx.Print(new ColorString($" ({(cq._default ? 'Y' : 'y')}/{(cq._default ? 'n' : 'N')}) ",
                                                Prompter.Style.Question.ForeColor, Prompter.Style.Question.BackColor));

                ConsoleKey keyPressed = ConsoleEx.WaitForKeys(ConsoleKey.Y, ConsoleKey.N, ConsoleKey.Enter);
                bool       result     = keyPressed == ConsoleKey.Enter ? cq._default : (keyPressed == ConsoleKey.Y);

                ConsoleEx.PrintLine(result ? "Y" : "N");

                return(result);
            };
            _default = @default;
        }
 protected TextEntryQuestion(string name, FunctionOrColorString message)
     : base(name, message)
 {
 }