Skip to content

Commit d795b8a

Browse files
authored
fix(table): padding on item indicator (#841)
1 parent ce6bb49 commit d795b8a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

table/table.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package table
1616

1717
import (
1818
"fmt"
19+
"strconv"
1920

2021
"github.com/charmbracelet/bubbles/help"
2122
"github.com/charmbracelet/bubbles/key"
@@ -80,7 +81,13 @@ func (m model) countView() string {
8081
return ""
8182
}
8283

83-
return m.help.Styles.FullDesc.Render(fmt.Sprintf("%d/%d%s", m.table.Cursor()+1, len(m.table.Rows()), m.help.ShortSeparator))
84+
padding := strconv.Itoa(numLen(len(m.table.Rows())))
85+
return m.help.Styles.FullDesc.Render(fmt.Sprintf(
86+
"%"+padding+"d/%d%s",
87+
m.table.Cursor()+1,
88+
len(m.table.Rows()),
89+
m.help.ShortSeparator,
90+
))
8491
}
8592

8693
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -117,3 +124,15 @@ func (m model) View() string {
117124
}
118125
return s
119126
}
127+
128+
func numLen(i int) int {
129+
if i == 0 {
130+
return 1
131+
}
132+
count := 0
133+
for i != 0 {
134+
i /= 10
135+
count++
136+
}
137+
return count
138+
}

0 commit comments

Comments
 (0)