Skip to content
Kavachकवच

User Input: Ask for text

● Beginner2 min

term.prompt gives the line typed, as text, or none when the input has ended.

use std.term

fn main() {
    const name = term.prompt("Your name?") ?? "friend"
    print("Hello, {name}")
}

The program ran and printed:

kavach run text.kav

Your name? Hello, Asha
text.kav: Kavach code, then what running it prints

Typed by the user: Asha. What is typed isn't part of the program's output, so it doesn't show in the box.

The question is printed with a space after it, and the answer is typed on the same line.