assume prompts are required

vilmibm 2023-10-26 22:32:30 +00:00
parent 90808c1ce0
commit add129826a
1 changed files with 13 additions and 7 deletions

View File

@ -72,15 +72,21 @@ func NewPrompter(tty *tty.TTY, cs colorScheme) *Prompter {
} }
func (p *Prompter) String(prompt string) (string, error) { func (p *Prompter) String(prompt string) (string, error) {
// TODO assumes blank is no bueno
var err error
var answer string
for answer == "" {
fmt.Println("") fmt.Println("")
fmt.Println(p.cs.Prompt(prompt)) fmt.Println(p.cs.Prompt(prompt))
fmt.Println(p.cs.Subtitle("(press enter to submit)")) fmt.Println(p.cs.Subtitle("(press enter to submit)"))
s, err := p.tty.ReadString() answer, err = p.tty.ReadString()
if err != nil { if err != nil {
return "", fmt.Errorf("couldn't collect input: %w", err) return "", fmt.Errorf("couldn't collect input: %w", err)
} }
}
return s, nil return answer, nil
} }
func (p *Prompter) Select(prompt string, opts []string) (int, error) { func (p *Prompter) Select(prompt string, opts []string) (int, error) {