TLang.Prompt
TLang.Prompt provides interactive prompts for CLI scaffolding tools. It is built on top of interactive terminal input and is ideal for generators that ask the user questions before producing output.
use TLang.Prompt
ask — Text Input
Prompt.ask displays a question and returns the user's input as a String.
let name = Prompt.ask("Project name:")
let pkg = Prompt.ask("Base package (e.g. com.example):")
Prompt.askWithDefault provides a fallback shown in brackets if the user presses Enter without typing.
let port = Prompt.askWithDefault("Port:", "8080")
let host = Prompt.askWithDefault("Host:", "localhost")
confirm — Yes/No
Prompt.confirm displays a yes/no question and returns a Bool.
let addTests = Prompt.confirm("Generate test scaffolding?")
if (addTests) {
// generate test files
}
select — Choice from List
Prompt.select displays a numbered menu and returns the chosen string.
let lang = Prompt.select("Target language:", List.of("kotlin", "java", "typescript"))
let db = Prompt.select("Database:", List.of("postgres", "mysql", "sqlite"))
password — Hidden Input
Prompt.password reads a value without echoing characters to the terminal.
let secret = Prompt.password("API key:")
Example — Interactive Scaffolding
use TLang.Prompt
use TLang.File
use TLang.Terminal
use TLang.List
func main(): String {
let project = Prompt.ask("Project name:")
let pkg = Prompt.askWithDefault("Base package:", "com.example")
let lang = Prompt.select("Language:", List.of("kotlin", "java"))
let tests = Prompt.confirm("Include test scaffolding?")
Terminal.println("Generating " + project + " (" + lang + ")...")
// use answers to drive generation
File.write("README.md", "# " + project, true)
if (tests) {
File.createDir("src/test")
}
Terminal.println("Done!")
return "done"
}