|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "strings" |
| 7 | + |
| 8 | + "github.com/yarlson/tap" |
| 9 | +) |
| 10 | + |
| 11 | +func main() { |
| 12 | + fmt.Println("Styled Select Example") |
| 13 | + fmt.Println("Use arrow keys (or hjkl) to navigate, Enter to select, Ctrl+C to cancel") |
| 14 | + fmt.Println() |
| 15 | + |
| 16 | + // Example 1: Color selection with hints |
| 17 | + colors := []tap.SelectOption[string]{ |
| 18 | + {Value: "red", Label: "Red", Hint: "The color of passion and energy"}, |
| 19 | + {Value: "blue", Label: "Blue", Hint: "The color of calm and trust"}, |
| 20 | + {Value: "green", Label: "Green", Hint: "The color of nature and growth"}, |
| 21 | + {Value: "yellow", Label: "Yellow", Hint: "The color of happiness and optimism"}, |
| 22 | + {Value: "purple", Label: "Purple", Hint: "The color of creativity and mystery"}, |
| 23 | + } |
| 24 | + |
| 25 | + result := tap.Select[string](context.Background(), tap.SelectOptions[string]{ |
| 26 | + Message: "What's your favorite color?", |
| 27 | + Options: colors, |
| 28 | + }) |
| 29 | + fmt.Printf("\nYou selected: %s\n", result) |
| 30 | + |
| 31 | + // Example 2: Framework selection with initial value |
| 32 | + fmt.Println("\n" + strings.Repeat("─", 50)) |
| 33 | + fmt.Println("Framework Selection Example:") |
| 34 | + |
| 35 | + frameworks := []tap.SelectOption[string]{ |
| 36 | + {Value: "react", Label: "React", Hint: "A JavaScript library for building user interfaces"}, |
| 37 | + {Value: "vue", Label: "Vue.js", Hint: "The Progressive JavaScript Framework"}, |
| 38 | + {Value: "angular", Label: "Angular", Hint: "Platform for building mobile and desktop web apps"}, |
| 39 | + {Value: "svelte", Label: "Svelte", Hint: "Cybernetically enhanced web apps"}, |
| 40 | + {Value: "solid", Label: "SolidJS", Hint: "Simple and performant reactivity"}, |
| 41 | + } |
| 42 | + |
| 43 | + initialValue := "react" |
| 44 | + result2 := tap.Select[string](context.Background(), tap.SelectOptions[string]{ |
| 45 | + Message: "Which frontend framework do you prefer?", |
| 46 | + Options: frameworks, |
| 47 | + InitialValue: &initialValue, |
| 48 | + }) |
| 49 | + fmt.Printf("\nYou chose: %s\n", result2) |
| 50 | + |
| 51 | + // Example 3: Priority levels (numeric values) |
| 52 | + fmt.Println("\n" + strings.Repeat("─", 50)) |
| 53 | + fmt.Println("Priority Selection Example:") |
| 54 | + |
| 55 | + priorities := []tap.SelectOption[int]{ |
| 56 | + {Value: 1, Label: "Low Priority", Hint: "Can be done when time permits"}, |
| 57 | + {Value: 2, Label: "Medium Priority", Hint: "Should be completed this week"}, |
| 58 | + {Value: 3, Label: "High Priority", Hint: "Needs attention today"}, |
| 59 | + {Value: 4, Label: "Critical", Hint: "Drop everything and do this now"}, |
| 60 | + } |
| 61 | + |
| 62 | + result3 := tap.Select[int](context.Background(), tap.SelectOptions[int]{ |
| 63 | + Message: "What's the priority level for this task?", |
| 64 | + Options: priorities, |
| 65 | + }) |
| 66 | + fmt.Printf("\nSelected priority level: %d\n", result3) |
| 67 | + |
| 68 | + // Example 4: Simple options without labels (uses values as labels) |
| 69 | + fmt.Println("\n" + strings.Repeat("─", 50)) |
| 70 | + fmt.Println("Simple Options Example:") |
| 71 | + |
| 72 | + environments := []tap.SelectOption[string]{ |
| 73 | + {Value: "development"}, |
| 74 | + {Value: "staging"}, |
| 75 | + {Value: "production"}, |
| 76 | + } |
| 77 | + |
| 78 | + result4 := tap.Select[string](context.Background(), tap.SelectOptions[string]{ |
| 79 | + Message: "Which environment to deploy to?", |
| 80 | + Options: environments, |
| 81 | + }) |
| 82 | + fmt.Printf("\nDeploying to: %s\n", result4) |
| 83 | + fmt.Println("\nAll examples completed successfully! 🎉") |
| 84 | +} |
0 commit comments