From 0ea390fcae9febb19405bd670894c0323ee66ccc Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 28 Apr 2022 22:35:53 +0200 Subject: [PATCH] Consider true word length --- main.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index d377f05..955ea55 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( "strings" "syscall" "time" + "unicode/utf8" ) var ( @@ -181,8 +182,8 @@ func (m model) InputWord() (model, tea.Cmd) { input := m.textInput.Value() m.lastWord = input - if len(input) > m.maxLength { - m.maxLength = len(input) + if utf8.RuneCountInString(input) > m.maxLength { + m.maxLength = utf8.RuneCountInString(input) } // TODO: Get distance and ranking from a file w := word{input, 200*rand.Float64() - 100, rand.Intn(1000)} @@ -235,7 +236,7 @@ func (w word) View(m model) string { return fmt.Sprintf( "* %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, emoji, w.ranking,