From f6cf031a2223288ce9cd1e5ce2db830d7c016dfb Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 4 May 2022 17:28:39 +0200 Subject: [PATCH] Display ranking only for positive values Signed-off-by: Yohann D'ANELLO --- main.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 51ef6fd..4572fb8 100644 --- a/main.go +++ b/main.go @@ -86,10 +86,10 @@ func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) { ti.CharLimit = 26 ti.Width = 26 - content, err := ioutil.ReadFile("cemantics.txt") + content, err := ioutil.ReadFile("cemantix.txt") if err != nil { - log.Printf("Error while opening cemantics.txt: %s", err) + log.Printf("Error while opening cemantix.txt: %s", err) return nil, nil } @@ -169,10 +169,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } lineWidth := lipgloss.Width(fmt.Sprintf( - "* %s %s %s %4d ", + "* %s %s %s %4d ", strings.Repeat(" ", m.maxLength), "-100.00", - " ", + " ", 42, )) m.progressBar.Width = msg.Width - lineWidth @@ -221,10 +221,10 @@ func (m model) InputWord() (model, tea.Cmd) { m.words = InsertWord(m.words, w) lineWidth := lipgloss.Width(fmt.Sprintf( - "* %s %s %s %5d ", + "* %s %s %s %5d ", strings.Repeat(" ", m.maxLength), "-00.00", - " ", + " ", 1000, )) m.progressBar.Width = m.wordsViewport.Width - lineWidth @@ -255,8 +255,10 @@ func (w word) View(m model) string { } var progressBar string + var ranking string = " " if w.ranking > 0 { progressBar = m.progressBar.ViewAs(float64(w.ranking) / 1000.0) + ranking = fmt.Sprintf("%4d", w.ranking) } distStr := fmt.Sprintf("%.02f", w.distance) @@ -271,11 +273,11 @@ func (w word) View(m model) string { } return fmt.Sprintf( - "* %s %s %s %4d %s\n", + "* %s %s %s %s %s\n", w.content+strings.Repeat(" ", m.maxLength-utf8.RuneCountInString(w.content)), distStr, emoji, - w.ranking, + ranking, progressBar, ) }