public static Prompter Checkbox(this Prompter prompter, string name, FunctionOrColorString message, IEnumerable <string> choices, Action <CheckboxQuestion> setupQuestion = null) { var question = new CheckboxQuestion(name, message, choices); setupQuestion?.Invoke(question); prompter.Add(question); return(prompter); }
public static Prompter Text(this Prompter prompter, FunctionOrColorString text, Action <StaticText> setupStaticText = null) { var staticText = new StaticText(text); setupStaticText?.Invoke(staticText); prompter.Add(staticText); return(prompter); }
public static Prompter Confirm(this Prompter prompter, string name, FunctionOrColorString message, bool @default = false, Action <ConfirmQuestion> setupQuestion = null) { var question = new ConfirmQuestion(name, message, @default); setupQuestion?.Invoke(question); prompter.Add(question); return(prompter); }
public static Prompter Password(this Prompter prompter, string name, FunctionOrColorString message, Action <PasswordQuestion> setupQuestion = null) { var question = new PasswordQuestion(name, message); setupQuestion?.Invoke(question); prompter.Add(question); return(prompter); }
/// <summary> /// Initializes a new instance of the <see cref="Question"/> class. /// </summary> /// <param name="name">The name of the variable to store the answer.</param> /// <param name="message">The message to display to the user.</param> protected Question(string name, FunctionOrColorString message) : base(message) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Specify a name for the question.", nameof(name)); } Name = name; }
internal StaticText(FunctionOrColorString message) : base(message) { _askerFn = (q, ans) => { ColorString staticText = q.Message.Resolve(ans); if (staticText != null) { ConsoleEx.PrintLine(staticText); } return(null); }; }
//TODO: Enforce a converter parameter here public static Prompter List <TValue>(this Prompter prompter, string name, FunctionOrColorString message, IEnumerable <string> choices, Func <int, TValue> converter, Action <ListQuestion <TValue> > setupQuestion = null) { if (converter is null) { throw new ArgumentNullException(nameof(converter)); } var question = new ListQuestion <TValue>(name, message, choices); question.Transform(converter); setupQuestion?.Invoke(question); prompter.Add(question); return(prompter); }
/// <summary> /// Initializes a new instance of the <see cref="PromptItem"/> class. /// </summary> /// <param name="message">The <paramref name="message"/> to display to the user.</param> protected PromptItem(FunctionOrColorString message) { Message = message; }