Skip to content
FutureBlitz

    Install

    Import std.term.prompts

    Ask

    std.term.prompts

    function

    Public Function Ask(question: String, default: String = ""): String?

    Asks question on the console, and gives what's typed, or default for nothing.

    std/term/prompts.fb, line 94

    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"))

    std/term/prompts.fb, line 114

    function

    Public Function Ask(terminal: Terminal, question: String, default: String = ""): String?

    Asks question on terminal, and gives what's typed, or default for nothing.

    std/term/prompts.fb, line 120

    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.

    std/term/prompts.fb, line 127

    Report an issue with this page or with FutureBlitz on GitHub.