11package pokemon
22
33import (
4+ "bytes"
45 "flag"
56 "fmt"
7+ "github.com/charmbracelet/lipgloss"
68 "github.com/digitalghost-dev/poke-cli/cmd/utils"
79 "github.com/digitalghost-dev/poke-cli/connections"
810 "github.com/digitalghost-dev/poke-cli/flags"
911 "github.com/digitalghost-dev/poke-cli/styling"
1012 "golang.org/x/text/cases"
1113 "golang.org/x/text/language"
14+ "io"
1215 "math"
1316 "os"
1417 "strings"
@@ -21,6 +24,7 @@ func PokemonCommand() (string, error) {
2124 hintMessage := styling .StyleItalic .Render ("options: [sm, md, lg]" )
2225
2326 flag .Usage = func () {
27+ styledFlag := styling .ErrorColor .Render (fmt .Sprintf ("%-30s" , "-t, --types" ))
2428 helpMessage := styling .HelpBorder .Render (
2529 "Get details about a specific Pokémon.\n \n " ,
2630 styling .StyleBold .Render ("USAGE:" ),
@@ -33,7 +37,7 @@ func PokemonCommand() (string, error) {
3337 fmt .Sprintf ("\n \t %5s%-15s" , "" , hintMessage ),
3438 fmt .Sprintf ("\n \t %-30s %s" , "-m, --moves" , "Prints the Pokemon's learnable moves." ),
3539 fmt .Sprintf ("\n \t %-30s %s" , "-s, --stats" , "Prints the Pokémon's base stats." ),
36- fmt .Sprintf ("\n \t %-30s %s" , "-t, --types" , "Prints the Pokémon's typing." ),
40+ fmt .Sprintf ("\n \t %s %s" , styledFlag , styling . ErrorColor . Render ( "Deprecated. Types are included with each Pokémon." ) ),
3741 fmt .Sprintf ("\n \t %-30s %s" , "-h, --help" , "Prints the help menu." ),
3842 )
3943 output .WriteString (helpMessage )
@@ -88,11 +92,39 @@ func PokemonCommand() (string, error) {
8892 inches = 0
8993 }
9094
95+ typing := func (w io.Writer ) {
96+ var typeBoxes []string
97+
98+ for _ , pokeType := range pokemonStruct .Types {
99+ colorHex , exists := styling .ColorMap [pokeType .Type .Name ]
100+ if exists {
101+ color := lipgloss .Color (colorHex )
102+ typeColorStyle := lipgloss .NewStyle ().
103+ Align (lipgloss .Center ).
104+ Foreground (lipgloss .Color ("#FAFAFA" )).
105+ Background (color ).
106+ Margin (1 , 1 , 0 , 0 ).
107+ Height (1 ).
108+ Width (14 )
109+
110+ rendered := typeColorStyle .Render (cases .Title (language .English ).String (pokeType .Type .Name ))
111+ typeBoxes = append (typeBoxes , rendered )
112+ }
113+ }
114+
115+ joinedTypes := lipgloss .JoinHorizontal (lipgloss .Top , typeBoxes ... )
116+ fmt .Fprintln (w , joinedTypes )
117+ }
118+
119+ var typeOutput bytes.Buffer
120+ typing (& typeOutput )
121+
91122 output .WriteString (fmt .Sprintf (
92- "Your selected Pokémon: %s\n %s National Pokédex #: %d\n %s Weight: %.1fkg (%.1f lbs)\n %s Height: %.1fm (%d′%02d″)\n " ,
93- capitalizedString , styling .ColoredBullet , pokemonStruct .ID ,
123+ "Your selected Pokémon: %s\n %s\n %s National Pokédex #: %d\n %s Weight: %.1fkg (%.1f lbs)\n %s Height: %.1fm (%d′%02d″)\n " ,
124+ capitalizedString , typeOutput .String (),
125+ styling .ColoredBullet , pokemonStruct .ID ,
94126 styling .ColoredBullet , weightKilograms , weightPounds ,
95- styling .ColoredBullet , heightFeet , feet , inches ,
127+ styling .ColoredBullet , heightMeters , feet , inches ,
96128 ))
97129
98130 if * imageFlag != "" || * shortImageFlag != "" {
0 commit comments