mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 13:45:45 +01:00
fix(table): padding on item indicator (#841)
This commit is contained in:
parent
ce6bb49ce0
commit
d795b8ab2f
1 changed files with 20 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue