一个用于构建交互式且无障碍提示的Go语言库,全面支持Windows和POSIX终端。
一个用于在支持 ANSI 转义序列的终端上构建交互式且无障碍提示的库。
⚠️ 该项目已不再维护。如需替代方案,请查看:https://github.com/charmbracelet/bubbletea ⚠️
大家好!我终于接受了现实,无法再投入足够的时间来维持这个库的活力。 这个项目超出了我最疯狂的预期,是一段非常棒的经历。如果有人愿意接手维护工作, 请与我联系
…示例可以在 examples/ 目录中找到。运行它们
以查看基本行为:
go run examples/simple.go
go run examples/validation.go执行提示词并从用户那里收集信息主要有两种方式:Ask 和 AskOne。主要区别在于你是想收集单条信息,还是有一系列问题需要询问,并将答案收集到一个结构体中。对于大多数基本用例,Ask 就足够了。然而,对于具有复杂分支逻辑的调查问卷,我们建议你将问题拆分成多次调用这两个函数,以满足你的需求。
大多数提示通过你实例化的结构体字段进行细粒度配置。也可以通过向 Ask 或 AskOne 传递 AskOpts 来更改 survey 的默认行为。本文档中的示例将交替使用这两种方式:
prompt := &Select{
Message: "Choose a color:",
Options: []string{"red", "blue", "green"},
// can pass a validator directly
Validate: survey.Required,
}
// or define a default for the single call to `AskOne`
// the answer will get written to the color variable
survey.AskOne(prompt, &color, survey.WithValidator(survey.Required))
// or define a default for every entry in a list of questions
// the answer will get copied into the matching field of the struct as shown above
survey.Ask(questions, &answers, survey.WithValidator(survey.Required))name := ""
prompt := &survey.Input{
Message: "ping",
}
survey.暂无开放 Issues,或尚未同步最近议题。