From b8e18263b9018bac56e7457c8589562da914ddb5 Mon Sep 17 00:00:00 2001 From: Ivar Fatland Date: Sun, 10 May 2026 02:41:17 +0200 Subject: [PATCH] use ok pattern instead of enum --- raymenu/main.go | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/raymenu/main.go b/raymenu/main.go index a6b44e1..0023366 100644 --- a/raymenu/main.go +++ b/raymenu/main.go @@ -32,37 +32,23 @@ func main() { if err != nil { log.Fatalln(err) } - lines := strings.Split(string(input), "\n") - lines = slices.DeleteFunc(lines, func(l string) bool { + choices := strings.Split(string(input), "\n") + choices = slices.DeleteFunc(choices, func(l string) bool { return l == "" }) - choice, result := raymenu(lines) - switch (result) { - case RayMenuResult_NoChoice: - return - case RayMenuResult_Chosen: - fmt.Println(choice) - return - default: - log.Fatalln("Unhandled RayMenuResult", result) + choice, ok := raymenu(choices) + if ok { + fmt.Println(choice) } } -type RayMenuResult int - -const ( - RayMenuResult_NoChoice RayMenuResult = iota - RayMenuResult_Chosen - Count_RayMenuResult int = iota -) - func isPressedRepeat(key int32) bool { return rl.IsKeyPressed(key) || rl.IsKeyPressedRepeat(key) } -func raymenu(options []string) (choice string, result RayMenuResult) { +func raymenu(options []string) (choice string, ok bool) { state := initialize(len(options)) rg.SetFont(state.Font) rg.SetStyle(rg.DEFAULT, rg.TEXT_SIZE, fontSize) @@ -121,9 +107,9 @@ func raymenu(options []string) (choice string, result RayMenuResult) { if enter { rl.CloseWindow() if cursor < len(matched) { - return options[matched[cursor].Idx], RayMenuResult_Chosen + return options[matched[cursor].Idx], true } - return "", RayMenuResult_NoChoice + return "", false } for i, match := range matched { @@ -153,7 +139,7 @@ func raymenu(options []string) (choice string, result RayMenuResult) { rl.EndDrawing() } - return "", RayMenuResult_NoChoice + return "", false } var yOffset float32 = 0.0