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)); }; }
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); }; }
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)); }; }
internal StaticText(FunctionOrColorString message) : base(message) { _askerFn = (q, ans) => { ColorString staticText = q.Message.Resolve(ans); if (staticText != null) { ConsoleEx.PrintLine(staticText); } return(null); }; }
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)); }; }
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; }