Skip to content

Commit

Permalink
fix(table): padding on item indicator (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 authored Feb 4, 2025
1 parent ce6bb49 commit d795b8a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package table

import (
"fmt"
"strconv"

"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

0 comments on commit d795b8a

Please sign in to comment.