Import std.term.prompts
Ask
function
Public Function Ask(question: String, default: String = ""): String?
Asks question on the console, and gives what's typed, or default for nothing.
function
Public Function Ask(question: String, validate: Func(String): String?, default: String = ""): String?
Asks question on the console, and gives what's typed, or default for nothing, once
validate gives Null for it; while it doesn't, what it gives says what's wrong, and the
question goes on.
Examples
Local terminal = FakeTerminal(interactive: False)
terminal.Feed("\n42\n")
// What validate gives says what's wrong with an answer, or Null for one that's right.
Local number = Function(text: String): String? => Int.Parse(text) == Null ? "a number" : Null
Local age = Ask(terminal, "Age?", number)
Expect(age == "42")
Expect(terminal.Output.Contains("a number"))function
Public Function Ask(terminal: Terminal, question: String, default: String = ""): String?
Asks question on terminal, and gives what's typed, or default for nothing.
function
Public Function Ask(terminal: Terminal, question: String, validate: Func(String): String?, default: String = ""): String?
Asks question on terminal, and gives what's typed, or default for nothing, once validate
gives Null for it; while it doesn't, what it gives says what's wrong, and the question goes
on.
Report an issue with this page or with FutureBlitz on GitHub.