From d795b8ab2ffb048f281d0af901d119ff00ebba59 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 4 Feb 2025 16:38:09 -0300 Subject: [PATCH] fix(table): padding on item indicator (#841) --- table/table.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/table/table.go b/table/table.go index 3574e48..9c6ed72 100644 --- a/table/table.go +++ b/table/table.go @@ -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 +}