|
7 | 7 | "fmt" |
8 | 8 | "github.com/charmbracelet/lipgloss" |
9 | 9 | "github.com/digitalghost-dev/poke-cli/connections" |
| 10 | + "golang.org/x/text/cases" |
| 11 | + "golang.org/x/text/language" |
10 | 12 | "strings" |
11 | 13 | ) |
12 | 14 |
|
@@ -58,13 +60,38 @@ func AbilitiesFlag(endpoint string, pokemonName string) error { |
58 | 60 |
|
59 | 61 | header("Abilities") |
60 | 62 |
|
| 63 | + // Anonymous function to format ability names |
| 64 | + formatAbilityName := func(name string) string { |
| 65 | + exceptions := map[string]bool{ |
| 66 | + "of": true, |
| 67 | + "the": true, |
| 68 | + "to": true, |
| 69 | + "as": true, |
| 70 | + } |
| 71 | + |
| 72 | + name = strings.Replace(name, "-", " ", -1) |
| 73 | + words := strings.Split(name, " ") |
| 74 | + titleCaser := cases.Title(language.English) |
| 75 | + |
| 76 | + // Process each word |
| 77 | + for i, word := range words { |
| 78 | + if _, found := exceptions[strings.ToLower(word)]; found && i != 0 { |
| 79 | + words[i] = strings.ToLower(word) |
| 80 | + } else { |
| 81 | + words[i] = titleCaser.String(word) |
| 82 | + } |
| 83 | + } |
| 84 | + return strings.Join(words, " ") |
| 85 | + } |
| 86 | + |
61 | 87 | for _, pokeAbility := range pokemonStruct.Abilities { |
| 88 | + formattedName := formatAbilityName(pokeAbility.Ability.Name) |
62 | 89 | if pokeAbility.Slot == 1 { |
63 | | - fmt.Printf("Ability %d: %s\n", pokeAbility.Slot, pokeAbility.Ability.Name) |
| 90 | + fmt.Printf("Ability %d: %s\n", pokeAbility.Slot, formattedName) |
64 | 91 | } else if pokeAbility.Slot == 2 { |
65 | | - fmt.Printf("Ability %d: %s\n", pokeAbility.Slot, pokeAbility.Ability.Name) |
| 92 | + fmt.Printf("Ability %d: %s\n", pokeAbility.Slot, formattedName) |
66 | 93 | } else { |
67 | | - fmt.Printf("Hidden Ability: %s\n", pokeAbility.Ability.Name) |
| 94 | + fmt.Printf("Hidden Ability: %s\n", formattedName) |
68 | 95 | } |
69 | 96 | } |
70 | 97 |
|
@@ -181,9 +208,11 @@ func TypesFlag(endpoint string, pokemonName string) error { |
181 | 208 | colorHex, exists := colorMap[pokeType.Type.Name] |
182 | 209 | if exists { |
183 | 210 | color := lipgloss.Color(colorHex) |
184 | | - fmt.Printf("Type %d: %s\n", pokeType.Slot, lipgloss.NewStyle().Bold(true).Foreground(color).Render(pokeType.Type.Name)) |
| 211 | + style := lipgloss.NewStyle().Bold(true).Foreground(color) |
| 212 | + styledName := style.Render(cases.Title(language.English).String(pokeType.Type.Name)) // Apply styling here |
| 213 | + fmt.Printf("Type %d: %s\n", pokeType.Slot, styledName) // Interpolate styled text |
185 | 214 | } else { |
186 | | - fmt.Printf("Type %d: %s\n", pokeType.Slot, pokeType.Type.Name) |
| 215 | + fmt.Printf("Type %d: %s\n", pokeType.Slot, cases.Title(language.English).String(pokeType.Type.Name)) |
187 | 216 | } |
188 | 217 | } |
189 | 218 |
|
|
0 commit comments