2024-11-22 15:29:25 +00:00
|
|
|
package prompt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func StringPrompt(label string) string {
|
2024-12-16 18:22:58 +00:00
|
|
|
var str string
|
|
|
|
|
2024-11-22 15:29:25 +00:00
|
|
|
r := bufio.NewReader(os.Stdin)
|
2024-12-16 18:22:58 +00:00
|
|
|
|
2024-11-22 15:29:25 +00:00
|
|
|
for {
|
|
|
|
fmt.Fprint(os.Stderr, label+" ")
|
2024-12-16 18:22:58 +00:00
|
|
|
|
|
|
|
str, _ = r.ReadString('\n')
|
|
|
|
if str != "" {
|
2024-11-22 15:29:25 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2024-12-16 18:22:58 +00:00
|
|
|
|
|
|
|
return strings.TrimSpace(str)
|
2024-11-22 15:29:25 +00:00
|
|
|
}
|