https://github.com/karantin2020/promptui
A golang library for building interactive prompts with support for windows and posix terminals
https://github.com/karantin2020/promptui
cli command-line go golang interactive prompt shell unix windows
Last synced: 4 months ago
JSON representation
A golang library for building interactive prompts with support for windows and posix terminals
- Host: GitHub
- URL: https://github.com/karantin2020/promptui
- Owner: karantin2020
- Created: 2019-03-24T23:00:59.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-15T03:09:07.000Z (about 7 years ago)
- Last Synced: 2024-06-19T05:42:34.736Z (about 2 years ago)
- Topics: cli, command-line, go, golang, interactive, prompt, shell, unix, windows
- Language: Go
- Size: 200 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PromptUI
[](github.com/karantin2020/promptui) [](https://goreportcard.com/report/github.com/karantin2020/promptui) [](https://opensource.org/licenses/MIT)
A library for building interactive prompts.

See `examples/main.go`.
```go
package main
import (
"fmt"
"os"
"strings"
"unicode"
bb "github.com/karantin2020/promptui"
)
func main() {
p := bb.Prompt{
BasicPrompt: bb.BasicPrompt{
Label: "test masked",
Validate: func(s string) error {
if s == "err" {
return bb.NewValidationError("input must not be equal to 'err'")
}
if s == "" {
return bb.NewValidationError("input must not be empty string")
}
return nil
},
Default: "hi there",
},
Mask: '*',
// IsVimMode: false,
}
checkError(p.Run())
checkError(bb.Ask("easy prompt", "Yepp"))
checkError(bb.AskMasked("easy masked prompt", "Yepp"))
c := bb.ConfirmPrompt{
BasicPrompt: bb.BasicPrompt{
Label: "test confirm",
Default: "y",
},
ConfirmOpt: "?",
}
checkError(c.Run())
checkError(bb.Confirm("easy confirm", "Y", false))
ml := bb.MultilinePrompt{
BasicPrompt: bb.BasicPrompt{
Label: "test multiline",
Default: "Request",
Formatter: func(s string) string {
var upl = func(sl string) string {
rs := []rune(sl)
if len(rs) > 0 {
rs[0] = unicode.ToUpper(rs[0])
}
return string(rs)
}
out := []string{}
ins := strings.Split(s, "\n")
for i := range ins {
out = append(out, upl(ins[i]))
}
return strings.Join(out, "\n")
},
Validate: func(s string) error {
if s == "Err" {
return bb.NewValidationError("input must not be equal to 'err'")
}
if s == "" {
return bb.NewValidationError("input must not be empty string")
}
return nil
},
},
}
checkError(ml.Run())
checkError(bb.MultiLine("easy multi", "Ready to go"))
s := bb.Select{
Label: "test select",
Items: []string{"one", "two", "three", "1one", "1two", "1three", "2one", "2two", "2three"},
Default: 3,
}
_, res, err := s.Run()
checkError(res, err)
checkError(bb.PromptAfterSelect("prompt after select", []string{"feat", "fix", "doc", "other"}))
}
```