TheMathemagicians/sevenkeys/cli/response.go

39 lines
632 B
Go
Raw Normal View History

2024-06-10 15:34:16 +00:00
package cli
import (
"bufio"
2024-06-10 15:34:16 +00:00
"fmt"
"os"
2024-06-11 16:02:02 +00:00
"sevenkeys/logic"
2024-06-10 15:34:16 +00:00
"strings"
)
func GetStringResponse(prompt string) string {
fmt.Print(prompt + " ")
var response string
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
response = scanner.Text()
2024-06-10 15:34:16 +00:00
return response
}
func GetYesNoResponse(prompt string) bool {
response := GetStringResponse(prompt)
return strings.ToUpper(response) == "Y"
}
2024-06-11 16:02:02 +00:00
func GetTriadicResponse(prompt string) logic.Triadic {
response := GetStringResponse(prompt)
switch strings.ToUpper(response) {
case "Y":
return logic.True
case "N":
return logic.False
default:
return logic.Either
}
}