Consider true word length

This commit is contained in:
Yohann D'ANELLO 2022-04-28 22:35:53 +02:00
parent ed64019555
commit 0ea390fcae
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 4 additions and 3 deletions

View File

@ -20,6 +20,7 @@ import (
"strings" "strings"
"syscall" "syscall"
"time" "time"
"unicode/utf8"
) )
var ( var (
@ -181,8 +182,8 @@ func (m model) InputWord() (model, tea.Cmd) {
input := m.textInput.Value() input := m.textInput.Value()
m.lastWord = input m.lastWord = input
if len(input) > m.maxLength { if utf8.RuneCountInString(input) > m.maxLength {
m.maxLength = len(input) m.maxLength = utf8.RuneCountInString(input)
} }
// TODO: Get distance and ranking from a file // TODO: Get distance and ranking from a file
w := word{input, 200*rand.Float64() - 100, rand.Intn(1000)} w := word{input, 200*rand.Float64() - 100, rand.Intn(1000)}
@ -235,7 +236,7 @@ func (w word) View(m model) string {
return fmt.Sprintf( return fmt.Sprintf(
"* %s %s %s %4d %s\n", "* %s %s %s %4d %s\n",
w.content+strings.Repeat(" ", m.maxLength-len(w.content)), w.content+strings.Repeat(" ", m.maxLength-utf8.RuneCountInString(w.content)),
distStr, distStr,
emoji, emoji,
w.ranking, w.ranking,