Skip to content

Commit

Permalink
Merge pull request #63 from tmck-code/nidoran-width-fix
Browse files Browse the repository at this point in the history
fix the width detection for nidoran ♀/♂
  • Loading branch information
tmck-code authored Apr 4, 2024
2 parents c4c2c83 + 4a21bb0 commit b71d67b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/pokesay/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ var (
RightArrow: "→",
CategorySeparator: "/",
}
SingleWidthCars map[string]bool = map[string]bool{
"♀": true,
"♂": true,
}
)

func DetermineBoxCharacters(unicodeBox bool) *BoxCharacters {
Expand Down Expand Up @@ -135,10 +139,11 @@ 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 {
// check if ascii or single-width unicode
if (c < 128) || (SingleWidthCars[string(c)]) {
totalLen++
} else {
totalLen += 2
Expand Down Expand Up @@ -170,7 +175,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 +186,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 b71d67b

Please sign in to comment.