fix(table): padding on item indicator (#841)

This commit is contained in:
Carlos Alexandro Becker 2025-02-04 16:38:09 -03:00 committed by GitHub
commit d795b8ab2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,6 +16,7 @@ package table
import (
"fmt"
"strconv"
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
@ -80,7 +81,13 @@ func (m model) countView() string {
return ""
}
return m.help.Styles.FullDesc.Render(fmt.Sprintf("%d/%d%s", m.table.Cursor()+1, len(m.table.Rows()), m.help.ShortSeparator))
padding := strconv.Itoa(numLen(len(m.table.Rows())))
return m.help.Styles.FullDesc.Render(fmt.Sprintf(
"%"+padding+"d/%d%s",
m.table.Cursor()+1,
len(m.table.Rows()),
m.help.ShortSeparator,
))
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@ -117,3 +124,15 @@ func (m model) View() string {
}
return s
}
func numLen(i int) int {
if i == 0 {
return 1
}
count := 0
for i != 0 {
i /= 10
count++
}
return count
}