yay/pkg/text/input.go

34 lines
565 B
Go
Raw Normal View History

2021-10-11 22:22:03 +02:00
package text
import (
"bufio"
"fmt"
"io"
2021-10-11 22:22:03 +02:00
)
func (l *Logger) GetInput(defaultValue string, noConfirm bool) (string, error) {
2021-10-11 22:22:03 +02:00
Info()
if defaultValue != "" || noConfirm {
fmt.Println(defaultValue)
return defaultValue, nil
}
reader := bufio.NewReader(l.r)
2021-10-11 22:22:03 +02:00
buf, overflow, err := reader.ReadLine()
if err != nil {
return "", err
}
if overflow {
return "", ErrInputOverflow{}
2021-10-11 22:22:03 +02:00
}
return string(buf), nil
}
func GetInput(r io.Reader, defaultValue string, noConfirm bool) (string, error) {
return GlobalLogger.GetInput(defaultValue, noConfirm)
}