Skip to content

Commit

Permalink
fix the width detection for nidoran ♀/♂
Browse files Browse the repository at this point in the history
  • Loading branch information
tmck-code committed Apr 4, 2024
1 parent c4c2c83 commit 636acb8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/pokesay/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"embed"
"fmt"
"os"
"slices"
"strings"

"github.com/fatih/color"
Expand Down Expand Up @@ -69,6 +70,7 @@ var (
RightArrow: "→",
CategorySeparator: "/",
}
SingleWidthCars []string = []string{"♀", "♂"}
)

func DetermineBoxCharacters(unicodeBox bool) *BoxCharacters {
Expand Down Expand Up @@ -135,13 +137,19 @@ func printWrappedText(boxCharacters *BoxCharacters, line string, width int, tabS

func nameLength(names []string) int {
totalLen := 0

for _, name := range names {
for _, c := range name {
// check if ascii
if c < 128 {
totalLen++
} else {
totalLen += 2
// check if single width character
if slices.Contains(SingleWidthCars, string(c)) {
totalLen++
} else {
totalLen += 2
}
}
}
}
Expand Down Expand Up @@ -170,7 +178,6 @@ func printPokemon(args Args, index int, names []string, categoryKeys []string, G
args.BoxCharacters.RightArrow,
strings.Join(namesFmt, fmt.Sprintf(" %s ", args.BoxCharacters.Separator)),
)

} else {
infoLine = fmt.Sprintf(
"%s %s %s %s",
Expand All @@ -182,7 +189,7 @@ func printPokemon(args Args, index int, names []string, categoryKeys []string, G
for _, category := range categoryKeys {
width += len(category)
}
width += len(categoryKeys) - 1 + 1 + 2
width += len(categoryKeys) - 1 + 1 + 2 // lol why did I do this
}

if args.DrawInfoBorder {
Expand Down

0 comments on commit 636acb8

Please sign in to comment.