Verified Commit b3768042 authored by ynerant's avatar ynerant
Browse files

Auto resize progress bars

parent f68970ea
......@@ -143,6 +143,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.wordsViewport.Height = msg.Height - verticalMarginHeight
}
lineWidth := lipgloss.Width(fmt.Sprintf(
"* %s %s %s %4d ",
strings.Repeat(" ", m.maxLength),
"-00.00",
" ",
42,
))
m.progressBar.Width = msg.Width - lineWidth
m.wordsViewport.SetContent(m.wordsView())
case errMsg:
m.err = msg
return m, nil
......@@ -168,11 +178,16 @@ func (m model) InputWord() (model, tea.Cmd) {
w := word{input, 200*rand.Float64() - 100, rand.Intn(1000)}
m.words = append(m.words, w)
var content string
for _, w := range m.words {
content += w.View(m)
}
m.wordsViewport.SetContent(content)
lineWidth := lipgloss.Width(fmt.Sprintf(
"* %s %s %s %4d ",
strings.Repeat(" ", m.maxLength),
"-00.00",
" ",
42,
))
m.progressBar.Width = m.wordsViewport.Width - lineWidth
m.wordsViewport.SetContent(m.wordsView())
m.textInput.SetValue("")
m.textInput.CursorStart()
......@@ -209,7 +224,7 @@ func (w word) View(m model) string {
}
return fmt.Sprintf(
"* %s\t%s %s\t%4d %s\n",
"* %s %s %s %4d %s\n",
w.content+strings.Repeat(" ", m.maxLength-len(w.content)),
distStr,
emoji,
......@@ -240,6 +255,14 @@ func (m model) headerView() string {
return msg
}
func (m model) wordsView() string {
var content string
for _, w := range m.words {
content += w.View(m)
}
return content
}
func (m model) footerView() string {
info := infoStyle.Render(fmt.Sprintf("%3.f%%", m.wordsViewport.ScrollPercent()*100))
line := strings.Repeat("─", int(math.Max(0, float64(m.wordsViewport.Width-lipgloss.Width(info)))))
......@@ -248,7 +271,7 @@ func (m model) footerView() string {
func (m model) View() string {
if !m.ready {
return "\n\tInitializing..."
return "\n\tInitialisation…"
}
return fmt.Sprintf("%s\n%s\n%s", m.headerView(), m.wordsViewport.View(), m.footerView())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment