2021-10-11 22:22:03 +02:00
|
|
|
package text
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
2023-02-17 20:01:26 +01:00
|
|
|
"io"
|
2021-10-11 22:22:03 +02:00
|
|
|
)
|
|
|
|
|
2023-02-17 20:01:26 +01: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
|
|
|
|
}
|
|
|
|
|
2023-02-17 20:01:26 +01:00
|
|
|
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 {
|
2021-10-16 09:48:13 +02:00
|
|
|
return "", ErrInputOverflow{}
|
2021-10-11 22:22:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return string(buf), nil
|
|
|
|
}
|
2023-02-17 20:01:26 +01:00
|
|
|
|
|
|
|
func GetInput(r io.Reader, defaultValue string, noConfirm bool) (string, error) {
|
2023-02-25 18:44:24 +01:00
|
|
|
return GlobalLogger.GetInput(defaultValue, noConfirm)
|
2023-02-17 20:01:26 +01:00
|
|
|
}
|