mirror of
https://github.com/Jguer/yay.git
synced 2024-11-07 09:37:22 +01:00
32 lines
478 B
Go
32 lines
478 B
Go
package text
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/leonelquinteros/gotext"
|
|
)
|
|
|
|
func GetInput(defaultValue string, noConfirm bool) (string, error) {
|
|
Info()
|
|
|
|
if defaultValue != "" || noConfirm {
|
|
fmt.Println(defaultValue)
|
|
return defaultValue, nil
|
|
}
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
buf, overflow, err := reader.ReadLine()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if overflow {
|
|
return "", fmt.Errorf(gotext.Get("input too long"))
|
|
}
|
|
|
|
return string(buf), nil
|
|
}
|