fix: crash when no groups defined and opening the group panel

This commit is contained in:
Slug-Boi
2024-11-25 22:17:07 +01:00
parent 9224da930f
commit a9850510e3
+11 -3
View File
@@ -53,7 +53,7 @@ func newModel() mainModel {
slices.Sort(content) slices.Sort(content)
// check if terminal 0 is a terminal // check if terminal 0 is a terminal
var w,h int var w, h int
var err error var err error
if ok := term.IsTerminal(0); ok { if ok := term.IsTerminal(0); ok {
// calculate term size // calculate term size
@@ -78,7 +78,7 @@ func newModel() mainModel {
} }
cap = max(1, cap) cap = max(1, cap)
if cap * 2 > len(content) { if cap*2 > len(content) {
cap = len(content) cap = len(content)
} }
@@ -89,6 +89,10 @@ func newModel() mainModel {
p.PerPage = cap * lines p.PerPage = cap * lines
p.SetTotalPages(len(content)) p.SetTotalPages(len(content))
if len(content) == 0 {
content = append(content, "No groups found")
}
m := mainModel{content: content, paginator: p} m := mainModel{content: content, paginator: p}
return m return m
} }
@@ -138,7 +142,11 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
// Adrian is a fucking genius thanks for the idea :) // Adrian is a fucking genius thanks for the idea :)
m.paginator.Page = m.index / (cap * lines) if m.index == 0 {
m.paginator.Page = 0
} else {
m.paginator.Page = m.index / (cap * lines)
}
cmds = append(cmds, cmd) cmds = append(cmds, cmd)
return m, tea.Batch(cmds...) return m, tea.Batch(cmds...)